This is an automated email from the ASF dual-hosted git repository.
zhangstar333 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 0ab4eae228e [Bug](function) fix is_ip_address_in_range function parse
error throw exception (#45657)
0ab4eae228e is described below
commit 0ab4eae228e815b3237e70dab54d67808df634df
Author: zhangstar333 <[email protected]>
AuthorDate: Fri Dec 20 22:49:46 2024 +0800
[Bug](function) fix is_ip_address_in_range function parse error throw
exception (#45657)
### What problem does this PR solve?
Problem Summary:
before: will be throw exception when parse NULL value, as the input is
empty invalid.
so need check firstly and then parse it.
```
mysql [test]>select * from ip_test;
+------+------------------+
| id | data |
+------+------------------+
| 54 | 2001:db8:4::/128 |
| 55 | NULL |
+------+------------------+
2 rows in set (0.07 sec)
mysql [test]>SELECT data, IS_IP_ADDRESS_IN_RANGE(CAST('0.0.0.1' AS
STRING), data) FROM ip_test;
ERROR 1105 (HY000): errCode = 2, detailMessage =
(10.16.10.8)[INVALID_ARGUMENT][E33] The text does not contain '/':
```
---
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 67edad5015a..1a1c23e2b06 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: [email protected]
For additional commands, e-mail: [email protected]