@@ -744,6 +744,41 @@ void testLookup1PkTableWith2Conditions(Caching caching, boolean async) throws Ex
744744 assertResultsIgnoreOrder (collected2 , expected2 , true );
745745 }
746746
747+ /**
748+ * lookup table with one pk, two join condition and one of the join condition is constant value.
749+ */
750+ @ Test
751+ void testLookupWithFilterPushDown () throws Exception {
752+ String dim =
753+ prepareDimTableAndSourceTable (
754+ Caching .DISABLE_CACHE , false , new String [] {"id" }, null , "p_date" );
755+
756+ Map <Long , String > partitionNameById =
757+ waitUntilPartitions (
758+ FLUSS_CLUSTER_EXTENSION .getZooKeeperClient (),
759+ TablePath .of (DEFAULT_DB , dim ));
760+
761+ // pick the first partition to do filter
762+ String filteredPartition = partitionNameById .values ().stream ().sorted ().iterator ().next ();
763+
764+ String dimJoinQuery =
765+ String .format (
766+ "SELECT a, h.id, h.name, h.address FROM src "
767+ + " LEFT JOIN %s FOR SYSTEM_TIME AS OF src.proc as h "
768+ + " ON src.a = h.id and src.p_date = h.p_date and h.p_date <> '%s'" ,
769+ dim , filteredPartition );
770+
771+ CloseableIterator <Row > collected = tEnv .executeSql (dimJoinQuery ).collect ();
772+ List <String > expected =
773+ Arrays .asList (
774+ "+I[1, null, null, null]" ,
775+ "+I[2, null, null, null]" ,
776+ "+I[3, null, null, null]" ,
777+ "+I[10, null, null, null]" ,
778+ "+I[1, null, null, null]" );
779+ assertResultsIgnoreOrder (collected , expected , true );
780+ }
781+
747782 /**
748783 * lookup table with one pk, 3 join condition on dim fields, 1st for variable non-pk, 2nd for
749784 * pk, 3rd for constant value.
@@ -959,8 +994,8 @@ void testStreamingReadSinglePartitionPushDown() throws Exception {
959994 assertThat (plan )
960995 .contains (
961996 "TableSourceScan(table=[[testcatalog, defaultdb, partitioned_table, "
962- + "filter=[=(c, _UTF-16LE'2025':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" )], "
963- + "project =[a, b]]], fields=[a, b ])" );
997+ + "filter=[=(c, _UTF-16LE'2025':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" )]]] , "
998+ + "fields =[a, b, c ])" );
964999
9651000 org .apache .flink .util .CloseableIterator <Row > rowIter =
9661001 tEnv .executeSql ("select * from partitioned_table where c ='2025'" ).collect ();
@@ -1013,10 +1048,11 @@ void testStreamingReadAllPartitionTypePushDown() throws Exception {
10131048 + "=(p_string, _UTF-16LE'hello':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" )), "
10141049 + "=(p_float, 1.25E1:FLOAT)), =(p_double, 7.88E0:DOUBLE)), =(p_date, 2025-10-12)), "
10151050 + "=(p_time, 12:55:00)), =(p_ts_ntz, 2025-10-12 12:55:00.001:TIMESTAMP(6))), "
1016- + "=(p_ts_ltz, 1970-01-01 00:00:04.001:TIMESTAMP_WITH_LOCAL_TIME_ZONE(6))), NOT(p_bool))], "
1017- + "project=[id, p_bool, p_int]]], fields=[id, p_bool, p_int])" )
1018- // all filter conditions should be pushed down
1019- .doesNotContain ("where=" );
1051+ + "=(p_ts_ltz, 1970-01-01 00:00:04.001:TIMESTAMP_WITH_LOCAL_TIME_ZONE(6))), NOT(p_bool))]]], "
1052+ + "fields=[id, p_bool, p_int, p_bigint, p_bytes, p_string, p_float, p_double, p_date, p_time, p_ts_ntz, p_ts_ltz])" )
1053+ // although all filter conditions are pushed down into source, they are still
1054+ // retained in the plan
1055+ .contains ("where=" );
10201056
10211057 List <String > expectedRowValues =
10221058 Collections .singletonList (
@@ -1050,8 +1086,8 @@ void testStreamingReadMultiPartitionPushDown() throws Exception {
10501086 assertThat (plan )
10511087 .contains (
10521088 "TableSourceScan(table=[[testcatalog, defaultdb, multi_partitioned_table, "
1053- + "filter=[=(c, _UTF-16LE'2025':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" )], "
1054- + "project =[a, b, d]]], fields=[a, b , d])" );
1089+ + "filter=[=(c, _UTF-16LE'2025':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" )]]] , "
1090+ + "fields =[a, b, c , d])" );
10551091
10561092 // test partition key prefix match
10571093 // This test requires dynamically discovering newly created partitions, so
@@ -1080,8 +1116,8 @@ void testStreamingReadMultiPartitionPushDown() throws Exception {
10801116 .contains (
10811117 "TableSourceScan(table=[[testcatalog, defaultdb, multi_partitioned_table, "
10821118 + "filter=[and(=(c, _UTF-16LE'2025':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" ), "
1083- + "=(d, _UTF-16LE'3':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" ))], "
1084- + "project =[a, b]]], fields=[a, b ])" );
1119+ + "=(d, _UTF-16LE'3':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" ))]]] , "
1120+ + "fields =[a, b, c, d ])" );
10851121
10861122 // test all partition key match
10871123 rowIter =
@@ -1128,7 +1164,7 @@ void testStreamingReadWithCombinedFilters1() throws Exception {
11281164 .contains (
11291165 "TableSourceScan(table=[[testcatalog, defaultdb, combined_filters_table, "
11301166 + "filter=[=(c, _UTF-16LE'2025':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" )], "
1131- + "project=[a, d]]], fields=[a, d])" );
1167+ + "project=[a, c, d]]], fields=[a, c , d])" );
11321168
11331169 // test column filter、partition filter and flink runtime filter
11341170 org .apache .flink .util .CloseableIterator <Row > rowIter =
@@ -1145,7 +1181,7 @@ void testStreamingReadWithCombinedFilters1() throws Exception {
11451181 .contains (
11461182 "TableSourceScan(table=[[testcatalog, defaultdb, combined_filters_table, "
11471183 + "filter=[=(c, _UTF-16LE'2025':VARCHAR(2147483647) CHARACTER SET \" UTF-16LE\" )], "
1148- + "project=[a, d]]], fields=[a, d])" );
1184+ + "project=[a, c, d]]], fields=[a, c , d])" );
11491185
11501186 // test column filter、partition filter and flink runtime filter
11511187 rowIter =
@@ -1366,7 +1402,7 @@ void testStreamingReadPartitionComplexPushDown() throws Exception {
13661402 String plan = tEnv .explainSql (query );
13671403 assertThat (plan )
13681404 .contains (
1369- "Calc(select=[3 AS a, b, c, d], where=[((a = 3) AND LIKE(b, '%v3%'))])\n "
1405+ "Calc(select=[3 AS a, b, c, d], where=[((a = 3) AND ((c = '2026') OR LIKE(d, '%1%')) AND LIKE(b, '%v3%'))])\n "
13701406 + "+- TableSourceScan(table=[[testcatalog, defaultdb, partitioned_table_complex, filter=[OR(=(c, _UTF-16LE'2026'), LIKE(d, _UTF-16LE'%1%'))]]], fields=[a, b, c, d])" );
13711407
13721408 org .apache .flink .util .CloseableIterator <Row > rowIter = tEnv .executeSql (query ).collect ();
0 commit comments