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

yiguolei 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 738e246b8f4 branch-3.0: [Bug](function) fix is_ip_address_in_range 
function parse error throw exception #45657 (#45749)
738e246b8f4 is described below

commit 738e246b8f48622169a655208a6b1d8ab4a57ba9
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sun Dec 22 21:59:22 2024 +0800

    branch-3.0: [Bug](function) fix is_ip_address_in_range function parse error 
throw exception #45657 (#45749)
    
    Cherry-picked from #45657
    
    Co-authored-by: zhangstar333 <zhangs...@selectdb.com>
---
 be/src/vec/functions/function_ip.h                 | 23 +++++++++++++++-------
 .../test_is_ip_address_in_range_function.out       |  8 ++++++++
 .../test_is_ip_address_in_range_function.groovy    |  9 +++++++++
 3 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/be/src/vec/functions/function_ip.h 
b/be/src/vec/functions/function_ip.h
index 864d0cbc220..0f22fbda043 100644
--- a/be/src/vec/functions/function_ip.h
+++ b/be/src/vec/functions/function_ip.h
@@ -615,8 +615,13 @@ public:
         for (size_t i = 0; i < input_rows_count; ++i) {
             auto addr_idx = index_check_const(i, addr_const);
             auto cidr_idx = index_check_const(i, cidr_const);
-            const auto cidr =
-                    
parse_ip_with_cidr(str_cidr_column->get_data_at(cidr_idx).to_string_view());
+            auto cidr_data = str_cidr_column->get_data_at(cidr_idx);
+            // cidr_data maybe NULL, But the input column is nested column, so 
check here avoid throw exception
+            if (cidr_data.data == nullptr || cidr_data.size == 0) {
+                col_res_data[i] = 0;
+                continue;
+            }
+            const auto cidr = parse_ip_with_cidr(cidr_data.to_string_view());
             if constexpr (PT == PrimitiveType::TYPE_IPV4) {
                 if (cidr._address.as_v4()) {
                     col_res_data[i] = match_ipv4_subnet(ip_data[addr_idx], 
cidr._address.as_v4(),
@@ -775,11 +780,15 @@ public:
             for (size_t i = 0; i < input_rows_count; ++i) {
                 auto addr_idx = index_check_const(i, addr_const);
                 auto cidr_idx = index_check_const(i, cidr_const);
-
-                const auto addr =
-                        
IPAddressVariant(str_addr_column->get_data_at(addr_idx).to_string_view());
-                const auto cidr =
-                        
parse_ip_with_cidr(str_cidr_column->get_data_at(cidr_idx).to_string_view());
+                auto addr_data = str_addr_column->get_data_at(addr_idx);
+                auto cidr_data = str_cidr_column->get_data_at(cidr_idx);
+                // cidr_data maybe NULL, But the input column is nested 
column, so check here avoid throw exception
+                if (cidr_data.data == nullptr || cidr_data.size == 0) {
+                    col_res_data[i] = 0;
+                    continue;
+                }
+                const auto addr = IPAddressVariant(addr_data.to_string_view());
+                const auto cidr = 
parse_ip_with_cidr(cidr_data.to_string_view());
                 col_res_data[i] = is_address_in_range(addr, cidr) ? 1 : 0;
             }
         }
diff --git 
a/regression-test/data/query_p0/sql_functions/ip_functions/test_is_ip_address_in_range_function.out
 
b/regression-test/data/query_p0/sql_functions/ip_functions/test_is_ip_address_in_range_function.out
index 285b861b742..759b6c890ea 100644
--- 
a/regression-test/data/query_p0/sql_functions/ip_functions/test_is_ip_address_in_range_function.out
+++ 
b/regression-test/data/query_p0/sql_functions/ip_functions/test_is_ip_address_in_range_function.out
@@ -92,3 +92,11 @@
 -- !sql --
 \N
 
+-- !sql1 --
+54     2001:db8:4::/128
+55     \N
+
+-- !sql2 --
+\N     \N
+2001:db8:4::/128       false
+
diff --git 
a/regression-test/suites/query_p0/sql_functions/ip_functions/test_is_ip_address_in_range_function.groovy
 
b/regression-test/suites/query_p0/sql_functions/ip_functions/test_is_ip_address_in_range_function.groovy
index 812bfffeb2f..cee47c81813 100644
--- 
a/regression-test/suites/query_p0/sql_functions/ip_functions/test_is_ip_address_in_range_function.groovy
+++ 
b/regression-test/suites/query_p0/sql_functions/ip_functions/test_is_ip_address_in_range_function.groovy
@@ -78,4 +78,13 @@ suite("test_is_ip_address_in_range_function") {
     qt_sql "SELECT is_ip_address_in_range(NULL, '::ffff:192.168.0.4/128')"
 
     qt_sql "SELECT is_ip_address_in_range(NULL, NULL)"
+
+
+    sql """ DROP TABLE IF EXISTS ip_test """
+    sql """ CREATE TABLE IF NOT EXISTS ip_test(id INT, data string) 
DISTRIBUTED BY HASH(id) BUCKETS 1 PROPERTIES ('replication_num' = '1');"""
+    sql """ INSERT INTO ip_test values (54, '2001:db8:4::/128'); """
+    sql """ INSERT INTO ip_test values (55, NULL); """
+    qt_sql1 """ select * from ip_test order by 1; """
+    qt_sql2 "SELECT  data,   IS_IP_ADDRESS_IN_RANGE(CAST('0.0.0.1' AS STRING), 
data) FROM ip_test order by 1;"
+
 }
\ No newline at end of file


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org
For additional commands, e-mail: commits-h...@doris.apache.org

Reply via email to