shivadarshan-devadiga commented on code in PR #18995:
URL: https://github.com/apache/iceberg/pull/18995#discussion_r4726840117


##########
spark/v4.0/spark/src/test/java/org/apache/iceberg/spark/sql/TestStoragePartitionedJoins.java:
##########
@@ -131,6 +137,232 @@ public static void setupSparkConf() {
   public void removeTables() {
     sql("DROP TABLE IF EXISTS %s", tableName);
     sql("DROP TABLE IF EXISTS %s", tableName(OTHER_TABLE_NAME));
+    sql("DROP TABLE IF EXISTS %s", tableName(UNPARTITIONED_TABLE_NAME));
+  }
+
+  @TestTemplate
+  void runtimeFilteringWithTrailingPartitionKey() {
+    sql(
+        "CREATE TABLE %s (store_id INT, dept_id INT, data STRING) USING 
iceberg "
+            + "PARTITIONED BY (store_id, dept_id) TBLPROPERTIES (%s)",
+        tableName, tablePropsAsString(TABLE_PROPERTIES));
+    configurePlanningMode(tableName, planningMode);
+    sql(
+        "INSERT INTO %s VALUES (100, 1, 'aa'), (100, 2, 'ab'), (200, 1, 'ac'), 
(200, 3, 'ad')",
+        tableName);
+    sql(
+        "CREATE TABLE %s (dept_id INT, data STRING) USING iceberg "
+            + "PARTITIONED BY (dept_id) TBLPROPERTIES (%s)",
+        tableName(OTHER_TABLE_NAME), tablePropsAsString(TABLE_PROPERTIES));
+    configurePlanningMode(tableName(OTHER_TABLE_NAME), planningMode);
+    sql("INSERT INTO %s VALUES (1, 'x'), (2, 'y'), (3, 'x')", 
tableName(OTHER_TABLE_NAME));
+
+    String query =
+        String.format(
+            "SELECT /*+ MERGE(t1, t2) */ t1.store_id, t1.dept_id, t1.data, 
t2.data "
+                + "FROM %s t1 JOIN %s t2 ON t1.dept_id = t2.dept_id "
+                + "WHERE t2.data = 'x' ORDER BY t1.store_id, t1.dept_id, 
t1.data",
+            tableName, tableName(OTHER_TABLE_NAME));
+
+    withSQLConf(
+        ImmutableMap.of(
+            SQLConf.DYNAMIC_PARTITION_PRUNING_ENABLED().key(), "true",
+            SQLConf.DYNAMIC_PARTITION_PRUNING_REUSE_BROADCAST_ONLY().key(), 
"false",
+            SQLConf.DYNAMIC_PARTITION_PRUNING_FALLBACK_FILTER_RATIO().key(), 
"10"),
+        () -> {
+          withSQLConf(
+              ENABLED_SPJ_SQL_CONF,
+              () -> {
+                Dataset<Row> df = spark.sql(query);
+                SparkPlan plan = df.queryExecution().executedPlan();
+                assertThat(CollectionConverters.asJava(plan.collectLeaves()))
+                    .anySatisfy(
+                        leaf -> {
+                          assertThat(leaf).isInstanceOf(BatchScanExec.class);
+                          BatchScanExec scan = (BatchScanExec) leaf;
+                          
assertThat(scan.runtimeFilters().isEmpty()).isFalse();

Review Comment:
   Thanks, good point. Done in 
[e4a5249](https://github.com/apache/iceberg/pull/18995/changes/e4a5249285748fa5ba08a59931af0d118f4ead41);
  for 4.0, 4.1 and 4.2: the test now adapts `deleteNotMatchingFiles` from 
`TestRuntimeFiltering` and deletes the `dept_id = 2` file of the partitioned 
table from disk, keeping it in the metadata, right after the inserts 
(`deleteNotMatchingFiles(Expressions.in("dept_id", 1, 3), 1)`). The query, with 
and without SPJ, now only succeeds if the runtime filter skips that file: 
deleting the `dept_id = 3` file instead, which the filter keeps, makes it fail 
with `NotFoundException: Failed to open input stream for file`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to