amorynan commented on code in PR #28556:
URL: https://github.com/apache/doris/pull/28556#discussion_r1438097228


##########
be/src/vec/functions/function_ip.h:
##########
@@ -348,4 +348,108 @@ class FunctionIPv6NumToString : public IFunction {
     }
 };
 
+class FunctionIsIPv4String : public IFunction {
+private:
+    Status execute_type(Block& block, const ColumnWithTypeAndName& argument, 
size_t result) const {
+        const ColumnPtr& column = argument.column;
+
+        if (const auto* col_src = typeid_cast<const 
ColumnString*>(column.get())) {
+            auto col_res = ColumnInt8::create();
+
+            for (size_t i = 0; i < col_src->size(); ++i) {
+                auto ipv4_str = col_src->get_data_at(i).to_string();
+                if (ipv4_str.size() > IPV4_MAX_TEXT_LENGTH ||
+                    !IPv4Value::is_valid_string(ipv4_str)) {
+                    col_res->insert_value(0);
+                } else {
+                    col_res->insert_value(1);
+                }
+            }
+
+            DCHECK_EQ(col_res->size(), col_src->size());
+
+            block.replace_by_position(
+                    result, ColumnNullable::create(std::move(col_res),
+                                                   
ColumnUInt8::create(col_src->size(), 0)));
+            return Status::OK();
+        }
+
+        return Status::RuntimeError("Illegal column {} of argument of function 
{}",
+                                    argument.column->get_name(), get_name());
+    }
+
+public:
+    static constexpr auto name = "isipv4string";
+    static FunctionPtr create() { return 
std::make_shared<FunctionIsIPv4String>(); }
+
+    String get_name() const override { return name; }
+
+    size_t get_number_of_arguments() const override { return 1; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        return make_nullable(std::make_shared<DataTypeInt8>());
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        ColumnWithTypeAndName& argument = block.get_by_position(arguments[0]);
+        DCHECK(argument.type->get_type_id() == TypeIndex::String);
+        return execute_type(block, argument, result);
+    }
+};
+
+class FunctionIsIPv6String : public IFunction {
+private:
+    Status execute_type(Block& block, const ColumnWithTypeAndName& argument, 
size_t result) const {
+        const ColumnPtr& column = argument.column;
+
+        if (const auto* col_src = typeid_cast<const 
ColumnString*>(column.get())) {
+            auto col_res = ColumnInt8::create();

Review Comment:
   I think here is mistake for boolean value which now we make ColumnUInt8 
present boolean!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to