This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new 0928ace94f6 branch-3.0: [Bug](function) fix cut_ipv6 function error 
about modify the input column data #43921 (#44179)
0928ace94f6 is described below

commit 0928ace94f6e080e012dff9c222bb34d4e7cae53
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Mon Nov 18 22:30:30 2024 +0800

    branch-3.0: [Bug](function) fix cut_ipv6 function error about modify the 
input column data #43921 (#44179)
    
    Cherry-picked from #43921
    
    Co-authored-by: zhangstar333 <[email protected]>
---
 be/src/vec/functions/function_ip.h                       |  7 +++++--
 .../ip_functions/test_cut_ipv6_function.out              |  5 +++++
 .../ip_functions/test_cut_ipv6_function.groovy           | 16 ++++++++++++++++
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/be/src/vec/functions/function_ip.h 
b/be/src/vec/functions/function_ip.h
index ddb99d80a1b..25f09bb594a 100644
--- a/be/src/vec/functions/function_ip.h
+++ b/be/src/vec/functions/function_ip.h
@@ -1290,9 +1290,12 @@ public:
             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<unsigned char*>(&val_128);
 
-            auto* address = const_cast<unsigned char*>(
-                    reinterpret_cast<const unsigned 
char*>(&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 c549c1533cd..3d17c87cb94 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 099705e2383..25eb010403c 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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to