anoopj commented on code in PR #13537: URL: https://github.com/apache/iceberg/pull/13537#discussion_r2208090103
########## core/src/test/java/org/apache/iceberg/TestScansAndSchemaEvolution.java: ########## @@ -113,4 +116,79 @@ public void testPartitionSourceRename() throws IOException { assertThat(tasks).hasSize(1); } + + @TestTemplate + public void testAddColumnWithDefaultValueAndQuery() throws IOException { + assumeThat(V3_AND_ABOVE).as("Default values require v3+").contains(formatVersion); + 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 + assertThat(table.newScan().planFiles()).hasSize(2); + + // Test that scan with projection includes the new column with default value + Schema projectionSchema = table.schema().select("id", "data", "category"); + List<FileScanTask> projectionTasks = + Lists.newArrayList(table.newScan().project(projectionSchema).planFiles()); + assertThat(projectionTasks).hasSize(2); Review Comment: @nastra done ########## core/src/test/java/org/apache/iceberg/TestScansAndSchemaEvolution.java: ########## @@ -113,4 +116,79 @@ public void testPartitionSourceRename() throws IOException { assertThat(tasks).hasSize(1); } + + @TestTemplate + public void testAddColumnWithDefaultValueAndQuery() throws IOException { + assumeThat(V3_AND_ABOVE).as("Default values require v3+").contains(formatVersion); + 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 + assertThat(table.newScan().planFiles()).hasSize(2); + + // Test that scan with projection includes the new column with default value + Schema projectionSchema = table.schema().select("id", "data", "category"); + List<FileScanTask> projectionTasks = + Lists.newArrayList(table.newScan().project(projectionSchema).planFiles()); + assertThat(projectionTasks).hasSize(2); + + // Verify that each task has the correct schema with the default column + for (FileScanTask task : projectionTasks) { Review Comment: Done -- 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