github-actions[bot] commented on code in PR #41768:
URL: https://github.com/apache/doris/pull/41768#discussion_r1799095738


##########
be/src/vec/functions/function_ip.h:
##########
@@ -606,110 +606,177 @@ class FunctionIsIPAddressInRange : public IFunction {
         return std::make_shared<DataTypeUInt8>();
     }
 
-    Status execute_impl(FunctionContext* context, Block& block, const 
ColumnNumbers& arguments,
-                        size_t result, size_t input_rows_count) const override 
{
-        const auto& addr_column_with_type_and_name = 
block.get_by_position(arguments[0]);
-        const auto& cidr_column_with_type_and_name = 
block.get_by_position(arguments[1]);
-        WhichDataType addr_type(addr_column_with_type_and_name.type);
-        WhichDataType cidr_type(cidr_column_with_type_and_name.type);
-        const auto& [addr_column, addr_const] =
-                unpack_if_const(addr_column_with_type_and_name.column);
-        const auto& [cidr_column, cidr_const] =
-                unpack_if_const(cidr_column_with_type_and_name.column);
-        const auto* str_addr_column = assert_cast<const 
ColumnString*>(addr_column.get());
-        const auto* str_cidr_column = assert_cast<const 
ColumnString*>(cidr_column.get());
-
-        auto col_res = ColumnUInt8::create(input_rows_count, 0);
+    template <PrimitiveType PT, typename ColumnType>
+    void execute_impl_with_ip(size_t input_rows_count, bool addr_const, bool 
cidr_const,
+                              const ColumnString* str_cidr_column, const 
ColumnPtr addr_column,
+                              ColumnUInt8* col_res) const {
         auto& col_res_data = col_res->get_data();
-
+        const auto& ip_data = assert_cast<const 
ColumnType*>(addr_column.get())->get_data();
         for (size_t i = 0; i < input_rows_count; ++i) {
             auto addr_idx = index_check_const(i, addr_const);
             auto cidr_idx = index_check_const(i, cidr_const);
-
-            const auto addr =
-                    
IPAddressVariant(str_addr_column->get_data_at(addr_idx).to_string_view());
             const auto cidr =
                     
parse_ip_with_cidr(str_cidr_column->get_data_at(cidr_idx).to_string_view());
-            col_res_data[i] = is_address_in_range(addr, cidr) ? 1 : 0;
+            if constexpr (PT == PrimitiveType::TYPE_IPV4) {
+                if (cidr._address.as_v4()) {
+                    col_res_data[i] = match_ipv4_subnet(ip_data[addr_idx], 
cidr._address.as_v4(),
+                                                        cidr._prefix)
+                                              ? 1
+                                              : 0;
+                } else {
+                    col_res_data[i] = 0;
+                }
+            } else if constexpr (PT == PrimitiveType::TYPE_IPV6) {
+                if (cidr._address.as_v6()) {
+                    col_res_data[i] = 
match_ipv6_subnet((uint8*)(&ip_data[addr_idx]),
+                                                        cidr._address.as_v6(), 
cidr._prefix)
+                                              ? 1
+                                              : 0;
+                } else {
+                    col_res_data[i] = 0;
+                }
+            }
         }
-
-        block.replace_by_position(result, std::move(col_res));
-        return Status::OK();
     }
-};
-
-// old version throw exception when meet null value
-class FunctionIsIPAddressInRangeOld : 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; }
+    Status evaluate_inverted_index(

Review Comment:
   warning: function 'evaluate_inverted_index' exceeds recommended 
size/complexity thresholds [readability-function-size]
   ```cpp
       Status evaluate_inverted_index(
              ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/vec/functions/function_ip.h:641:** 90 lines including whitespace 
and comments (threshold 80)
   ```cpp
       Status evaluate_inverted_index(
              ^
   ```
   
   </details>
   



-- 
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