nastra commented on code in PR #13537: URL: https://github.com/apache/iceberg/pull/13537#discussion_r2207148301
########## core/src/test/java/org/apache/iceberg/TestScansAndSchemaEvolution.java: ########## @@ -113,4 +116,80 @@ public void testPartitionSourceRename() throws IOException { assertThat(tasks).hasSize(1); } + + @TestTemplate + public void testAddColumnWithDefaultValueAndQuery() throws IOException { + assumeThat(V3_AND_ABOVE.contains(formatVersion)) + .withFailMessage( + "Only enable the test for versions above V3 since default values require V3+.") + .isTrue(); + File location = Files.createTempDirectory(temp, "junit").toFile(); + assertThat(location.delete()).isTrue(); // should be created by table create + + Table table = TestTables.create(location, "test", SCHEMA, SPEC, formatVersion); + + // Write initial data + DataFile fileOne = createDataFile("one"); + DataFile fileTwo = createDataFile("two"); + table.newAppend().appendFile(fileOne).appendFile(fileTwo).commit(); + + // Add a new column with an initial default value + String defaultValue = "default_category"; + table + .updateSchema() + .addColumn("category", Types.StringType.get(), "Product category", Literal.of(defaultValue)) + .commit(); + + // Verify the schema includes the new column with default value + Schema updatedSchema = table.schema(); + Types.NestedField categoryField = updatedSchema.findField("category"); + assertThat(categoryField).isNotNull(); + assertThat(categoryField.initialDefault()).isEqualTo(defaultValue); + assertThat(categoryField.writeDefault()).isEqualTo(defaultValue); + + // Verify scan planning works with the new column that has default value + List<FileScanTask> tasks = Lists.newArrayList(table.newScan().planFiles()); + assertThat(tasks).hasSize(2); Review Comment: can be simplified to `assertThat(table.newScan().planFiles()).hasSize(2)`. Same for other places -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org