Skip to content

Commit 1d01837

Browse files
authored
Fix TimestampColumn fail in ASan/TSan (#10142)
ref #6233 Signed-off-by: xufei <[email protected]>
1 parent f000ce3 commit 1d01837

File tree

1 file changed

+35
-15
lines changed

1 file changed

+35
-15
lines changed

dbms/src/Storages/tests/gtests_parse_push_down_filter.cpp

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,17 @@ class ParsePushDownExecutorTest : public ::testing::Test
5050
// Maybe another test has already registed, ignore exception here.
5151
}
5252
}
53+
void SetUp() override
54+
{
55+
ctx = DB::tests::TiFlashTestEnv::getContext();
56+
ctx->getTimezoneInfo().resetByTimezoneName("Asia/Shanghai");
57+
default_timezone_info = DB::tests::TiFlashTestEnv::getContext()->getTimezoneInfo();
58+
}
5359

5460
protected:
5561
LoggerPtr log = Logger::get();
56-
ContextPtr ctx = DB::tests::TiFlashTestEnv::getContext();
57-
TimezoneInfo default_timezone_info = DB::tests::TiFlashTestEnv::getContext()->getTimezoneInfo();
58-
DM::PushDownExecutorPtr generatePushDownExecutor(
59-
const String & table_info_json,
60-
const String & query,
61-
TimezoneInfo & timezone_info);
62+
ContextPtr ctx;
63+
TimezoneInfo default_timezone_info;
6264
};
6365

