From e69dffc6f3ea752b8a3a7a3035317598e9280750 Mon Sep 17 00:00:00 2001 From: Denis Khalikov Date: Mon, 17 Jun 2024 16:58:11 +0300 Subject: [PATCH] MCOL-5237 Proper handle DATETIME column for "ifnull" function. (#3201) --- .../columnstore/bugfixes/mcol-5237.result | 16 ++++++++++++ .../columnstore/bugfixes/mcol-5237.test | 26 +++++++++++++++++++ utils/funcexp/func_ifnull.cpp | 10 ++++++- 3 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 mysql-test/columnstore/bugfixes/mcol-5237.result create mode 100644 mysql-test/columnstore/bugfixes/mcol-5237.test diff --git a/mysql-test/columnstore/bugfixes/mcol-5237.result b/mysql-test/columnstore/bugfixes/mcol-5237.result new file mode 100644 index 000000000..89741efac --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol-5237.result @@ -0,0 +1,16 @@ +DROP DATABASE IF EXISTS mcol_5237; +CREATE DATABASE mcol_5237; +USE mcol_5237; +create table t1 (a varchar(1000), b datetime, c int) ENGINE=Columnstore DEFAULT CHARSET=utf8; +insert into t1 values +('abc', null, 1), +('xyz', str_to_date('2022-09-22 00:00:00', '%Y-%m-%d %H:%i:%s'), 1); +create view v1 as +select a, NVL(b, str_to_date('1970-01-01 00:00:00', '%Y-%m-%d %H:%i:%s')) as b, c from t1; +select count(*) from v1 where YEAR(b) = 2022; +count(*) +1 +select count(*) from v1 where YEAR(b) = 1970; +count(*) +1 +DROP DATABASE mcol_5237; diff --git a/mysql-test/columnstore/bugfixes/mcol-5237.test b/mysql-test/columnstore/bugfixes/mcol-5237.test new file mode 100644 index 000000000..05e3458d4 --- /dev/null +++ b/mysql-test/columnstore/bugfixes/mcol-5237.test @@ -0,0 +1,26 @@ +# +# MCOL-5237 +# + +--source ../include/have_columnstore.inc + +--disable_warnings +DROP DATABASE IF EXISTS mcol_5237; +--enable_warnings +CREATE DATABASE mcol_5237; +USE mcol_5237; +create table t1 (a varchar(1000), b datetime, c int) ENGINE=Columnstore DEFAULT CHARSET=utf8; + +insert into t1 values +('abc', null, 1), +('xyz', str_to_date('2022-09-22 00:00:00', '%Y-%m-%d %H:%i:%s'), 1); + +create view v1 as +select a, NVL(b, str_to_date('1970-01-01 00:00:00', '%Y-%m-%d %H:%i:%s')) as b, c from t1; + +select count(*) from v1 where YEAR(b) = 2022; +select count(*) from v1 where YEAR(b) = 1970; + +--disable_warnings +DROP DATABASE mcol_5237; +--enable_warnings diff --git a/utils/funcexp/func_ifnull.cpp b/utils/funcexp/func_ifnull.cpp index 7cb5ebebc..2dcb67736 100644 --- a/utils/funcexp/func_ifnull.cpp +++ b/utils/funcexp/func_ifnull.cpp @@ -25,6 +25,7 @@ #include using namespace std; +#include "constantcolumn.h" #include "functor_all.h" #include "functioncolumn.h" using namespace execplan; @@ -60,7 +61,14 @@ int64_t Func_ifnull::getIntVal(Row& row, FunctionParm& parm, bool& isNull, Calpo if (isNull) { isNull = false; - return parm[1]->data()->getIntVal(row, isNull); + r = parm[1]->data()->getIntVal(row, isNull); + // MCOL-5237 In case we substitude a null value for `DATETIME` column with a value from `ConstantColumn` + // we have to convert the value into the `DATETIME` format for `int64_t` type. + if (parm[0]->data()->resultType().colDataType == CalpontSystemCatalog::DATETIME && + dynamic_cast(parm[1]->data())) + { + r = r << 48; + } } return r;