-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Core: Prevent dropping column which is referenced by active partition specs #11842
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -437,8 +437,8 @@ private void internalMove(String name, Move move) { | |
@Override | ||
public Schema apply() { | ||
Schema newSchema = | ||
applyChanges(schema, deletes, updates, adds, moves, identifierFieldNames, caseSensitive); | ||
|
||
applyChanges( | ||
schema, deletes, updates, adds, moves, identifierFieldNames, caseSensitive, base); | ||
return newSchema; | ||
} | ||
|
||
|
@@ -508,7 +508,8 @@ private static Schema applyChanges( | |
Multimap<Integer, Types.NestedField> adds, | ||
Multimap<Integer, Move> moves, | ||
Set<String> identifierFieldNames, | ||
boolean caseSensitive) { | ||
boolean caseSensitive, | ||
TableMetadata base) { | ||
// validate existing identifier fields are not deleted | ||
Map<Integer, Integer> idToParent = TypeUtil.indexParents(schema.asStruct()); | ||
|
||
|
@@ -533,6 +534,25 @@ private static Schema applyChanges( | |
} | ||
} | ||
|
||
if (base != null) { | ||
for (int fieldIdToDelete : deletes) { | ||
base.specsById() | ||
.forEach( | ||
(specId, spec) -> { | ||
// Prevent dropping fields that are referenced in older partitions specs in use. | ||
if (!specId.equals(base.defaultSpecId())) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wondering if we will run into the issue again if we allow dropping from current spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although, dropping partition source columns from the current spec will fail later when building table metadata. We should remove the if condition here as we certainly cannot remove partition source columns in the current spec. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes sense. My concern is that this is a big behavior change. Users cannot drop partition columns at all. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't users can drop partition source field/columns(please note , not the partition columns) in current spec. See the following test: TestTables.TestTable table =
TestTables.create(tableDir, "test", SCHEMA, BY_DATA_SPEC, V1_FORMAT_VERSION);
table.updateSchema().deleteColumn("data").commit(); will throws:
So, it make sense to not allow dropping partition source columns in other active partition specs as well. The only problem is that the void transform in V1 table, which still references a source column. |
||
if (spec.fields().stream() | ||
.anyMatch(partitionField -> partitionField.sourceId() == fieldIdToDelete)) { | ||
throw new IllegalArgumentException( | ||
String.format( | ||
"Cannot delete field id %s as it is used by an active partition spec id %s", | ||
fieldIdToDelete, specId)); | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
|
||
// apply schema changes | ||
Types.StructType struct = | ||
TypeUtil.visit(schema, new ApplyChanges(deletes, updates, adds, moves)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe just passing
Map<Integer, PartitionSpec> specsById
here.