6466
DM::PushDownExecutorPtr generatePushDownExecutor(
@@ -136,14 +138,6 @@ DM::PushDownExecutorPtr generatePushDownExecutor(
136138
return push_down_executor;
137139
}
138140

139-
DM::PushDownExecutorPtr ParsePushDownExecutorTest::generatePushDownExecutor(
140-
const String & table_info_json,
141-
const String & query,
142-
TimezoneInfo & timezone_info)
143-
{
144-
return ::DB::tests::generatePushDownExecutor(*ctx, table_info_json, query, timezone_info);
145-
}
146-
147141
// Test cases for col and literal
148142
TEST_F(ParsePushDownExecutorTest, ColAndLiteral)
149143
try
@@ -160,6 +154,7 @@ try
160154
{
161155
// Equal between col and literal
162156
auto filter = generatePushDownExecutor(
157+
*ctx,
163158
table_info_json,
164159
"select * from default.t_111 where col_2 = 666",
165160
default_timezone_info);
@@ -182,6 +177,7 @@ try
182177
{
183178
// Greater between col and literal
184179
auto filter = generatePushDownExecutor(
180+
*ctx,
185181
table_info_json,
186182
"select * from default.t_111 where col_2 > 666",
187183
default_timezone_info);
@@ -204,6 +200,7 @@ try
204200
{
205201
// GreaterEqual between col and literal
206202
auto filter = generatePushDownExecutor(
203+
*ctx,
207204
table_info_json,
208205
"select * from default.t_111 where col_2 >= 667",
209206
default_timezone_info);
@@ -226,6 +223,7 @@ try
226223
{
227224
// Less between col and literal
228225
auto filter = generatePushDownExecutor(
226+
*ctx,
229227
table_info_json,
230228
"select * from default.t_111 where col_2 < 777",
231229
default_timezone_info);
@@ -248,6 +246,7 @@ try
248246
{
249247
// LessEqual between col and literal
250248
auto filter = generatePushDownExecutor(
249+
*ctx,
251250
table_info_json,
252251
"select * from default.t_111 where col_2 <= 776",
253252
default_timezone_info);
@@ -284,6 +283,7 @@ try
284283
{
285284
// Equal between literal and col (take care of direction)
286285
auto filter = generatePushDownExecutor(
286+
*ctx,
287287
table_info_json,
288288
"select * from default.t_111 where 667 = col_2",
289289
default_timezone_info);
@@ -306,6 +306,7 @@ try
306306
{
307307
// NotEqual between literal and col (take care of direction)
308308
auto filter = generatePushDownExecutor(
309+
*ctx,
309310
table_info_json,
310311
"select * from default.t_111 where 667 != col_2",
311312
default_timezone_info);
@@ -328,6 +329,7 @@ try
328329
{
329330
// Greater between literal and col (take care of direction)
330331
auto filter = generatePushDownExecutor(
332+
*ctx,
331333
table_info_json,
332334
"select * from default.t_111 where 667 < col_2",
333335
default_timezone_info);
@@ -350,6 +352,7 @@ try
350352
{
351353
// GreaterEqual between literal and col (take care of direction)
352354
auto filter = generatePushDownExecutor(
355+
*ctx,
353356
table_info_json,
354357
"select * from default.t_111 where 667 <= col_2",
355358
default_timezone_info);
@@ -372,6 +375,7 @@ try
372375
{
373376
// Less between literal and col (take care of direction)
374377
auto filter = generatePushDownExecutor(
378+
*ctx,
375379
table_info_json,
376380
"select * from default.t_111 where 777 > col_2",
377381
default_timezone_info);
@@ -394,6 +398,7 @@ try
394398
{
395399
// LessEqual between literal and col (take care of direction)
396400
auto filter = generatePushDownExecutor(
401+
*ctx,
397402
table_info_json,
398403
"select * from default.t_111 where 777 >= col_2",
399404
default_timezone_info);
@@ -432,6 +437,7 @@ try
432437
{
433438
// Not
434439
auto filter = generatePushDownExecutor(
440+
*ctx,
435441
table_info_json,
436442
"select col_1, col_2 from default.t_111 where NOT col_2=666",
437443
default_timezone_info);
@@ -459,6 +465,7 @@ try
459465
{
460466
// And
461467
auto filter = generatePushDownExecutor(
468+
*ctx,
462469
table_info_json,
463470
"select * from default.t_111 where col_1 = 'test1' and col_2 = 666",
464471
default_timezone_info);
@@ -486,6 +493,7 @@ try
486493
{
487494
// OR
488495
auto filter = generatePushDownExecutor(
496+
*ctx,
489497
table_info_json,
490498
"select * from default.t_111 where col_2 = 789 or col_2 = 777",
491499
default_timezone_info);
@@ -516,6 +524,7 @@ try
516524
{
517525
// And with "not supported"
518526
auto filter = generatePushDownExecutor(
527+
*ctx,
519528
table_info_json,
520529
"select * from default.t_111 where col_1 = 'test1' and not col_2 = 666",
521530
default_timezone_info);
@@ -543,6 +552,7 @@ try
543552
{
544553
// And with not
545554
auto filter = generatePushDownExecutor(
555+
*ctx,
546556
table_info_json,
547557
"select * from default.t_111 where col_2 = 789 and not col_3 = 666",
548558
default_timezone_info);
@@ -572,6 +582,7 @@ try
572582
{
573583
// And with or
574584
auto filter = generatePushDownExecutor(
585+
*ctx,
575586
table_info_json,
576587
"select * from default.t_111 where col_2 = 789 and (col_3 = 666 or col_3 = 678)",
577588
default_timezone_info);
@@ -603,6 +614,7 @@ try
603614
{
604615
// Or with "not supported"
605616
auto filter = generatePushDownExecutor(
617+
*ctx,
606618
table_info_json,
607619
"select * from default.t_111 where col_1 = 'test1' or col_2 = 666",
608620
default_timezone_info);
@@ -630,6 +642,7 @@ try
630642
{
631643
// Or with not
632644
auto filter = generatePushDownExecutor(
645+
*ctx,
633646
table_info_json,
634647
"select * from default.t_111 where col_1 = 'test1' or not col_2 = 666",
635648
default_timezone_info);
@@ -657,6 +670,7 @@ try
657670
{
658671
// And between col and literal (not supported since And only support when child is ColumnExpr)
659672
auto filter = generatePushDownExecutor(
673+
*ctx,
660674
table_info_json,
661675
"select * from default.t_111 where col_2 and 1",
662676
default_timezone_info);
@@ -682,6 +696,7 @@ try
682696
{
683697
// Or between col and literal (not supported since Or only support when child is ColumnExpr)
684698
auto filter = generatePushDownExecutor(
699+
*ctx,
685700
table_info_json,
686701
"select * from default.t_111 where col_2 or 1",
687702
default_timezone_info);
@@ -733,14 +748,15 @@ try
733748
// origin_time_stamp: 1802216106174185472
734749

735750
{
736-
// Greater between TimeStamp col and Datetime literal, use Asia/Shanghai timezone
737751
auto ctx = TiFlashTestEnv::getContext();
752+
// Greater between TimeStamp col and Datetime literal, use Asia/Shanghai timezone
738753
auto & timezone_info = ctx->getTimezoneInfo();
739754
timezone_info.resetByTimezoneName("Asia/Shanghai");
740755
convertTimeZone(origin_time_stamp, converted_time, *timezone_info.timezone, time_zone_utc);
741756
// converted_time: 0
742757

743758
auto filter = generatePushDownExecutor(
759+
*ctx,
744760
table_info_json,
745761
String("select * from default.t_111 where col_timestamp > cast_string_datetime('") + datetime
746762
+ String("')"),
@@ -790,6 +806,7 @@ try
790806
// converted_time: 1802216518491045888
791807

792808
auto filter = generatePushDownExecutor(
809+
*ctx,
793810
table_info_json,
794811
String("select * from default.t_111 where col_timestamp > cast_string_datetime('") + datetime
795812
+ String("')"),
@@ -846,6 +863,7 @@ try
846863
// converted_time: 0
847864

848865
auto filter = generatePushDownExecutor(
866+
*ctx,
849867
table_info_json,
850868
String("select * from default.t_111 where col_timestamp > cast_string_datetime('") + datetime
851869
+ String("')"),
@@ -896,6 +914,7 @@ try
896914
{
897915
// Greater between Datetime col and Datetime literal
898916
auto filter = generatePushDownExecutor(
917+
*ctx,
899918
table_info_json,
900919
String("select * from default.t_111 where col_datetime > cast_string_datetime('") + datetime + String("')"),
901920
default_timezone_info);
@@ -944,6 +963,7 @@ try
944963
{
945964
// Greater between Date col and Datetime literal
946965
auto filter = generatePushDownExecutor(
966+
*ctx,
947967
table_info_json,
948968
String("select * from default.t_111 where col_date > cast_string_datetime('") + datetime + String("')"),
949969
default_timezone_info);

0 commit comments

Comments
 (0)