Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,11 @@ protected void updateLastColumn(
}
}
}.updateIntermediateColumn(newFields, 0);
if (drop.fieldNames().length == 1) {
String droppedField = drop.fieldNames()[0];
String prefix = FIELDS_PREFIX + "." + droppedField + ".";
newOptions.keySet().removeIf(k -> k.startsWith(prefix));
}
} else if (change instanceof UpdateColumnType) {
UpdateColumnType update = (UpdateColumnType) change;
assertNotUpdatingPartitionKeys(oldTableSchema, update.fieldNames(), "update");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,4 +939,41 @@ public void testRollbackSchemaNotExist() throws Exception {
new ChangelogManager(LocalFileIO.create(), path, null)))
.hasMessageContaining("Schema 999 does not exist");
}

@Test
public void testDropColumnCleansUpFieldOptions() throws Exception {
Map<String, String> tableOptions = new HashMap<>();
tableOptions.put("fields.extra_col.default-value", "1970-01-01 00:00:00");
tableOptions.put("key", "value");

List<DataField> fields =
Arrays.asList(
new DataField(0, "f0", new IntType()),
new DataField(1, "f1", new BigIntType()),
new DataField(2, "f2", new VarCharType()),
new DataField(3, "extra_col", DataTypes.TIMESTAMP(0)));
Schema schemaWithFieldOptions =
new Schema(
fields,
Collections.singletonList("f0"),
Arrays.asList("f0", "f1"),
tableOptions,
"");

SchemaManager mgr = new SchemaManager(LocalFileIO.create(), new Path(tempDir.toString()));
TableSchema created = mgr.createTable(schemaWithFieldOptions);

assertThat(created.options()).containsKey("fields.extra_col.default-value");

List<SchemaChange> changes =
Collections.singletonList(SchemaChange.dropColumn(new String[] {"extra_col"}));
assertThatCode(() -> mgr.commitChanges(changes)).doesNotThrowAnyException();

// Verify the column is removed and field-level options are cleaned up
TableSchema updated = mgr.latest().get();
assertThat(updated.fieldNames()).doesNotContain("extra_col");
assertThat(updated.options()).doesNotContainKey("fields.extra_col.default-value");
// Other options should remain
assertThat(updated.options()).containsKey("key");
}
}
Loading