diff --git a/be/src/vec/functions/function_ip.h b/be/src/vec/functions/function_ip.h index 67edad5015aeaf..1a1c23e2b06c35 100644 --- a/be/src/vec/functions/function_ip.h +++ b/be/src/vec/functions/function_ip.h @@ -615,8 +615,13 @@ class FunctionIsIPAddressInRange : public IFunction { 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 @@ class FunctionIsIPAddressInRange : public IFunction { 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 285b861b742c5b..759b6c890ea13e 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 812bfffeb2f3e0..cee47c818130a7 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