-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Kernel][icebergWriterCompatV1] Add a check that map struct keys don't evolve #4525
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][icebergWriterCompatV1] Add a check that map struct keys don't evolve #4525
Conversation
* If IcebergWriterCompatV1 is enabled, we need to ensure that map struct keys don't change. This | ||
* validates that | ||
*/ | ||
private static void validateNoMapStructKeyChanges( |
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.
I wonder if this check should be nested deeper within the schema evolution checks? Then we can use the SchemaChanges
class @amogh-jahagirdar added to just check the "updatedColumns"
But I'm also okay with this if it's not any easier/better. Maybe it's fewer schema traversals however? Since I think this method alone involves at least 2
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.
Actually that's much nicer, thanks for the suggestion I didn't see the SchemaChanges stuff
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.
I was actually picturing nesting this even further in the existing code, I think it can just be an extra check in validateFieldCompatibility
. There we already have a branch where we have established a field update where we go from map type -> map type (skips a lot of this code here) and then all we need to add there is the additional check if icebergWriterCompatV1
is enabled & keyType is struct
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.
I think this should be super concise and simple there just something like
} else if (existingField.getDataType() instanceof MapType
&& newField.getDataType() instanceof MapType) {
MapType existingMapType = (MapType) existingField.getDataType();
MapType newMapType = (MapType) newField.getDataType();
if (icebergWriterCompatV1Enabled && existingMapType.getKeyType() instanceof StructType && newMapType.getKeyType() instanceof StructType) {
// Require existingMapType.getKeyType() equals newMapType.getKeyType()
}
validateFieldCompatibility(existingMapType.getKeyField(), newMapType.getKeyField());
validateFieldCompatibility(existingMapType.getValueField(), newMapType.getValueField());
}
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.
Ohh man, can't believe I missed that those checks already exist. Thanks! That's obviously much better.
kernel/kernel-api/src/main/java/io/delta/kernel/internal/util/SchemaUtils.java
Outdated
Show resolved
Hide resolved
kernel/kernel-api/src/main/java/io/delta/kernel/internal/util/SchemaUtils.java
Outdated
Show resolved
Hide resolved
kernel/kernel-api/src/main/java/io/delta/kernel/internal/util/SchemaUtils.java
Outdated
Show resolved
Hide resolved
kernel/kernel-api/src/main/java/io/delta/kernel/internal/util/SchemaUtils.java
Outdated
Show resolved
Hide resolved
* If IcebergWriterCompatV1 is enabled, we need to ensure that map struct keys don't change. This | ||
* validates that | ||
*/ | ||
private static void validateNoMapStructKeyChanges( |
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.
I was actually picturing nesting this even further in the existing code, I think it can just be an extra check in validateFieldCompatibility
. There we already have a branch where we have established a field update where we go from map type -> map type (skips a lot of this code here) and then all we need to add there is the additional check if icebergWriterCompatV1
is enabled & keyType is struct
* If IcebergWriterCompatV1 is enabled, we need to ensure that map struct keys don't change. This | ||
* validates that | ||
*/ | ||
private static void validateNoMapStructKeyChanges( |
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.
I think this should be super concise and simple there just something like
} else if (existingField.getDataType() instanceof MapType
&& newField.getDataType() instanceof MapType) {
MapType existingMapType = (MapType) existingField.getDataType();
MapType newMapType = (MapType) newField.getDataType();
if (icebergWriterCompatV1Enabled && existingMapType.getKeyType() instanceof StructType && newMapType.getKeyType() instanceof StructType) {
// Require existingMapType.getKeyType() equals newMapType.getKeyType()
}
validateFieldCompatibility(existingMapType.getKeyField(), newMapType.getKeyField());
validateFieldCompatibility(existingMapType.getValueField(), newMapType.getValueField());
}
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.
LGTM
Which Delta project/connector is this regarding?
Description
Add a check to forbid changes in struct types that are map keys. See docs which state:
We have empirically determined that drops also trigger an error, so we forbid any changes to structs that are used as map keys.
This check only triggers if IcebergWriterCompatV1 is enabled on the table. This is required by the spec (see here)
How was this patch tested?
Unit Tests
Does this PR introduce any user-facing changes?
No