From 3113e28ac646199408c11ec985da0ea7a7098964 Mon Sep 17 00:00:00 2001 From: amorynan Date: Wed, 27 Nov 2024 22:07:01 +0800 Subject: [PATCH 1/4] fix ip nullable param without check --- be/src/vec/functions/function_ip.h | 48 +++++++++++++++---- .../scalar_function/IP.groovy | 14 ++++-- 2 files changed, 50 insertions(+), 12 deletions(-) diff --git a/be/src/vec/functions/function_ip.h b/be/src/vec/functions/function_ip.h index b90d1b2bcf9434..5d9d137b50828d 100644 --- a/be/src/vec/functions/function_ip.h +++ b/be/src/vec/functions/function_ip.h @@ -923,8 +923,18 @@ class FunctionIPv6CIDRToRange : public IFunction { auto& vec_res_upper_range = col_res_upper_range->get_data(); static constexpr UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; + std::vector ipv6_address_data[IPV6_BINARY_LENGTH]; if (is_addr_const) { + StringRef str_ref = from_column.get_data_at(0); + const char* value = str_ref.data; + size_t value_size = str_ref.size; + if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { + throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", + std::string(value, value_size)); + } + memcpy(ipv6_address_data, value, value_size); + memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); for (size_t i = 0; i < input_rows_count; ++i) { auto cidr = cidr_column.get_int(i); if (cidr < 0 || cidr > max_cidr_mask) { @@ -934,9 +944,9 @@ class FunctionIPv6CIDRToRange : public IFunction { if constexpr (std::is_same_v) { // 16 bytes ipv6 string is stored in big-endian byte order // so transfer to little-endian firstly - auto* src_data = const_cast(from_column.get_data_at(0).data); - std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), + std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); + apply_cidr_mask(reinterpret_cast(ipv6_address_data->data()), + reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); } else { @@ -956,9 +966,19 @@ class FunctionIPv6CIDRToRange : public IFunction { if constexpr (std::is_same_v) { // 16 bytes ipv6 string is stored in big-endian byte order // so transfer to little-endian firstly - auto* src_data = const_cast(from_column.get_data_at(i).data); - std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), + StringRef str_ref = from_column.get_data_at(i); + const char* value = str_ref.data; + size_t value_size = str_ref.size; + if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { + throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", + std::string(value, value_size)); + } + ipv6_address_data->clear(); + memcpy(ipv6_address_data, value, value_size); + memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); + std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); + apply_cidr_mask(reinterpret_cast(ipv6_address_data->data()), + reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); } else { @@ -978,9 +998,19 @@ class FunctionIPv6CIDRToRange : public IFunction { if constexpr (std::is_same_v) { // 16 bytes ipv6 string is stored in big-endian byte order // so transfer to little-endian firstly - auto* src_data = const_cast(from_column.get_data_at(i).data); - std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), + StringRef str_ref = from_column.get_data_at(i); + const char* value = str_ref.data; + size_t value_size = str_ref.size; + if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { + throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", + std::string(value, value_size)); + } + ipv6_address_data->clear(); + memcpy(ipv6_address_data, value, value_size); + memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); + std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); + apply_cidr_mask(reinterpret_cast(ipv6_address_data->data()), + reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); } else { diff --git a/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy b/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy index 9cbdccbe78840b..8770d5c753fd77 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy @@ -30,7 +30,11 @@ suite("nereids_scalar_fn_IP") { qt_sql_cidr_ipv6_all """ select id, ipv6_cidr_to_range(ip6, 16) from fn_test_ip_nullable order by id; """ qt_sql_cidr_ipv4_all """ select id, ipv4_cidr_to_range(ip4, 16) from fn_test_ip_nullable order by id; """ - + // test nullable param + test { + sql "select id, ipv6_cidr_to_range(nullable(''), 32) from fn_test_ip_nullable order by id" + exception "Illegal ipv6 address" + } // test IPV4_STRING_TO_NUM/IPV6_STRING_TO_NUM (we have null value in ip4 and ip6 column in fn_test_ip_nullable table) test { sql 'select id, ipv6_string_to_num(ip6) from fn_test_ip_nullable order by id' @@ -153,7 +157,11 @@ suite("nereids_scalar_fn_IP") { qt_sql_not_null_cidr_ipv6_all """ select id, ipv6_cidr_to_range(ip6, 16) from fn_test_ip_not_nullable order by id; """ qt_sql_not_null_cidr_ipv4_all """ select id, ipv4_cidr_to_range(ip4, 16) from fn_test_ip_not_nullable order by id; """ - + // test nullable param + test { + sql "select id, ipv6_cidr_to_range(nullable(''), 32) from fn_test_ip_not_nullable order by id" + exception "Illegal ipv6 address" + } // test IPV4_STRING_TO_NUM/IPV6_STRING_TO_NUM qt_sql_not_null_ipv6_string_to_num 'select id, hex(ipv6_string_to_num(ip6)) from fn_test_ip_not_nullable order by id' @@ -269,4 +277,4 @@ suite("nereids_scalar_fn_IP") { qt_sql_not_null_to_ipv4_or_null "select id, to_ipv4_or_null(ip6) from fn_test_ip_not_nullable order by id" qt_sql_not_null_to_ipv4_or_null_str "select id, to_ipv4_or_null(ip6_str) from fn_test_ip_not_nullable order by id" -} \ No newline at end of file +} From c01b79bf8c161b710e3528d983e94445ec0b8d55 Mon Sep 17 00:00:00 2001 From: amorynan Date: Wed, 27 Nov 2024 23:47:46 +0800 Subject: [PATCH 2/4] fixed --- be/src/vec/functions/function_ip.h | 19 +- .../scalar_function/IP.out | 204 ++++++++++++++++++ .../scalar_function/IP.groovy | 2 + 3 files changed, 216 insertions(+), 9 deletions(-) diff --git a/be/src/vec/functions/function_ip.h b/be/src/vec/functions/function_ip.h index 5d9d137b50828d..4fe24d44a4bad3 100644 --- a/be/src/vec/functions/function_ip.h +++ b/be/src/vec/functions/function_ip.h @@ -923,13 +923,14 @@ class FunctionIPv6CIDRToRange : public IFunction { auto& vec_res_upper_range = col_res_upper_range->get_data(); static constexpr UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; - std::vector ipv6_address_data[IPV6_BINARY_LENGTH]; + unsigned char ipv6_address_data[IPV6_BINARY_LENGTH]; if (is_addr_const) { StringRef str_ref = from_column.get_data_at(0); const char* value = str_ref.data; size_t value_size = str_ref.size; - if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { + if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0 || + !IPv6Value::is_valid_string(value, value_size)) { throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", std::string(value, value_size)); } @@ -945,7 +946,7 @@ class FunctionIPv6CIDRToRange : public IFunction { // 16 bytes ipv6 string is stored in big-endian byte order // so transfer to little-endian firstly std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(reinterpret_cast(ipv6_address_data->data()), + apply_cidr_mask(reinterpret_cast(&ipv6_address_data), reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); @@ -969,15 +970,15 @@ class FunctionIPv6CIDRToRange : public IFunction { StringRef str_ref = from_column.get_data_at(i); const char* value = str_ref.data; size_t value_size = str_ref.size; - if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { + if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0 || + !IPv6Value::is_valid_string(value, value_size)) { throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", std::string(value, value_size)); } - ipv6_address_data->clear(); memcpy(ipv6_address_data, value, value_size); memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(reinterpret_cast(ipv6_address_data->data()), + apply_cidr_mask(reinterpret_cast(&ipv6_address_data), reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); @@ -1001,15 +1002,15 @@ class FunctionIPv6CIDRToRange : public IFunction { StringRef str_ref = from_column.get_data_at(i); const char* value = str_ref.data; size_t value_size = str_ref.size; - if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0) { + if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0 || + !IPv6Value::is_valid_string(value, value_size)) { throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", std::string(value, value_size)); } - ipv6_address_data->clear(); memcpy(ipv6_address_data, value, value_size); memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(reinterpret_cast(ipv6_address_data->data()), + apply_cidr_mask(reinterpret_cast(&ipv6_address_data), reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); diff --git a/regression-test/data/nereids_function_p0/scalar_function/IP.out b/regression-test/data/nereids_function_p0/scalar_function/IP.out index 5b44453ceb6232..af146b66223378 100644 --- a/regression-test/data/nereids_function_p0/scalar_function/IP.out +++ b/regression-test/data/nereids_function_p0/scalar_function/IP.out @@ -410,6 +410,108 @@ 99 {"min":"224.0.0.0", "max":"224.0.255.255"} 100 {"min":"224.0.0.0", "max":"224.0.255.255"} +-- !sql_cidr_ipv6_nullable_ -- +1 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +2 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +3 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +4 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +5 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +6 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +7 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +8 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +9 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +10 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +11 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +12 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +13 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +14 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +15 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +16 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +17 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +18 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +19 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +20 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +21 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +22 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +23 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +24 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +25 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +26 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +27 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +28 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +29 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +30 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +31 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +32 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +33 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +34 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +35 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +36 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +37 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +38 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +39 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +40 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +41 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +42 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +43 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +44 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +45 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +46 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +47 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +48 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +49 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +50 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +51 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +52 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +53 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +54 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +55 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +56 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +57 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +58 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +59 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +60 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +61 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +62 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +63 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +64 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +65 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +66 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +67 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +68 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +69 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +70 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +71 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +72 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +73 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +74 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +75 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +76 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +77 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +78 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +79 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +80 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +81 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +82 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +83 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +84 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +85 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +86 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +87 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +88 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +89 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +90 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +91 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +92 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +93 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +94 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +95 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +96 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +97 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +98 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +99 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +100 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} + -- !sql_num2string_ipv6 -- 1 ::1 2 fc00:: @@ -6121,6 +6223,108 @@ 99 {"min":"224.0.0.0", "max":"224.0.255.255"} 100 {"min":"224.0.0.0", "max":"224.0.255.255"} +-- !sql_not_null_cidr_ipv6_nullable_ -- +1 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +2 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +3 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +4 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +5 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +6 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +7 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +8 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +9 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +10 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +11 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +12 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +13 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +14 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +15 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +16 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +17 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +18 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +19 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +20 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +21 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +22 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +23 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +24 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +25 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +26 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +27 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +28 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +29 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +30 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +31 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +32 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +33 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +34 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +35 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +36 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +37 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +38 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +39 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +40 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +41 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +42 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +43 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +44 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +45 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +46 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +47 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +48 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +49 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +50 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +51 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +52 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +53 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +54 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +55 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +56 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +57 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +58 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +59 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +60 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +61 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +62 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +63 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +64 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +65 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +66 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +67 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +68 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +69 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +70 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +71 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +72 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +73 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +74 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +75 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +76 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +77 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +78 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +79 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +80 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +81 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +82 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +83 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +84 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +85 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +86 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +87 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +88 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +89 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +90 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +91 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +92 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +93 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +94 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +95 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +96 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +97 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +98 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +99 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} +100 {"min":"::", "max":"::ffff:ffff:ffff:ffff:ffff:ffff"} + -- !sql_not_null_ipv6_string_to_num -- 1 00000000000000000000000000000001 2 FC000000000000000000000000000000 diff --git a/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy b/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy index 8770d5c753fd77..71abccc9dae104 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy @@ -31,6 +31,7 @@ suite("nereids_scalar_fn_IP") { qt_sql_cidr_ipv4_all """ select id, ipv4_cidr_to_range(ip4, 16) from fn_test_ip_nullable order by id; """ // test nullable param + qt_sql_cidr_ipv6_nullable_ "select id, ipv6_cidr_to_range(to_ipv6('::'), 32) from fn_test_ip_nullable order by id;" test { sql "select id, ipv6_cidr_to_range(nullable(''), 32) from fn_test_ip_nullable order by id" exception "Illegal ipv6 address" @@ -158,6 +159,7 @@ suite("nereids_scalar_fn_IP") { qt_sql_not_null_cidr_ipv4_all """ select id, ipv4_cidr_to_range(ip4, 16) from fn_test_ip_not_nullable order by id; """ // test nullable param + qt_sql_not_null_cidr_ipv6_nullable_ "select id, ipv6_cidr_to_range(to_ipv6('::'), 32) from fn_test_ip_nullable order by id;" test { sql "select id, ipv6_cidr_to_range(nullable(''), 32) from fn_test_ip_not_nullable order by id" exception "Illegal ipv6 address" From 96f60c30bcf9ac7c11ce70cbd247104a46fcbac1 Mon Sep 17 00:00:00 2001 From: amorynan Date: Sat, 30 Nov 2024 10:56:25 +0800 Subject: [PATCH 3/4] fix ip functions --- be/src/vec/functions/function_ip.h | 62 ++++++------------- .../scalar_function/IP.groovy | 13 +++- .../test_ipv6_cidr_to_range_function.groovy | 12 ++-- 3 files changed, 36 insertions(+), 51 deletions(-) diff --git a/be/src/vec/functions/function_ip.h b/be/src/vec/functions/function_ip.h index 4fe24d44a4bad3..c01172270069d5 100644 --- a/be/src/vec/functions/function_ip.h +++ b/be/src/vec/functions/function_ip.h @@ -866,6 +866,11 @@ class FunctionIPv4CIDRToRange : public IFunction { } }; +/** + * this function accepts two arguments: an IPv6 address and a CIDR mask + * IPv6 address can be either ipv6 type or string type as ipv6 string address + * FE: PropagateNullable is used to handle nullable columns + */ class FunctionIPv6CIDRToRange : public IFunction { public: static constexpr auto name = "ipv6_cidr_to_range"; @@ -900,9 +905,11 @@ class FunctionIPv6CIDRToRange : public IFunction { col_res = execute_impl(*ipv6_addr_column, *cidr_col, input_rows_count, add_col_const, col_const); } else if (addr_type.is_string()) { - const auto* str_addr_column = assert_cast(addr_column.get()); - col_res = execute_impl(*str_addr_column, *cidr_col, input_rows_count, - add_col_const, col_const); + ColumnPtr col_ipv6 = + convert_to_ipv6(addr_column, nullptr); + const auto* ipv6_addr_column = assert_cast(col_ipv6.get()); + col_res = execute_impl(*ipv6_addr_column, *cidr_col, input_rows_count, + add_col_const, col_const); } else { return Status::RuntimeError( "Illegal column {} of argument of function {}, Expected IPv6 or String", @@ -923,19 +930,8 @@ class FunctionIPv6CIDRToRange : public IFunction { auto& vec_res_upper_range = col_res_upper_range->get_data(); static constexpr UInt8 max_cidr_mask = IPV6_BINARY_LENGTH * 8; - unsigned char ipv6_address_data[IPV6_BINARY_LENGTH]; if (is_addr_const) { - StringRef str_ref = from_column.get_data_at(0); - const char* value = str_ref.data; - size_t value_size = str_ref.size; - if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0 || - !IPv6Value::is_valid_string(value, value_size)) { - throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", - std::string(value, value_size)); - } - memcpy(ipv6_address_data, value, value_size); - memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); for (size_t i = 0; i < input_rows_count; ++i) { auto cidr = cidr_column.get_int(i); if (cidr < 0 || cidr > max_cidr_mask) { @@ -945,9 +941,9 @@ class FunctionIPv6CIDRToRange : public IFunction { if constexpr (std::is_same_v) { // 16 bytes ipv6 string is stored in big-endian byte order // so transfer to little-endian firstly - std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(reinterpret_cast(&ipv6_address_data), - reinterpret_cast(&vec_res_lower_range[i]), + auto* src_data = const_cast(from_column.get_data_at(0).data); + std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); + apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); } else { @@ -967,19 +963,9 @@ class FunctionIPv6CIDRToRange : public IFunction { if constexpr (std::is_same_v) { // 16 bytes ipv6 string is stored in big-endian byte order // so transfer to little-endian firstly - StringRef str_ref = from_column.get_data_at(i); - const char* value = str_ref.data; - size_t value_size = str_ref.size; - if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0 || - !IPv6Value::is_valid_string(value, value_size)) { - throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", - std::string(value, value_size)); - } - memcpy(ipv6_address_data, value, value_size); - memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); - std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(reinterpret_cast(&ipv6_address_data), - reinterpret_cast(&vec_res_lower_range[i]), + auto* src_data = const_cast(from_column.get_data_at(i).data); + std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); + apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); } else { @@ -999,19 +985,9 @@ class FunctionIPv6CIDRToRange : public IFunction { if constexpr (std::is_same_v) { // 16 bytes ipv6 string is stored in big-endian byte order // so transfer to little-endian firstly - StringRef str_ref = from_column.get_data_at(i); - const char* value = str_ref.data; - size_t value_size = str_ref.size; - if (value_size > IPV6_BINARY_LENGTH || value == nullptr || value_size == 0 || - !IPv6Value::is_valid_string(value, value_size)) { - throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal ipv6 address '{}'", - std::string(value, value_size)); - } - memcpy(ipv6_address_data, value, value_size); - memset(ipv6_address_data + value_size, 0, IPV6_BINARY_LENGTH - value_size); - std::reverse(ipv6_address_data, ipv6_address_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(reinterpret_cast(&ipv6_address_data), - reinterpret_cast(&vec_res_lower_range[i]), + auto* src_data = const_cast(from_column.get_data_at(i).data); + std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); + apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), reinterpret_cast(&vec_res_upper_range[i]), cast_set(cidr)); } else { diff --git a/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy b/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy index 71abccc9dae104..a1c1d00caa29fe 100644 --- a/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy +++ b/regression-test/suites/nereids_function_p0/scalar_function/IP.groovy @@ -34,7 +34,11 @@ suite("nereids_scalar_fn_IP") { qt_sql_cidr_ipv6_nullable_ "select id, ipv6_cidr_to_range(to_ipv6('::'), 32) from fn_test_ip_nullable order by id;" test { sql "select id, ipv6_cidr_to_range(nullable(''), 32) from fn_test_ip_nullable order by id" - exception "Illegal ipv6 address" + exception "Invalid IPv6 value" + } + test { + sql "select id, ipv6_cidr_to_range(nullable('abc'), 32) from fn_test_ip_not_nullable order by id" + exception "Invalid IPv6 value" } // test IPV4_STRING_TO_NUM/IPV6_STRING_TO_NUM (we have null value in ip4 and ip6 column in fn_test_ip_nullable table) test { @@ -162,7 +166,12 @@ suite("nereids_scalar_fn_IP") { qt_sql_not_null_cidr_ipv6_nullable_ "select id, ipv6_cidr_to_range(to_ipv6('::'), 32) from fn_test_ip_nullable order by id;" test { sql "select id, ipv6_cidr_to_range(nullable(''), 32) from fn_test_ip_not_nullable order by id" - exception "Illegal ipv6 address" + exception "Invalid IPv6 value" + } + + test { + sql "select id, ipv6_cidr_to_range(nullable('abc'), 32) from fn_test_ip_not_nullable order by id" + exception "Invalid IPv6 value" } // test IPV4_STRING_TO_NUM/IPV6_STRING_TO_NUM qt_sql_not_null_ipv6_string_to_num 'select id, hex(ipv6_string_to_num(ip6)) from fn_test_ip_not_nullable order by id' diff --git a/regression-test/suites/query_p0/sql_functions/ip_functions/test_ipv6_cidr_to_range_function.groovy b/regression-test/suites/query_p0/sql_functions/ip_functions/test_ipv6_cidr_to_range_function.groovy index 41432c986fec49..0a8ba107013b4e 100644 --- a/regression-test/suites/query_p0/sql_functions/ip_functions/test_ipv6_cidr_to_range_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/ip_functions/test_ipv6_cidr_to_range_function.groovy @@ -91,13 +91,13 @@ suite("test_ipv6_cidr_to_range_function") { (9, 'ffff:0000:0000:0000:0000:0000:0000:0000', NULL) """ - qt_sql "select id, struct_element(ipv6_cidr_to_range(ipv6_string_to_num_or_null(addr), cidr), 'min') as min_range, struct_element(ipv6_cidr_to_range(ipv6_string_to_num_or_null(addr), cidr), 'max') as max_range from test_str_cidr_to_range_function order by id" + qt_sql "select id, struct_element(ipv6_cidr_to_range(ipv6_num_to_string(ipv6_string_to_num_or_null(addr)), cidr), 'min') as min_range, struct_element(ipv6_cidr_to_range(ipv6_num_to_string(ipv6_string_to_num_or_null(addr)), cidr), 'max') as max_range from test_str_cidr_to_range_function order by id" sql """ DROP TABLE IF EXISTS test_str_cidr_to_range_function """ - qt_sql "select ipv6_cidr_to_range(ipv6_string_to_num('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 0)" - qt_sql "select ipv6_cidr_to_range(ipv6_string_to_num('2001:0db8:0000:85a3:0000:0000:ac1f:8001'), 128)" - qt_sql "select ipv6_cidr_to_range(ipv6_string_to_num('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff'), 64)" - qt_sql "select ipv6_cidr_to_range(ipv6_string_to_num('0000:0000:0000:0000:0000:0000:0000:0000'), 8)" - qt_sql "select ipv6_cidr_to_range(ipv6_string_to_num('ffff:0000:0000:0000:0000:0000:0000:0000'), 4)" + qt_sql "select ipv6_cidr_to_range(ipv6_num_to_string(ipv6_string_to_num('2001:0db8:0000:85a3:0000:0000:ac1f:8001')), 0)" + qt_sql "select ipv6_cidr_to_range(ipv6_num_to_string(ipv6_string_to_num('2001:0db8:0000:85a3:0000:0000:ac1f:8001')), 128)" + qt_sql "select ipv6_cidr_to_range(ipv6_num_to_string(ipv6_string_to_num('ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff')), 64)" + qt_sql "select ipv6_cidr_to_range(ipv6_num_to_string(ipv6_string_to_num('0000:0000:0000:0000:0000:0000:0000:0000')), 8)" + qt_sql "select ipv6_cidr_to_range(ipv6_num_to_string(ipv6_string_to_num('ffff:0000:0000:0000:0000:0000:0000:0000')), 4)" } From 6c3d290e792adc3ce3df51047c03db0c5a7d9fbc Mon Sep 17 00:00:00 2001 From: amorynan Date: Mon, 2 Dec 2024 19:12:00 +0800 Subject: [PATCH 4/4] delete un use code --- be/src/vec/functions/function_ip.h | 65 ++++++++---------------------- 1 file changed, 17 insertions(+), 48 deletions(-) diff --git a/be/src/vec/functions/function_ip.h b/be/src/vec/functions/function_ip.h index c01172270069d5..287c7eaa22b38c 100644 --- a/be/src/vec/functions/function_ip.h +++ b/be/src/vec/functions/function_ip.h @@ -902,14 +902,14 @@ class FunctionIPv6CIDRToRange : public IFunction { if (addr_type.is_ipv6()) { const auto* ipv6_addr_column = assert_cast(addr_column.get()); - col_res = execute_impl(*ipv6_addr_column, *cidr_col, input_rows_count, - add_col_const, col_const); + col_res = execute_impl(*ipv6_addr_column, *cidr_col, input_rows_count, add_col_const, + col_const); } else if (addr_type.is_string()) { ColumnPtr col_ipv6 = convert_to_ipv6(addr_column, nullptr); const auto* ipv6_addr_column = assert_cast(col_ipv6.get()); - col_res = execute_impl(*ipv6_addr_column, *cidr_col, input_rows_count, - add_col_const, col_const); + col_res = execute_impl(*ipv6_addr_column, *cidr_col, input_rows_count, add_col_const, + col_const); } else { return Status::RuntimeError( "Illegal column {} of argument of function {}, Expected IPv6 or String", @@ -920,8 +920,7 @@ class FunctionIPv6CIDRToRange : public IFunction { return Status::OK(); } - template - static ColumnPtr execute_impl(const FromColumn& from_column, const ColumnInt16& cidr_column, + static ColumnPtr execute_impl(const ColumnIPv6& from_column, const ColumnInt16& cidr_column, size_t input_rows_count, bool is_addr_const = false, bool is_cidr_const = false) { auto col_res_lower_range = ColumnIPv6::create(input_rows_count, 0); @@ -938,20 +937,10 @@ class FunctionIPv6CIDRToRange : public IFunction { throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", std::to_string(cidr)); } - if constexpr (std::is_same_v) { - // 16 bytes ipv6 string is stored in big-endian byte order - // so transfer to little-endian firstly - auto* src_data = const_cast(from_column.get_data_at(0).data); - std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), - reinterpret_cast(&vec_res_upper_range[i]), - cast_set(cidr)); - } else { - apply_cidr_mask(from_column.get_data_at(0).data, - reinterpret_cast(&vec_res_lower_range[i]), - reinterpret_cast(&vec_res_upper_range[i]), - cast_set(cidr)); - } + apply_cidr_mask(from_column.get_data_at(0).data, + reinterpret_cast(&vec_res_lower_range[i]), + reinterpret_cast(&vec_res_upper_range[i]), + cast_set(cidr)); } } else if (is_cidr_const) { auto cidr = cidr_column.get_int(0); @@ -960,20 +949,10 @@ class FunctionIPv6CIDRToRange : public IFunction { std::to_string(cidr)); } for (size_t i = 0; i < input_rows_count; ++i) { - if constexpr (std::is_same_v) { - // 16 bytes ipv6 string is stored in big-endian byte order - // so transfer to little-endian firstly - auto* src_data = const_cast(from_column.get_data_at(i).data); - std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), - reinterpret_cast(&vec_res_upper_range[i]), - cast_set(cidr)); - } else { - apply_cidr_mask(from_column.get_data_at(i).data, - reinterpret_cast(&vec_res_lower_range[i]), - reinterpret_cast(&vec_res_upper_range[i]), - cast_set(cidr)); - } + apply_cidr_mask(from_column.get_data_at(i).data, + reinterpret_cast(&vec_res_lower_range[i]), + reinterpret_cast(&vec_res_upper_range[i]), + cast_set(cidr)); } } else { for (size_t i = 0; i < input_rows_count; ++i) { @@ -982,20 +961,10 @@ class FunctionIPv6CIDRToRange : public IFunction { throw Exception(ErrorCode::INVALID_ARGUMENT, "Illegal cidr value '{}'", std::to_string(cidr)); } - if constexpr (std::is_same_v) { - // 16 bytes ipv6 string is stored in big-endian byte order - // so transfer to little-endian firstly - auto* src_data = const_cast(from_column.get_data_at(i).data); - std::reverse(src_data, src_data + IPV6_BINARY_LENGTH); - apply_cidr_mask(src_data, reinterpret_cast(&vec_res_lower_range[i]), - reinterpret_cast(&vec_res_upper_range[i]), - cast_set(cidr)); - } else { - apply_cidr_mask(from_column.get_data_at(i).data, - reinterpret_cast(&vec_res_lower_range[i]), - reinterpret_cast(&vec_res_upper_range[i]), - cast_set(cidr)); - } + apply_cidr_mask(from_column.get_data_at(i).data, + reinterpret_cast(&vec_res_lower_range[i]), + reinterpret_cast(&vec_res_upper_range[i]), + cast_set(cidr)); } } return ColumnStruct::create(