Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Kernel] Fix config passed to the column mapping mode change validation method #4197

Merged
merged 2 commits into from
Feb 28, 2025
Merged
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 @@ -170,11 +170,14 @@ public Transaction build(Engine engine) {
TableConfig.validateDeltaProperties(tableProperties.orElse(Collections.emptyMap()));
Map<String, String> newProperties = metadata.filterOutUnchangedProperties(validatedProperties);

ColumnMapping.verifyColumnMappingChange(metadata.getConfiguration(), newProperties, isNewTable);

if (!newProperties.isEmpty()) {
shouldUpdateMetadata = true;
Map<String, String> oldConfiguration = metadata.getConfiguration();

metadata = metadata.withNewConfiguration(newProperties);

ColumnMapping.verifyColumnMappingChange(
oldConfiguration, metadata.getConfiguration() /* new config */, isNewTable);
}

Optional<Tuple2<Protocol, Set<TableFeature>>> newProtocolAndFeatures =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,40 @@ class DeltaTableWritesSuite extends DeltaTableWriteSuiteBase with ParquetSuiteBa
}
}

test("update table properties on a column mapping enabled table") {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this wasn't super intuitive to me at first to understand the issue, can you confirm that I understand correctly?

  • before, we were passing only the newProperties as the new config
  • this means we would identify the newMappingMode=none and then fail?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thats correct.

withTempDirAndEngine { (tablePath, engine) =>
val table = Table.forPath(engine, tablePath)
val schema = new StructType()
.add("a", StringType.STRING, true)
.add("b", IntegerType.INTEGER, true)

createTxn(
engine,
tablePath,
isNewTable = true,
schema,
partCols = Seq.empty,
tableProperties = Map(TableConfig.COLUMN_MAPPING_MODE.getKey -> "id"))
.commit(engine, emptyIterable())

val structType = table.getLatestSnapshot(engine).getSchema()
assertColumnMapping(structType.get("a"), 1)
assertColumnMapping(structType.get("b"), 2)

table.createTransactionBuilder(engine, testEngineInfo, Operation.WRITE)
.withTableProperties(
engine,
Map("spark.sql.sources.provider" -> "delta").asJava)
.build(engine)
.commit(engine, emptyIterable())

val updatedTable = Table.forPath(engine, tablePath)
val updatedStructType = updatedTable.getLatestSnapshot(engine).getSchema()
assertColumnMapping(updatedStructType.get("a"), 1)
assertColumnMapping(updatedStructType.get("b"), 2)
}
}

test("unsupported protocol version with column mapping mode and no protocol update in metadata") {
// TODO
}
Expand Down
Loading