From 0ad593404dc23c511f2e8a0b8a550f9f3e70c0ff Mon Sep 17 00:00:00 2001 From: fuzhe1989 Date: Fri, 5 Nov 2021 17:41:59 +0800 Subject: [PATCH 1/2] update --- dbms/src/Functions/FunctionsNull.cpp | 2 +- dbms/src/Functions/tests/gtest_coalesce.cpp | 34 +++++++++++++++++++ .../expr/coalesce_pushdown.test | 16 +++++++-- 3 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 dbms/src/Functions/tests/gtest_coalesce.cpp diff --git a/dbms/src/Functions/FunctionsNull.cpp b/dbms/src/Functions/FunctionsNull.cpp index 84b13497a75..61f7bb6ec2f 100644 --- a/dbms/src/Functions/FunctionsNull.cpp +++ b/dbms/src/Functions/FunctionsNull.cpp @@ -213,7 +213,7 @@ void FunctionCoalesce::executeImpl(Block & block, const ColumnNumbers & argument ColumnPtr res = std::move(temp_block.getByPosition(result).column); /// if last argument is not nullable, result should be also not nullable - if (!block.getByPosition(multi_if_args.back()).column->isColumnNullable() && res->isColumnNullable()) + if (!block.getByPosition(filtered_args.back()).type->isNullable() && res->isColumnNullable()) res = static_cast(*res).getNestedColumnPtr(); block.getByPosition(result).column = std::move(res); diff --git a/dbms/src/Functions/tests/gtest_coalesce.cpp b/dbms/src/Functions/tests/gtest_coalesce.cpp new file mode 100644 index 00000000000..5d338e65c1f --- /dev/null +++ b/dbms/src/Functions/tests/gtest_coalesce.cpp @@ -0,0 +1,34 @@ +#include +#include +#include + +#include +#include + +namespace DB::tests +{ +class CoalesceTest : public DB::tests::FunctionTest +{ +}; + +TEST_F(CoalesceTest, testOnlyNull) +try +{ + const String & func_name = "coalesce"; + + ASSERT_COLUMN_EQ( + createColumn>({"a"}), + executeFunction( + func_name, + createColumn>({"a"}), + createConstColumn>(1, std::nullopt))); + + ASSERT_COLUMN_EQ( + createColumn>({"a"}), + executeFunction( + func_name, + createColumn>({"a"}), + createOnlyNullColumn(1))); +} +CATCH +} // namespace DB::tests diff --git a/tests/fullstack-test/expr/coalesce_pushdown.test b/tests/fullstack-test/expr/coalesce_pushdown.test index 9b89f5e76d8..e10c281a847 100644 --- a/tests/fullstack-test/expr/coalesce_pushdown.test +++ b/tests/fullstack-test/expr/coalesce_pushdown.test @@ -5,9 +5,11 @@ mysql> INSERT INTO test.test_tb(id,char_,enum_,longtext_,mediumtext_,set_,text_, mysql> analyze table test.test_tb mysql> alter table test.test_tb set tiflash replica 1 -func> wait_table test test_tb - - +mysql> drop table if exists test.fix_3388 +mysql> create table if not exists test.fix_3388(a varchar(10)) +mysql> alter table test.fix_3388 set tiflash replica 1 +mysql> insert into test.fix_3388 values ("a") +func> wait_table test test_tb fix_3388 # start checking mysql> select /*+ read_from_storage(tiflash[test.test_tb]) */ id from test.test_tb where char_ = coalesce(null, char_); @@ -335,3 +337,11 @@ mysql> select /*+ read_from_storage(tiflash[test.test_tb]) */ id from test.test_ | 2 | +----+ +# fix 3388 +mysql> set tidb_enforce_mpp=1; select count(*) from test.fix_3388 where coalesce(a, null) = "a" ++----------+ +| count(*) | ++----------+ +| 1 | ++----------+ + From d2611a53bbbdcd631c6bd615bd58a74f645b0a3c Mon Sep 17 00:00:00 2001 From: Fu Zhe Date: Fri, 5 Nov 2021 19:29:09 +0800 Subject: [PATCH 2/2] Update coalesce_pushdown.test --- tests/fullstack-test/expr/coalesce_pushdown.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fullstack-test/expr/coalesce_pushdown.test b/tests/fullstack-test/expr/coalesce_pushdown.test index e10c281a847..698de84e350 100644 --- a/tests/fullstack-test/expr/coalesce_pushdown.test +++ b/tests/fullstack-test/expr/coalesce_pushdown.test @@ -8,7 +8,7 @@ mysql> alter table test.test_tb set tiflash replica 1 mysql> drop table if exists test.fix_3388 mysql> create table if not exists test.fix_3388(a varchar(10)) mysql> alter table test.fix_3388 set tiflash replica 1 -mysql> insert into test.fix_3388 values ("a") +mysql> insert into test.fix_3388 values ('a') func> wait_table test test_tb fix_3388 # start checking