Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 35 additions & 15 deletions dbms/src/Storages/tests/gtests_parse_push_down_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ class ParsePushDownExecutorTest : public ::testing::Test
// Maybe another test has already registed, ignore exception here.
}
}
void SetUp() override
{
ctx = DB::tests::TiFlashTestEnv::getContext();
ctx->getTimezoneInfo().resetByTimezoneName("Asia/Shanghai");
default_timezone_info = DB::tests::TiFlashTestEnv::getContext()->getTimezoneInfo();
}

protected:
LoggerPtr log = Logger::get();
ContextPtr ctx = DB::tests::TiFlashTestEnv::getContext();
TimezoneInfo default_timezone_info = DB::tests::TiFlashTestEnv::getContext()->getTimezoneInfo();
DM::PushDownExecutorPtr generatePushDownExecutor(
const String & table_info_json,
const String & query,
TimezoneInfo & timezone_info);
ContextPtr ctx;
TimezoneInfo default_timezone_info;
};

DM::PushDownExecutorPtr generatePushDownExecutor(
Expand Down Expand Up @@ -136,14 +138,6 @@ DM::PushDownExecutorPtr generatePushDownExecutor(
return push_down_executor;
}

DM::PushDownExecutorPtr ParsePushDownExecutorTest::generatePushDownExecutor(
const String & table_info_json,
const String & query,
TimezoneInfo & timezone_info)
{
return ::DB::tests::generatePushDownExecutor(*ctx, table_info_json, query, timezone_info);
}

// Test cases for col and literal
TEST_F(ParsePushDownExecutorTest, ColAndLiteral)
try
Expand All @@ -160,6 +154,7 @@ try
{
// Equal between col and literal
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 = 666",
default_timezone_info);
Expand All @@ -182,6 +177,7 @@ try
{
// Greater between col and literal
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 > 666",
default_timezone_info);
Expand All @@ -204,6 +200,7 @@ try
{
// GreaterEqual between col and literal
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 >= 667",
default_timezone_info);
Expand All @@ -226,6 +223,7 @@ try
{
// Less between col and literal
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 < 777",
default_timezone_info);
Expand All @@ -248,6 +246,7 @@ try
{
// LessEqual between col and literal
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 <= 776",
default_timezone_info);
Expand Down Expand Up @@ -284,6 +283,7 @@ try
{
// Equal between literal and col (take care of direction)
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where 667 = col_2",
default_timezone_info);
Expand All @@ -306,6 +306,7 @@ try
{
// NotEqual between literal and col (take care of direction)
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where 667 != col_2",
default_timezone_info);
Expand All @@ -328,6 +329,7 @@ try
{
// Greater between literal and col (take care of direction)
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where 667 < col_2",
default_timezone_info);
Expand All @@ -350,6 +352,7 @@ try
{
// GreaterEqual between literal and col (take care of direction)
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where 667 <= col_2",
default_timezone_info);
Expand All @@ -372,6 +375,7 @@ try
{
// Less between literal and col (take care of direction)
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where 777 > col_2",
default_timezone_info);
Expand All @@ -394,6 +398,7 @@ try
{
// LessEqual between literal and col (take care of direction)
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where 777 >= col_2",
default_timezone_info);
Expand Down Expand Up @@ -432,6 +437,7 @@ try
{
// Not
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select col_1, col_2 from default.t_111 where NOT col_2=666",
default_timezone_info);
Expand Down Expand Up @@ -459,6 +465,7 @@ try
{
// And
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_1 = 'test1' and col_2 = 666",
default_timezone_info);
Expand Down Expand Up @@ -486,6 +493,7 @@ try
{
// OR
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 = 789 or col_2 = 777",
default_timezone_info);
Expand Down Expand Up @@ -516,6 +524,7 @@ try
{
// And with "not supported"
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_1 = 'test1' and not col_2 = 666",
default_timezone_info);
Expand Down Expand Up @@ -543,6 +552,7 @@ try
{
// And with not
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 = 789 and not col_3 = 666",
default_timezone_info);
Expand Down Expand Up @@ -572,6 +582,7 @@ try
{
// And with or
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 = 789 and (col_3 = 666 or col_3 = 678)",
default_timezone_info);
Expand Down Expand Up @@ -603,6 +614,7 @@ try
{
// Or with "not supported"
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_1 = 'test1' or col_2 = 666",
default_timezone_info);
Expand Down Expand Up @@ -630,6 +642,7 @@ try
{
// Or with not
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_1 = 'test1' or not col_2 = 666",
default_timezone_info);
Expand Down Expand Up @@ -657,6 +670,7 @@ try
{
// And between col and literal (not supported since And only support when child is ColumnExpr)
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 and 1",
default_timezone_info);
Expand All @@ -682,6 +696,7 @@ try
{
// Or between col and literal (not supported since Or only support when child is ColumnExpr)
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
"select * from default.t_111 where col_2 or 1",
default_timezone_info);
Expand Down Expand Up @@ -733,14 +748,15 @@ try
// origin_time_stamp: 1802216106174185472

{
// Greater between TimeStamp col and Datetime literal, use Asia/Shanghai timezone
auto ctx = TiFlashTestEnv::getContext();
// Greater between TimeStamp col and Datetime literal, use Asia/Shanghai timezone
auto & timezone_info = ctx->getTimezoneInfo();
timezone_info.resetByTimezoneName("Asia/Shanghai");
convertTimeZone(origin_time_stamp, converted_time, *timezone_info.timezone, time_zone_utc);
// converted_time: 0

auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
String("select * from default.t_111 where col_timestamp > cast_string_datetime('") + datetime
+ String("')"),
Expand Down Expand Up @@ -790,6 +806,7 @@ try
// converted_time: 1802216518491045888

auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
String("select * from default.t_111 where col_timestamp > cast_string_datetime('") + datetime
+ String("')"),
Expand Down Expand Up @@ -846,6 +863,7 @@ try
// converted_time: 0

auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
String("select * from default.t_111 where col_timestamp > cast_string_datetime('") + datetime
+ String("')"),
Expand Down Expand Up @@ -896,6 +914,7 @@ try
{
// Greater between Datetime col and Datetime literal
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
String("select * from default.t_111 where col_datetime > cast_string_datetime('") + datetime + String("')"),
default_timezone_info);
Expand Down Expand Up @@ -944,6 +963,7 @@ try
{
// Greater between Date col and Datetime literal
auto filter = generatePushDownExecutor(
*ctx,
table_info_json,
String("select * from default.t_111 where col_date > cast_string_datetime('") + datetime + String("')"),
default_timezone_info);
Expand Down