-
Notifications
You must be signed in to change notification settings - Fork 409
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support last_day and dayofmonth pushdown to tiflash (#4183)
close #4149
- Loading branch information
1 parent
2b14421
commit c7d69d4
Showing
10 changed files
with
433 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include <Columns/ColumnConst.h> | ||
#include <Common/Exception.h> | ||
#include <Functions/FunctionFactory.h> | ||
#include <Functions/FunctionsDateTime.h> | ||
#include <Interpreters/Context.h> | ||
#include <TestUtils/FunctionTestUtils.h> | ||
#include <TestUtils/TiFlashTestBasic.h> | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
namespace DB | ||
{ | ||
namespace tests | ||
{ | ||
class TestLastDay : public DB::tests::FunctionTest | ||
{ | ||
}; | ||
|
||
TEST_F(TestLastDay, BasicTest) | ||
try | ||
{ | ||
const String func_name = TiDBLastDayTransformerImpl<DataTypeMyDate::FieldType>::name; | ||
|
||
// Ignore invalid month error | ||
DAGContext * dag_context = context.getDAGContext(); | ||
UInt64 ori_flags = dag_context->getFlags(); | ||
dag_context->addFlag(TiDBSQLFlags::TRUNCATE_AS_WARNING); | ||
dag_context->clearWarnings(); | ||
|
||
// nullable column test | ||
ASSERT_COLUMN_EQ( | ||
createColumn<Nullable<MyDate>>({MyDate{2001, 2, 28}.toPackedUInt(), | ||
MyDate{2000, 2, 29}.toPackedUInt(), | ||
MyDate{2000, 6, 30}.toPackedUInt(), | ||
MyDate{2000, 5, 31}.toPackedUInt(), | ||
{}}), | ||
executeFunction(func_name, | ||
{createColumn<MyDate>({MyDate{2001, 2, 10}.toPackedUInt(), | ||
MyDate{2000, 2, 10}.toPackedUInt(), | ||
MyDate{2000, 6, 10}.toPackedUInt(), | ||
MyDate{2000, 5, 10}.toPackedUInt(), | ||
MyDate{2000, 0, 10}.toPackedUInt()})})); | ||
|
||
ASSERT_COLUMN_EQ( | ||
createColumn<Nullable<MyDate>>({MyDate{2001, 2, 28}.toPackedUInt(), | ||
MyDate{2000, 2, 29}.toPackedUInt(), | ||
MyDate{2000, 6, 30}.toPackedUInt(), | ||
MyDate{2000, 5, 31}.toPackedUInt(), | ||
{}}), | ||
executeFunction(func_name, | ||
{createColumn<MyDateTime>({MyDateTime{2001, 2, 10, 10, 10, 10, 0}.toPackedUInt(), | ||
MyDateTime{2000, 2, 10, 10, 10, 10, 0}.toPackedUInt(), | ||
MyDateTime{2000, 6, 10, 10, 10, 10, 0}.toPackedUInt(), | ||
MyDateTime{2000, 5, 10, 10, 10, 10, 0}.toPackedUInt(), | ||
MyDateTime{2000, 0, 10, 10, 10, 10, 0}.toPackedUInt()})})); | ||
|
||
// const test | ||
UInt64 input[] = { | ||
MyDateTime{2001, 2, 10, 10, 10, 10, 0}.toPackedUInt(), | ||
MyDateTime{2000, 2, 10, 10, 10, 10, 0}.toPackedUInt(), | ||
MyDateTime{2000, 6, 10, 10, 10, 10, 0}.toPackedUInt(), | ||
MyDateTime{2000, 5, 10, 10, 10, 10, 0}.toPackedUInt(), | ||
}; | ||
|
||
UInt64 output[] = { | ||
MyDate{2001, 2, 28}.toPackedUInt(), | ||
MyDate{2000, 2, 29}.toPackedUInt(), | ||
MyDate{2000, 6, 30}.toPackedUInt(), | ||
MyDate{2000, 5, 31}.toPackedUInt(), | ||
}; | ||
|
||
for (size_t i = 0; i < sizeof(input) / sizeof(UInt64); ++i) | ||
{ | ||
ASSERT_COLUMN_EQ( | ||
createConstColumn<Nullable<MyDate>>(3, output[i]), | ||
executeFunction(func_name, | ||
{createConstColumn<MyDate>(3, input[i])})); | ||
|
||
ASSERT_COLUMN_EQ( | ||
createConstColumn<Nullable<MyDate>>(3, output[i]), | ||
executeFunction(func_name, | ||
{createConstColumn<Nullable<MyDate>>(3, input[i])})); | ||
} | ||
|
||
// const nullable test | ||
ASSERT_COLUMN_EQ( | ||
createConstColumn<Nullable<MyDate>>(3, {}), | ||
executeFunction(func_name, | ||
{createConstColumn<Nullable<MyDate>>(3, {})})); | ||
|
||
// special const test, month is zero. | ||
ASSERT_COLUMN_EQ( | ||
createConstColumn<Nullable<MyDate>>(3, {}), | ||
executeFunction(func_name, | ||
{createConstColumn<MyDate>(3, MyDateTime{2000, 0, 10, 10, 10, 10, 0}.toPackedUInt())})); | ||
|
||
dag_context->setFlags(ori_flags); | ||
} | ||
CATCH | ||
|
||
} // namespace tests | ||
} // namespace DB |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
mysql> drop table if exists test.t1; | ||
mysql> create table test.t1 (c_str varchar(100), c_datetime datetime(4), c_date date); | ||
mysql> insert into test.t1 values('', '1999-10-10 10:10:10.123', '1999-01-10'), ('200', '1999-02-10 10:10:10.123', '1999-11-10'), ('1999-30-10', '1999-10-10 10:10:10.123', '1999-01-10'), ('1999-01-10', '1999-10-10 10:10:10.123', '1999-01-10'); | ||
mysql> alter table test.t1 set tiflash replica 1; | ||
func> wait_table test t1 | ||
|
||
mysql> set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp = 1; select dayofmonth(); | ||
ERROR 1582 (42000) at line 1: Incorrect parameter count in the call to native function 'dayofmonth' | ||
|
||
# invalid input | ||
mysql> set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp = 1; select dayofmonth(''), dayofmonth('1'), dayofmonth('1999-30-01'), dayofmonth(null); | ||
+----------------+-----------------+--------------------------+------------------+ | ||
| dayofmonth('') | dayofmonth('1') | dayofmonth('1999-30-01') | dayofmonth(null) | | ||
+----------------+-----------------+--------------------------+------------------+ | ||
| NULL | NULL | NULL | NULL | | ||
+----------------+-----------------+--------------------------+------------------+ | ||
|
||
# got bug: https://github.com/pingcap/tics/issues/4186 | ||
# mysql> set @@tidb_isolation_read_engines='tiflash'; set @@tidb_enforce_mpp = 1; select dayofmonth(c_str), dayofmonth(c_datetime), dayofmonth(c_date) from test.t1 order by 1, 2, 3; | ||
# +-------------------+------------------------+--------------------+ | ||
# | dayofmonth(c_str) | dayofmonth(c_datetime) | dayofmonth(c_date) | | ||
# +-------------------+------------------------+--------------------+ | ||
# | NULL | 10 | 10 | | ||
# | NULL | 10 | 10 | | ||
# | NULL | 10 | 10 | | ||
# | 10 | 10 | 10 | | ||
# +-------------------+------------------------+--------------------+ |
Oops, something went wrong.