ebyhr commented on code in PR #14438:
URL: https://github.com/apache/iceberg/pull/14438#discussion_r2471901692


##########
core/src/test/java/org/apache/iceberg/TestScansAndSchemaEvolution.java:
##########
@@ -134,6 +134,45 @@ public void testPartitionSourceRename() throws IOException 
{
     assertThat(tasks).hasSize(1);
   }
 
+  @TestTemplate
+  public void testPartitionSourceAdd() throws IOException {
+    Table table = TestTables.create(temp, "test", SCHEMA, SPEC, formatVersion);
+
+    DataFile fileOne = createDataFile("one");
+    DataFile fileTwo = createDataFile("two");
+
+    table.newAppend().appendFile(fileOne).appendFile(fileTwo).commit();
+    long firstSnapshotId = table.currentSnapshot().snapshotId();
+
+    List<FileScanTask> tasks =
+        Lists.newArrayList(table.newScan().filter(Expressions.equal("part", 
"one")).planFiles());
+
+    assertThat(tasks).hasSize(1);
+
+    // add a new partition column
+    table.updateSchema().addColumn("hour", Types.IntegerType.get()).commit();
+    table.updateSpec().addField("hour").commit();
+
+    // plan the scan using the new column in a filter
+    tasks = 
Lists.newArrayList(table.newScan().filter(Expressions.isNull("hour")).planFiles());
+
+    assertThat(tasks).hasSize(2);
+
+    // create a new commit
+    table.newAppend().appendFile(createDataFile("three")).commit();
+
+    // plan the scan using the existing column in a filter
+    tasks =
+        Lists.newArrayList(
+            table
+                .newScan()
+                .useSnapshot(firstSnapshotId)
+                .filter(Expressions.equal("part", "one"))
+                .planFiles());

Review Comment:
   The `planFiles()` fails with the below exception without this PR's change: 
   ```sh
   Cannot find source column for partition field: 1001: hour: identity(4)
   org.apache.iceberg.exceptions.ValidationException: Cannot find source column 
for partition field: 1001: hour: identity(4)
        at 
org.apache.iceberg.exceptions.ValidationException.check(ValidationException.java:49)
        at 
org.apache.iceberg.PartitionSpec.checkCompatibility(PartitionSpec.java:656)
        at 
org.apache.iceberg.PartitionSpec$Builder.build(PartitionSpec.java:628)
        at 
org.apache.iceberg.PartitionSpec$Builder.build(PartitionSpec.java:623)
        at 
org.apache.iceberg.UnboundPartitionSpec.bind(UnboundPartitionSpec.java:46)
        at org.apache.iceberg.SnapshotScan.specs(SnapshotScan.java:98)
        at org.apache.iceberg.DataTableScan.doPlanFiles(DataTableScan.java:77)
        at org.apache.iceberg.SnapshotScan.planFiles(SnapshotScan.java:161)
   ```



-- 
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