diff --git a/be/src/vec/functions/function_ip.h b/be/src/vec/functions/function_ip.h index 69fd2a8914890e..b90d1b2bcf9434 100644 --- a/be/src/vec/functions/function_ip.h +++ b/be/src/vec/functions/function_ip.h @@ -1296,9 +1296,12 @@ class FunctionCutIPv6 : public IFunction { auto ipv6_idx = index_check_const(i, ipv6_const); auto bytes_to_cut_for_ipv6_idx = index_check_const(i, bytes_to_cut_for_ipv6_const); auto bytes_to_cut_for_ipv4_idx = index_check_const(i, bytes_to_cut_for_ipv4_const); + // the current function logic is processed in big endian manner + // But ipv6 in doris is stored in little-endian byte order + // need transfer to big-endian byte order first, so we can't deal this process in column + auto val_128 = ipv6_addr_column_data[ipv6_idx]; + auto* address = reinterpret_cast(&val_128); - auto* address = const_cast( - reinterpret_cast(&ipv6_addr_column_data[ipv6_idx])); Int8 bytes_to_cut_for_ipv6_count = to_cut_for_ipv6_bytes_column_data[bytes_to_cut_for_ipv6_idx]; Int8 bytes_to_cut_for_ipv4_count = diff --git a/regression-test/data/query_p0/sql_functions/ip_functions/test_cut_ipv6_function.out b/regression-test/data/query_p0/sql_functions/ip_functions/test_cut_ipv6_function.out index c549c1533cd1ab..3d17c87cb94a72 100644 --- a/regression-test/data/query_p0/sql_functions/ip_functions/test_cut_ipv6_function.out +++ b/regression-test/data/query_p0/sql_functions/ip_functions/test_cut_ipv6_function.out @@ -1,3 +1,4 @@ +-- This file is automatically generated. You should know what you did if you want to edit this -- !sql -- :: ::ffff:0.0.0.0 :: ::ffff:192.168.0.0 @@ -17,3 +18,7 @@ ffff:ffff:ffff:ffff:: :: -- !sql -- \N + +-- !sql -- +0 182a:556f:6665:4fb1:a0f0:40ff:3af2:7ad3 + diff --git a/regression-test/suites/query_p0/sql_functions/ip_functions/test_cut_ipv6_function.groovy b/regression-test/suites/query_p0/sql_functions/ip_functions/test_cut_ipv6_function.groovy index 099705e2383acc..25eb010403cdcf 100644 --- a/regression-test/suites/query_p0/sql_functions/ip_functions/test_cut_ipv6_function.groovy +++ b/regression-test/suites/query_p0/sql_functions/ip_functions/test_cut_ipv6_function.groovy @@ -53,4 +53,20 @@ suite("test_cut_ipv6_function") { qt_sql "select cut_ipv6(to_ipv6('2001:0DB8:AC10:FE01:FEED:BABE:CAFE:F00D'), 0, NULL)" sql "DROP TABLE test_cut_ipv6_function" + + sql """ DROP TABLE IF EXISTS test_cutipv6 """ + sql """ + CREATE TABLE `test_cutipv6` ( + `pk` int NOT NULL, + `col_ipv6_undef_signed` ipv6 NULL + ) ENGINE=OLAP + UNIQUE KEY(`pk`) + DISTRIBUTED BY HASH(`pk`) BUCKETS 10 + PROPERTIES ( + "replication_allocation" = "tag.location.default: 1" + ); + """ + sql """ insert into test_cutipv6 values(0,"182a:556f:6665:4fb1:a0f0:40ff:3af2:7ad3"); """ + qt_sql "select pk,col_ipv6_undef_signed from test_cutipv6 where cut_ipv6(col_ipv6_undef_signed, 4, 7) != '182a:556f:6665:4fb1:a0f0:40ff:3af2:7ad3';" + } \ No newline at end of file