diff --git a/dbms/src/Flash/Coprocessor/TiDBBit.h b/dbms/src/Flash/Coprocessor/TiDBBit.h index 442198e80da..5c1684a7068 100644 --- a/dbms/src/Flash/Coprocessor/TiDBBit.h +++ b/dbms/src/Flash/Coprocessor/TiDBBit.h @@ -5,7 +5,6 @@ #include #pragma GCC diagnostic pop -#include #include #include #include diff --git a/dbms/src/Flash/Coprocessor/TiDBEnum.h b/dbms/src/Flash/Coprocessor/TiDBEnum.h index 4c1679eba2c..71b98315fe4 100644 --- a/dbms/src/Flash/Coprocessor/TiDBEnum.h +++ b/dbms/src/Flash/Coprocessor/TiDBEnum.h @@ -5,7 +5,6 @@ #include #pragma GCC diagnostic pop -#include #include #include diff --git a/dbms/src/Functions/FunctionsComparison.h b/dbms/src/Functions/FunctionsComparison.h index 3ec28334953..8f7846ce324 100644 --- a/dbms/src/Functions/FunctionsComparison.h +++ b/dbms/src/Functions/FunctionsComparison.h @@ -7,8 +7,6 @@ #include #include -#include - #include #include #include diff --git a/dbms/src/Functions/FunctionsConversion.h b/dbms/src/Functions/FunctionsConversion.h index e09f7b93280..83ec5f1c08b 100644 --- a/dbms/src/Functions/FunctionsConversion.h +++ b/dbms/src/Functions/FunctionsConversion.h @@ -1676,8 +1676,13 @@ class FunctionStrToDate : public IFunction { if (input_column->isColumnNullable()) { - null_res[i] = input_column->isNullAt(i); - continue; + // For null input, just set the result as null + if (bool is_null = input_column->isNullAt(i); is_null) + { + null_res[i] = is_null; + continue; + } + // else fallthrough to parsing } const auto str_ref = col_from->getDataAt(i); diff --git a/dbms/src/Storages/DeltaMerge/DeltaMergeHelpers.cpp b/dbms/src/Storages/DeltaMerge/DeltaMergeHelpers.cpp index 5b1cb728942..ed1ab3de3b0 100644 --- a/dbms/src/Storages/DeltaMerge/DeltaMergeHelpers.cpp +++ b/dbms/src/Storages/DeltaMerge/DeltaMergeHelpers.cpp @@ -1,3 +1,4 @@ +#include #include namespace DB @@ -101,4 +102,4 @@ void appendIntoHandleColumn(ColumnVector::Container & handle_column, con } } // namespace DM -} // namespace DB \ No newline at end of file +} // namespace DB diff --git a/dbms/src/Storages/DeltaMerge/DeltaMergeHelpers.h b/dbms/src/Storages/DeltaMerge/DeltaMergeHelpers.h index d5ece791928..e7b3a9930bb 100644 --- a/dbms/src/Storages/DeltaMerge/DeltaMergeHelpers.h +++ b/dbms/src/Storages/DeltaMerge/DeltaMergeHelpers.h @@ -7,9 +7,7 @@ #include #include #include -#include #include -#include #include #include #include diff --git a/dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp b/dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp index e40c833b17e..7829c211050 100644 --- a/dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp +++ b/dbms/src/Storages/DeltaMerge/DeltaMergeStore.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp b/dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp index 18089f84ac6..c6d2f4922a2 100644 --- a/dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp +++ b/dbms/src/Storages/DeltaMerge/Index/MinMaxIndex.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include #include #include diff --git a/dbms/src/Storages/DeltaMerge/RowKeyRange.h b/dbms/src/Storages/DeltaMerge/RowKeyRange.h index c82725100df..09ce340d9af 100644 --- a/dbms/src/Storages/DeltaMerge/RowKeyRange.h +++ b/dbms/src/Storages/DeltaMerge/RowKeyRange.h @@ -10,6 +10,7 @@ #include #include #include +#include namespace DB::DM { diff --git a/dbms/src/Storages/DeltaMerge/convertColumnTypeHelpers.cpp b/dbms/src/Storages/DeltaMerge/convertColumnTypeHelpers.cpp index b458fa79464..036794caf1c 100644 --- a/dbms/src/Storages/DeltaMerge/convertColumnTypeHelpers.cpp +++ b/dbms/src/Storages/DeltaMerge/convertColumnTypeHelpers.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -12,6 +13,11 @@ namespace DB { +namespace ErrorCodes +{ +extern const int BAD_ARGUMENTS; +} + namespace DM { diff --git a/tests/fullstack-test/expr/str_to_date.test b/tests/fullstack-test/expr/str_to_date.test index 7bded2f0490..f9baeb89c27 100644 --- a/tests/fullstack-test/expr/str_to_date.test +++ b/tests/fullstack-test/expr/str_to_date.test @@ -11,30 +11,33 @@ func> wait_table test t # Note that we need to put `str_to_date` in group by to make sure it is pushed down ## Test suite 1 - Allow zero day -#mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, ifnull(str_to_date(a, '%d/%m/%Y'),str_to_date('0000/00/00', '%d/%m/%Y')) as date, count(*) as cnt from test.t where suite = 1 group by date order by a -mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, ifnull(str_to_date(a, '%d/%m/%Y'),str_to_date('0000/00/00', '%d/%m/%Y')) as date, count(*) as cnt from test.t where suite = 1 group by date order by a +#mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, ifnull(str_to_date(a, '%d/%m/%Y'),str_to_date('00/00/0000', '%d/%m/%Y')) as date, count(*) as cnt from test.t where suite = 1 group by a,date order by a +mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, ifnull(str_to_date(a, '%d/%m/%Y'),str_to_date('00/00/0000', '%d/%m/%Y')) as date, count(*) as cnt from test.t where suite = 1 group by a,date order by a +------------+------------+-----+ | a | date | cnt | +------------+------------+-----+ | 0/0/2012 | 2012-00-00 | 1 | -| 00/00/0000 | 0000-00-00 | 2 | +| 00/00/0000 | 0000-00-00 | 1 | | 13/05/2019 | 2019-05-13 | 1 | +| abc | 0000-00-00 | 1 | +------------+------------+-----+ ## Test suite 1 - Disallow zero day -#mysql> set sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE'; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, ifnull(str_to_date(a, '%d/%m/%Y'),str_to_date('0000/00/00', '%d/%m/%Y')) as date, count(*) as cnt from test.t where suite = 1 group by date order by a -mysql> set sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE'; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, ifnull(str_to_date(a, '%d/%m/%Y'),str_to_date('0000/00/00', '%d/%m/%Y')) as date, count(*) as cnt from test.t where suite = 1 group by date order by a +# The sql_mode does not effect the result set +#mysql> set sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE'; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, ifnull(str_to_date(a, '%d/%m/%Y'),str_to_date('00/00/0000', '%d/%m/%Y')) as date, count(*) as cnt from test.t where suite = 1 group by a,date order by a +mysql> set sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE'; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, ifnull(str_to_date(a, '%d/%m/%Y'),str_to_date('00/00/0000', '%d/%m/%Y')) as date, count(*) as cnt from test.t where suite = 1 group by a,date order by a +------------+------------+-----+ | a | date | cnt | +------------+------------+-----+ | 0/0/2012 | NULL | 1 | -| 00/00/0000 | NULL | 2 | +| 00/00/0000 | NULL | 1 | | 13/05/2019 | 2019-05-13 | 1 | +| abc | NULL | 1 | +------------+------------+-----+ ## Test suite 2 - showing datetime with fractions -#mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, str_to_date(a, '%d/%b/%Y %H:%i:%S.%f') as date from test.t where suite = 2 group by date order by a -mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select /*+ agg_to_cop() */ a, str_to_date(a, '%d/%b/%Y %H:%i:%S.%f') as date from test.t where suite = 2 group by date order by a +#mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, str_to_date(a, '%d/%b/%Y %H:%i:%S.%f') as date from test.t where suite = 2 group by a,date order by a +mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, str_to_date(a, '%d/%b/%Y %H:%i:%S.%f') as date from test.t where suite = 2 group by a,date order by a +-----------------------------+----------------------------+ | a | date | +-----------------------------+----------------------------+ @@ -44,8 +47,8 @@ mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='t +-----------------------------+----------------------------+ ## Test suite 3 - showing datetime without fractions -#mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, str_to_date(a, ' %d/%b/%Y %H:%i:%S') as date from test.t where suite = 3 group by date order by a -mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, str_to_date(a, ' %d/%b/%Y %H:%i:%S') as date from test.t where suite = 3 group by date order by a +#mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, str_to_date(a, ' %d/%b/%Y %H:%i:%S') as date from test.t where suite = 3 group by a,date order by a +mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, str_to_date(a, ' %d/%b/%Y %H:%i:%S') as date from test.t where suite = 3 group by a,date order by a +-------------------------+---------------------+ | a | date | +-------------------------+---------------------+ @@ -54,8 +57,8 @@ mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='t +-------------------------+---------------------+ ## Test suite 4 - showing date -#mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, str_to_date(a, '%d/%b/%Y ') as date from test.t where suite = 4 group by date order by a -mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, str_to_date(a, '%d/%b/%Y ') as date from test.t where suite = 4 group by date order by a +#mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; explain select a, str_to_date(a, '%d/%b/%Y ') as date from test.t where suite = 4 group by a,date order by a +mysql> set sql_mode=''; set tidb_allow_mpp=1; set tidb_isolation_read_engines='tiflash'; select a, str_to_date(a, '%d/%b/%Y ') as date from test.t where suite = 4 group by a,date order by a +---------------+------------+ | a | date | +---------------+------------+