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

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


The following commit(s) were added to refs/heads/master by this push:
     new 03bc0518e38 [Bug](function) fix cut_ipv6 function error about modify 
the input column data (#43921)
03bc0518e38 is described below

commit 03bc0518e383a90a61577b42394856f4ad17676e
Author: zhangstar333 <[email protected]>
AuthorDate: Mon Nov 18 17:35:24 2024 +0800

    [Bug](function) fix cut_ipv6 function error about modify the input column 
data (#43921)
    
    
![cut_ipv6](https://github.com/user-attachments/assets/c4cde1d4-f812-4e25-bc45-c1e0e43ff08c)
    
    the ipv6 function maybe need reverse the input ipv6 data, but can't do
    it at the input data
    could copy to another data area process it.
---
 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 69fd2a89148..b90d1b2bcf9 100644
--- a/be/src/vec/functions/function_ip.h
+++ b/be/src/vec/functions/function_ip.h
@@ -1296,9 +1296,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