zclllyybb commented on code in PR #29681:
URL: https://github.com/apache/doris/pull/29681#discussion_r1444712640


##########
be/src/vec/functions/function_ip.h:
##########
@@ -745,4 +740,96 @@ class FunctionIsIPv6String : public IFunction {
     }
 };
 
+class FunctionIsIPAddressInRange : public IFunction {
+public:
+    static constexpr auto name = "is_ip_address_in_range";
+    static FunctionPtr create() { return 
std::make_shared<FunctionIsIPAddressInRange>(); }
+
+    String get_name() const override { return name; }
+
+    size_t get_number_of_arguments() const override { return 2; }
+
+    DataTypePtr get_return_type_impl(const DataTypes& arguments) const 
override {
+        if (arguments.size() != 2) {
+            throw Exception(
+                    ErrorCode::INVALID_ARGUMENT,
+                    "Number of arguments for function {} doesn't match: passed 
{}, should be 2",
+                    get_name(), arguments.size());
+        }
+        const auto& addr_type = arguments[0];
+        const auto& cidr_type = arguments[1];
+        if (!is_string(remove_nullable(addr_type)) || 
!is_string(remove_nullable(cidr_type))) {
+            throw Exception(ErrorCode::INVALID_ARGUMENT,
+                            "The arguments of function {} must be String", 
get_name());
+        }
+        return std::make_shared<DataTypeUInt8>();
+    }
+
+    bool use_default_implementation_for_nulls() const override { return false; 
}
+
+    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
+                        size_t result, size_t input_rows_count) const override 
{
+        ColumnPtr& addr_column = block.get_by_position(arguments[0]).column;
+        ColumnPtr& cidr_column = block.get_by_position(arguments[1]).column;
+        const ColumnString* str_addr_column = nullptr;
+        const ColumnString* str_cidr_column = nullptr;
+        const NullMap* nullmap_addr = nullptr;
+        const NullMap* nullmap_cidr = nullptr;
+
+        if (addr_column->is_nullable()) {
+            const auto* addr_column_nullable =
+                    assert_cast<const ColumnNullable*>(addr_column.get());
+            str_addr_column =
+                    
check_and_get_column<ColumnString>(addr_column_nullable->get_nested_column());
+            nullmap_addr = &addr_column_nullable->get_null_map_data();
+        } else {
+            str_addr_column = 
check_and_get_column<ColumnString>(addr_column.get());
+        }
+
+        if (cidr_column->is_nullable()) {
+            const auto* cidr_column_nullable =
+                    assert_cast<const ColumnNullable*>(cidr_column.get());
+            str_cidr_column =
+                    
check_and_get_column<ColumnString>(cidr_column_nullable->get_nested_column());
+            nullmap_cidr = &cidr_column_nullable->get_null_map_data();
+        } else {
+            str_cidr_column = 
check_and_get_column<ColumnString>(cidr_column.get());
+        }
+
+        if (!str_addr_column) {
+            throw Exception(ErrorCode::INVALID_ARGUMENT,
+                            "Illegal column {} of argument of function {}, 
expected String",
+                            addr_column->get_name(), get_name());
+        }
+
+        if (!str_cidr_column) {
+            throw Exception(ErrorCode::INVALID_ARGUMENT,
+                            "Illegal column {} of argument of function {}, 
expected String",
+                            cidr_column->get_name(), get_name());
+        }
+
+        auto col_res = ColumnUInt8::create(input_rows_count, 0);
+        auto& col_res_data = col_res->get_data();
+
+        for (size_t i = 0; i < input_rows_count; ++i) {
+            if (nullmap_addr && (*nullmap_addr)[i]) {
+                throw Exception(ErrorCode::INVALID_ARGUMENT,
+                                "The arguments of function {} must be String, 
not NULL",
+                                get_name());
+            }
+            if (nullmap_cidr && (*nullmap_cidr)[i]) {
+                throw Exception(ErrorCode::INVALID_ARGUMENT,
+                                "The arguments of function {} must be String, 
not NULL",
+                                get_name());
+            }
+            const auto addr = 
IPAddressVariant(str_addr_column->get_data_at(i).to_string_view());

Review Comment:
   in a loop please cast column to concrete column first(`ColumnString` here) 
and deal its constant property correctly first to eliminate virtual function 
call(`get_data_at` here)



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to