diff --git a/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java b/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java index df4224915927..23214ff05fea 100644 --- a/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java +++ b/paimon-core/src/main/java/org/apache/paimon/table/AbstractFileStoreTable.java @@ -383,9 +383,10 @@ protected FileStoreTable copyInternal( public FileStoreTable copyWithLatestSchema() { Optional optionalLatestSchema = schemaManager().latest(); if (optionalLatestSchema.isPresent()) { - Map options = tableSchema.options(); - TableSchema newTableSchema = optionalLatestSchema.get(); - newTableSchema = newTableSchema.copy(options); + TableSchema latestSchema = optionalLatestSchema.get(); + Map mergedOptions = new HashMap<>(latestSchema.options()); + mergedOptions.putAll(tableSchema.options()); + TableSchema newTableSchema = latestSchema.copy(mergedOptions); SchemaValidation.validateTableSchema(newTableSchema); return copy(newTableSchema); } else { diff --git a/paimon-core/src/test/java/org/apache/paimon/table/SimpleTableTestBase.java b/paimon-core/src/test/java/org/apache/paimon/table/SimpleTableTestBase.java index cfdccc197ec3..e02c2bae1bea 100644 --- a/paimon-core/src/test/java/org/apache/paimon/table/SimpleTableTestBase.java +++ b/paimon-core/src/test/java/org/apache/paimon/table/SimpleTableTestBase.java @@ -615,6 +615,17 @@ public void testCopyWithLatestSchema() throws Exception { "1|40|400|binary|varbinary|mapKey:mapVal|multiset|4000")); } + @Test + public void testCopyWithLatestSchemaPicksUpAlteredOptions() throws Exception { + FileStoreTable table = createFileStoreTable(); + SchemaManager schemaManager = new SchemaManager(table.fileIO(), table.location()); + + schemaManager.commitChanges(SchemaChange.setOption("my-custom-key", "my-custom-value")); + + FileStoreTable updated = table.copyWithLatestSchema(); + assertThat(updated.schema().options()).containsEntry("my-custom-key", "my-custom-value"); + } + @Test public void testConsumerIdNotBlank() throws Exception { FileStoreTable table =