@@ -72,6 +72,34 @@ class ParquetTableScanTest : public HiveConnectorTestBase {
7272 assertQuery (plan, splits_, sql);
7373 }
7474
75+ void assertSelectWithFilter (
76+ std::vector<std::string>&& outputColumnNames,
77+ const std::vector<std::string>& subfieldFilters,
78+ const std::string& remainingFilter,
79+ const std::string& sql,
80+ bool isFilterPushdownEnabled) {
81+ auto rowType = getRowType (std::move (outputColumnNames));
82+ parse::ParseOptions options;
83+ options.parseDecimalAsDouble = false ;
84+
85+ auto plan = PlanBuilder (pool_.get ())
86+ .setParseOptions (options)
87+ // Function extractFiltersFromRemainingFilter will extract
88+ // filters to subfield filters, but for some types, filter
89+ // pushdown is not supported.
90+ .tableScan (
91+ " hive_table" ,
92+ rowType,
93+ {},
94+ subfieldFilters,
95+ remainingFilter,
96+ nullptr ,
97+ isFilterPushdownEnabled)
98+ .planNode ();
99+
100+ assertQuery (plan, splits_, sql);
101+ }
102+
75103 void assertSelectWithAgg (
76104 std::vector<std::string>&& outputColumnNames,
77105 const std::vector<std::string>& aggregates,
@@ -518,6 +546,83 @@ TEST_F(ParquetTableScanTest, structSelection) {
518546 assertSelectWithFilter ({" name" }, {}, " " , " SELECT t from tmp" );
519547}
520548
549+ TEST_F (ParquetTableScanTest, timestampFilter) {
550+ // Timestamp-int96.parquet holds one column (t: TIMESTAMP) and
551+ // 10 rows in one row group. Data is in SNAPPY compressed format.
552+ // The values are:
553+ // |t |
554+ // +-------------------+
555+ // |2015-06-01 19:34:56|
556+ // |2015-06-02 19:34:56|
557+ // |2001-02-03 03:34:06|
558+ // |1998-03-01 08:01:06|
559+ // |2022-12-23 03:56:01|
560+ // |1980-01-24 00:23:07|
561+ // |1999-12-08 13:39:26|
562+ // |2023-04-21 09:09:34|
563+ // |2000-09-12 22:36:29|
564+ // |2007-12-12 04:27:56|
565+ // +-------------------+
566+ auto vector = makeFlatVector<Timestamp>(
567+ {Timestamp (1433116800 , 70496000000000 ),
568+ Timestamp (1433203200 , 70496000000000 ),
569+ Timestamp (981158400 , 12846000000000 ),
570+ Timestamp (888710400 , 28866000000000 ),
571+ Timestamp (1671753600 , 14161000000000 ),
572+ Timestamp (317520000 , 1387000000000 ),
573+ Timestamp (944611200 , 49166000000000 ),
574+ Timestamp (1682035200 , 32974000000000 ),
575+ Timestamp (968716800 , 81389000000000 ),
576+ Timestamp (1197417600 , 16076000000000 )});
577+
578+ loadData (
579+ getExampleFilePath (" timestamp_int96.parquet" ),
580+ ROW ({" t" }, {TIMESTAMP ()}),
581+ makeRowVector (
582+ {" t" },
583+ {
584+ vector,
585+ }));
586+ assertSelectWithFilter ({" t" }, {}, " " , " SELECT t from tmp" , false );
587+ assertSelectWithFilter (
588+ {" t" },
589+ {},
590+ " t < TIMESTAMP '2000-09-12 22:36:29'" ,
591+ " SELECT t from tmp where t < TIMESTAMP '2000-09-12 22:36:29'" ,
592+ false );
593+ assertSelectWithFilter (
594+ {" t" },
595+ {},
596+ " t <= TIMESTAMP '2000-09-12 22:36:29'" ,
597+ " SELECT t from tmp where t <= TIMESTAMP '2000-09-12 22:36:29'" ,
598+ false );
599+ assertSelectWithFilter (
600+ {" t" },
601+ {},
602+ " t > TIMESTAMP '1980-01-24 00:23:07'" ,
603+ " SELECT t from tmp where t > TIMESTAMP '1980-01-24 00:23:07'" ,
604+ false );
605+ assertSelectWithFilter (
606+ {" t" },
607+ {},
608+ " t >= TIMESTAMP '1980-01-24 00:23:07'" ,
609+ " SELECT t from tmp where t >= TIMESTAMP '1980-01-24 00:23:07'" ,
610+ false );
611+ assertSelectWithFilter (
612+ {" t" },
613+ {},
614+ " t == TIMESTAMP '2022-12-23 03:56:01'" ,
615+ " SELECT t from tmp where t == TIMESTAMP '2022-12-23 03:56:01'" ,
616+ false );
617+ VELOX_ASSERT_THROW (
618+ assertSelectWithFilter (
619+ {" t" },
620+ {" t < TIMESTAMP '2000-09-12 22:36:29'" },
621+ " " ,
622+ " SELECT t from tmp where t < TIMESTAMP '2000-09-12 22:36:29'" ),
623+ " testInt128() is not supported" );
624+ }
625+
521626int main (int argc, char ** argv) {
522627 testing::InitGoogleTest (&argc, argv);
523628 folly::init (&argc, &argv, false );
0 commit comments