This is an automated email from the ASF dual-hosted git repository.
yiguolei pushed a commit to branch branch-1.2-lts
in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-1.2-lts by this push:
new 9df769a462 [fix](in) fix wrong DCHECK of in expr for not nullable
column (#21934)
9df769a462 is described below
commit 9df769a462fa9c06acbb75616894812d161ad718
Author: TengJianPing <[email protected]>
AuthorDate: Tue Jul 18 19:31:01 2023 +0800
[fix](in) fix wrong DCHECK of in expr for not nullable column (#21934)
DCHECK(!in_state->null_in_set); in FunctionIn::execute_impl when left
column is not nullable is not necessary, remove it;
function convert_type_to_primitive in be/src/runtime/primitive_type.cpp
forget to handle float type, fix it;
when left column is not nullable, if values in expr list have null value,
nullable flags should also be set as when left column is nullable.
---
be/src/runtime/primitive_type.cpp | 54 ++++----
be/src/vec/functions/in.h | 6 +-
.../data/query_p0/sql_functions/test_in_expr.out | 144 ++++++++++++++++++++-
.../query_p0/sql_functions/test_in_expr.groovy | 34 ++++-
4 files changed, 201 insertions(+), 37 deletions(-)
diff --git a/be/src/runtime/primitive_type.cpp
b/be/src/runtime/primitive_type.cpp
index 779676a45d..9e4fd901ea 100644
--- a/be/src/runtime/primitive_type.cpp
+++ b/be/src/runtime/primitive_type.cpp
@@ -29,36 +29,10 @@ PrimitiveType
convert_type_to_primitive(FunctionContext::Type type) {
switch (type) {
case FunctionContext::Type::INVALID_TYPE:
return PrimitiveType::INVALID_TYPE;
- case FunctionContext::Type::TYPE_DOUBLE:
- return PrimitiveType::TYPE_DOUBLE;
case FunctionContext::Type::TYPE_NULL:
return PrimitiveType::TYPE_NULL;
- case FunctionContext::Type::TYPE_CHAR:
- return PrimitiveType::TYPE_CHAR;
- case FunctionContext::Type::TYPE_VARCHAR:
- return PrimitiveType::TYPE_VARCHAR;
- case FunctionContext::Type::TYPE_STRING:
- return PrimitiveType::TYPE_STRING;
- case FunctionContext::Type::TYPE_DATETIME:
- return PrimitiveType::TYPE_DATETIME;
- case FunctionContext::Type::TYPE_DECIMALV2:
- return PrimitiveType::TYPE_DECIMALV2;
- case FunctionContext::Type::TYPE_DECIMAL32:
- return PrimitiveType::TYPE_DECIMAL32;
- case FunctionContext::Type::TYPE_DECIMAL64:
- return PrimitiveType::TYPE_DECIMAL64;
- case FunctionContext::Type::TYPE_DECIMAL128I:
- return PrimitiveType::TYPE_DECIMAL128I;
case FunctionContext::Type::TYPE_BOOLEAN:
return PrimitiveType::TYPE_BOOLEAN;
- case FunctionContext::Type::TYPE_ARRAY:
- return PrimitiveType::TYPE_ARRAY;
- case FunctionContext::Type::TYPE_OBJECT:
- return PrimitiveType::TYPE_OBJECT;
- case FunctionContext::Type::TYPE_HLL:
- return PrimitiveType::TYPE_HLL;
- case FunctionContext::Type::TYPE_QUANTILE_STATE:
- return PrimitiveType::TYPE_QUANTILE_STATE;
case FunctionContext::Type::TYPE_TINYINT:
return PrimitiveType::TYPE_TINYINT;
case FunctionContext::Type::TYPE_SMALLINT:
@@ -69,14 +43,42 @@ PrimitiveType
convert_type_to_primitive(FunctionContext::Type type) {
return PrimitiveType::TYPE_BIGINT;
case FunctionContext::Type::TYPE_LARGEINT:
return PrimitiveType::TYPE_LARGEINT;
+ case FunctionContext::Type::TYPE_FLOAT:
+ return PrimitiveType::TYPE_FLOAT;
+ case FunctionContext::Type::TYPE_DOUBLE:
+ return PrimitiveType::TYPE_DOUBLE;
case FunctionContext::Type::TYPE_DATE:
return PrimitiveType::TYPE_DATE;
+ case FunctionContext::Type::TYPE_DATETIME:
+ return PrimitiveType::TYPE_DATETIME;
+ case FunctionContext::Type::TYPE_CHAR:
+ return PrimitiveType::TYPE_CHAR;
+ case FunctionContext::Type::TYPE_VARCHAR:
+ return PrimitiveType::TYPE_VARCHAR;
+ case FunctionContext::Type::TYPE_HLL:
+ return PrimitiveType::TYPE_HLL;
+ case FunctionContext::Type::TYPE_STRING:
+ return PrimitiveType::TYPE_STRING;
+ case FunctionContext::Type::TYPE_DECIMALV2:
+ return PrimitiveType::TYPE_DECIMALV2;
+ case FunctionContext::Type::TYPE_OBJECT:
+ return PrimitiveType::TYPE_OBJECT;
+ case FunctionContext::Type::TYPE_ARRAY:
+ return PrimitiveType::TYPE_ARRAY;
+ case FunctionContext::Type::TYPE_QUANTILE_STATE:
+ return PrimitiveType::TYPE_QUANTILE_STATE;
case FunctionContext::Type::TYPE_DATEV2:
return PrimitiveType::TYPE_DATEV2;
case FunctionContext::Type::TYPE_DATETIMEV2:
return PrimitiveType::TYPE_DATETIMEV2;
case FunctionContext::Type::TYPE_TIMEV2:
return PrimitiveType::TYPE_TIMEV2;
+ case FunctionContext::Type::TYPE_DECIMAL32:
+ return PrimitiveType::TYPE_DECIMAL32;
+ case FunctionContext::Type::TYPE_DECIMAL64:
+ return PrimitiveType::TYPE_DECIMAL64;
+ case FunctionContext::Type::TYPE_DECIMAL128I:
+ return PrimitiveType::TYPE_DECIMAL128I;
case FunctionContext::Type::TYPE_JSONB:
return PrimitiveType::TYPE_JSONB;
default:
diff --git a/be/src/vec/functions/in.h b/be/src/vec/functions/in.h
index 626060e399..756eac91b8 100644
--- a/be/src/vec/functions/in.h
+++ b/be/src/vec/functions/in.h
@@ -156,7 +156,6 @@ public:
}
} else { // non-nullable
- DCHECK(!in_state->null_in_set);
auto search_hash_set = [&](auto* col_ptr) {
for (size_t i = 0; i < input_rows_count; ++i) {
@@ -177,6 +176,11 @@ public:
} else {
search_hash_set(materialized_column.get());
}
+ if (in_state->null_in_set) {
+ for (size_t i = 0; i < input_rows_count; ++i) {
+ vec_null_map_to[i] = negative == vec_res[i];
+ }
+ }
}
} else {
std::vector<ColumnPtr> set_columns;
diff --git a/regression-test/data/query_p0/sql_functions/test_in_expr.out
b/regression-test/data/query_p0/sql_functions/test_in_expr.out
index c7f58848a5..654440cc2d 100644
--- a/regression-test/data/query_p0/sql_functions/test_in_expr.out
+++ b/regression-test/data/query_p0/sql_functions/test_in_expr.out
@@ -8,12 +8,60 @@
-- !select --
-- !select --
-103 4 d
-
--- !select --
-103 4 d
-
--- !select --
+103 4 d 1.4
+
+-- !select --
+103 4 d 1.4
+
+-- !select --
+
+-- !select_float_in --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+1.5 \N
+\N \N
+
+-- !select_float_in2 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+1.5 \N
+\N \N
+
+-- !select_float_in3 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+1.5 \N
+\N \N
+
+-- !select_float_in4 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+1.5 \N
+\N \N
+
+-- !select_float_in5 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+1.5 \N
+\N \N
+
+-- !select_float_in6 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+1.5 \N
+\N \N
-- !select --
c
@@ -53,6 +101,90 @@ a
b
d
+-- !select_not_null_in_null --
+100 true
+101 \N
+102 \N
+103 \N
+
+-- !select_not_null_in_null2 --
+100 \N
+101 \N
+102 \N
+103 \N
+
+-- !select_not_null_in_null3 --
+a true
+b \N
+c \N
+d \N
+
+-- !select_not_null_in_null4 --
+a \N
+b \N
+c \N
+d \N
+
+-- !select_not_null_not_in_null --
+100 false
+101 \N
+102 \N
+103 \N
+
+-- !select_not_null_not_in_null2 --
+100 \N
+101 \N
+102 \N
+103 \N
+
+-- !select_not_null_not_in_null3 --
+a false
+b \N
+c \N
+d \N
+
+-- !select_not_null_not_in_null4 --
+a \N
+b \N
+c \N
+d \N
+
+-- !select_not_null_float_in --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+
+-- !select_not_null_float_in2 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+
+-- !select_not_null_float_in3 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+
+-- !select_not_null_float_in4 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+
+-- !select_not_null_float_in5 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+
+-- !select_not_null_float_in6 --
+1.1 \N
+1.2 \N
+1.3 \N
+1.4 \N
+
-- !select --
2
3
diff --git a/regression-test/suites/query_p0/sql_functions/test_in_expr.groovy
b/regression-test/suites/query_p0/sql_functions/test_in_expr.groovy
index a2424e4d82..495c359fe2 100644
--- a/regression-test/suites/query_p0/sql_functions/test_in_expr.groovy
+++ b/regression-test/suites/query_p0/sql_functions/test_in_expr.groovy
@@ -24,7 +24,8 @@ suite("test_in_expr", "query") {
CREATE TABLE IF NOT EXISTS ${nullTableName} (
`cid` int(11) NULL,
`number` int(11) NULL,
- `addr` varchar(256) NULL
+ `addr` varchar(256) NULL,
+ `fnum` float NULL
) ENGINE=OLAP
DUPLICATE KEY(`cid`)
COMMENT 'OLAP'
@@ -35,7 +36,7 @@ suite("test_in_expr", "query") {
"storage_format" = "V2"
)
"""
- sql """ insert into ${nullTableName}
values(100,1,'a'),(101,2,'b'),(102,3,'c'),(103,4,'d'),(104,null,'e'),(105,6,
null) """
+ sql """ insert into ${nullTableName} values(100,1,'a',
1.1),(101,2,'b',1.2),(102,3,'c',1.3),(103,4,'d',1.4),(104,null,'e',1.5),(105,6,
null,null) """
sql """DROP TABLE IF EXISTS ${notNullTableName}"""
@@ -43,7 +44,8 @@ suite("test_in_expr", "query") {
CREATE TABLE IF NOT EXISTS ${notNullTableName} (
`cid` int(11) not NULL,
`number` int(11) not NULL,
- `addr` varchar(256) not NULL
+ `addr` varchar(256) not NULL,
+ `fnum` float not NULL
) ENGINE=OLAP
DUPLICATE KEY(`cid`)
COMMENT 'OLAP'
@@ -55,7 +57,7 @@ suite("test_in_expr", "query") {
)
"""
- sql """ insert into ${notNullTableName}
values(100,1,'a'),(101,2,'b'),(102,3,'c'),(103,4,'d') """
+ sql """ insert into ${notNullTableName} values(100,1,'a', 1.1),(101,2,'b',
1.2),(102,3,'c',1.3),(103,4,'d',1.4) """
sql """ set enable_vectorized_engine = true """
@@ -75,6 +77,13 @@ suite("test_in_expr", "query") {
qt_select "select * from ${nullTableName} where not(addr in ('d', null))"
+ qt_select_float_in """ select fnum, fnum in (1.1, null) from
${nullTableName} order by cid"""
+ qt_select_float_in2 """ select fnum, not (fnum in (1.1, null)) from
${nullTableName} order by cid"""
+ qt_select_float_in3 """ select fnum, fnum not in (1.1, null) from
${nullTableName} order by cid"""
+ qt_select_float_in4 """ select fnum, fnum in (null) from ${nullTableName}
order by cid"""
+ qt_select_float_in5 """ select fnum, not(fnum in (null)) from
${nullTableName} order by cid"""
+ qt_select_float_in6 """ select fnum, fnum not in (null) from
${nullTableName} order by cid"""
+
// 1.1.3 non-string
qt_select "select t1.addr from ${nullTableName} t1 left join
${nullTableName} t2 on t1.cid=t2.cid where t2.number in (3)"
@@ -112,6 +121,23 @@ suite("test_in_expr", "query") {
// 2.1.3 non-string
qt_select "select t1.addr from ${notNullTableName} t1 left join
${notNullTableName} t2 on t1.cid=t2.cid where t2.number not in (3) order by
t1.addr "
+ qt_select_not_null_in_null """ select cid, cid in (100, null) from
${notNullTableName} order by cid"""
+ qt_select_not_null_in_null2 """ select cid, cid in (null) from
${notNullTableName} order by cid"""
+ qt_select_not_null_in_null3 """ select addr, addr in ('a', null) from
${notNullTableName} order by addr"""
+ qt_select_not_null_in_null4 """ select addr, addr in (null) from
${notNullTableName} order by addr"""
+
+ qt_select_not_null_not_in_null """ select cid, cid not in (100, null) from
${notNullTableName} order by cid"""
+ qt_select_not_null_not_in_null2 """ select cid, cid not in (null) from
${notNullTableName} order by cid"""
+ qt_select_not_null_not_in_null3 """ select addr, addr not in ('a', null)
from ${notNullTableName} order by addr"""
+ qt_select_not_null_not_in_null4 """ select addr, addr not in (null) from
${notNullTableName} order by addr"""
+
+ qt_select_not_null_float_in """ select fnum, fnum in (1.1, null) from
${notNullTableName} order by cid"""
+ qt_select_not_null_float_in2 """ select fnum, not (fnum in (1.1, null))
from ${notNullTableName} order by cid"""
+ qt_select_not_null_float_in3 """ select fnum, fnum not in (1.1, null)
from ${notNullTableName} order by cid"""
+ qt_select_not_null_float_in4 """ select fnum, fnum in (null) from
${notNullTableName} order by cid"""
+ qt_select_not_null_float_in5 """ select fnum, not(fnum in (null)) from
${notNullTableName} order by cid"""
+ qt_select_not_null_float_in6 """ select fnum, fnum not in (null) from
${notNullTableName} order by cid"""
+
sql """DROP TABLE IF EXISTS ${nullTableName}"""
sql """DROP TABLE IF EXISTS ${notNullTableName}"""
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]