HappenLee commented on code in PR #29954:
URL: https://github.com/apache/doris/pull/29954#discussion_r1452541176


##########
be/src/vec/functions/function_ip.h:
##########
@@ -969,4 +930,114 @@ class FunctionIPv6CIDRToRange : public IFunction {
     }
 };
 
-} // namespace doris::vectorized
\ No newline at end of file
+class FunctionIsIPv4Compat : public IFunction {
+public:
+    static constexpr auto name = "is_ipv4_compat";
+    static FunctionPtr create() { return 
std::make_shared<FunctionIsIPv4Compat>(); }
+
+    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<DataTypeUInt8>());
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }

Review Comment:
   no need override the function, the default value is `true`



##########
be/src/vec/functions/function_ip.h:
##########
@@ -969,4 +930,114 @@ class FunctionIPv6CIDRToRange : public IFunction {
     }
 };
 
-} // namespace doris::vectorized
\ No newline at end of file
+class FunctionIsIPv4Compat : public IFunction {
+public:
+    static constexpr auto name = "is_ipv4_compat";
+    static FunctionPtr create() { return 
std::make_shared<FunctionIsIPv4Compat>(); }
+
+    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<DataTypeUInt8>());
+    }
+
+    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 
{
+        const ColumnPtr& column = block.get_by_position(arguments[0]).column;
+        const auto* col_in = check_and_get_column<ColumnString>(column.get());
+
+        if (!col_in)
+            throw Exception(ErrorCode::INVALID_ARGUMENT,
+                            "Illegal column {} of argument of function {}, 
expected String",
+                            column->get_name(), get_name());
+        size_t col_size = col_in->size();
+        auto col_res = ColumnUInt8::create(col_size, 0);
+        auto null_map = ColumnUInt8::create(col_size, 0);
+
+        for (size_t i = 0; i < col_size; ++i) {
+            auto& col_res_data = col_res->get_data();
+            auto& null_map_data = null_map->get_data();
+
+            if (col_in->is_null_at(i)) {
+                null_map_data[i] = 1;
+            } else {
+                auto ipv4_in = col_in->get_data_at(i);
+                if (is_ipv4_compat(reinterpret_cast<const 
UInt8*>(ipv4_in.data))) {
+                    col_res_data[i] = 1;
+                }
+            }
+        }
+
+        block.replace_by_position(result,
+                                  ColumnNullable::create(std::move(col_res), 
std::move(null_map)));
+        return Status::OK();
+    }
+
+private:
+    static bool is_ipv4_compat(const UInt8* address) {
+        return (unaligned_load_little_endian<UInt64>(address) == 0) &&
+               (unaligned_load_little_endian<UInt32>(address + 8) == 0) &&
+               (unaligned_load_little_endian<UInt32>(address + 12) != 0);
+    }
+};
+
+class FunctionIsIPv4Mapped : public IFunction {
+public:
+    static constexpr auto name = "is_ipv4_mapped";
+    static FunctionPtr create() { return 
std::make_shared<FunctionIsIPv4Mapped>(); }
+
+    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<DataTypeUInt8>());
+    }
+
+    bool use_default_implementation_for_nulls() const override { return true; }

Review Comment:
   no need override the function, the default value is `true`



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