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


##########
be/src/vec/functions/function_ip.h:
##########
@@ -832,4 +835,128 @@ class FunctionIsIPAddressInRange : public IFunction {
     }
 };
 
+class FunctionIPv6CIDRToRange : public IFunction {
+public:
+    static constexpr auto name = "ipv6_cidr_to_range";
+    static FunctionPtr create() { return 
std::make_shared<FunctionIPv6CIDRToRange>(); }
+
+    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 {
+        const auto& ipv6_type = arguments[0];
+        if (!is_string(remove_nullable(ipv6_type)) && 
!is_ipv6(remove_nullable(ipv6_type))) {
+            throw Exception(
+                    ErrorCode::INVALID_ARGUMENT,
+                    "Illegal type {} of first argument of function {}, 
expected String or IPv6",
+                    ipv6_type->get_name(), get_name());
+        }
+        const auto& cidr_type = arguments[1];
+        if (!is_integer(remove_nullable(cidr_type))) {
+            throw Exception(ErrorCode::INVALID_ARGUMENT,
+                            "Illegal type {} of second argument of function 
{}, expected Integer",
+                            cidr_type->get_name(), get_name());
+        }
+        DataTypePtr element = std::make_shared<DataTypeIPv6>();
+        return make_nullable(std::make_shared<DataTypeStruct>(DataTypes 
{element, element},
+                                                              Strings {"min", 
"max"}));
+    }
+
+    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 
{
+        ColumnPtr& addr_column = block.get_by_position(arguments[0]).column;
+        ColumnPtr& cidr_column = block.get_by_position(arguments[1]).column;
+        const IColumn* cidr_col = nullptr;
+        const NullMap* cidr_nullmap = nullptr;
+        ColumnPtr col_res = nullptr;
+
+        if (cidr_column->is_nullable()) {
+            const auto* cidr_column_nullable =
+                    assert_cast<const ColumnNullable*>(cidr_column.get());
+            cidr_col = &cidr_column_nullable->get_nested_column();
+            cidr_nullmap = &cidr_column_nullable->get_null_map_data();
+        } else {
+            cidr_col = cidr_column.get();
+        }
+
+        if (addr_column->is_nullable()) {
+            const auto* addr_column_nullable =
+                    assert_cast<const ColumnNullable*>(addr_column.get());
+            const NullMap* addr_nullmap = 
&addr_column_nullable->get_null_map_data();
+            if (const auto* ipv6_addr_column = 
check_and_get_column<ColumnIPv6>(

Review Comment:
   same with is_null
   use data type to check



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