Uh oh!
There was an error while loading. Please reload this page.
Core: Fix querying metadata tables with multiple specs - #2936
Conversation
aokolnychyi
commented
Aug 4, 2021
| TableOperations ops = ((HasTableOperations) table).operations(); | ||
| TableMetadata current = ops.current(); | ||
| ops.commit(current, current.updatePartitionSpec(newSpec)); |
There was a problem hiding this comment.
Can we make change for the method updatePartitionSpec to avoid conflicts?
There was a problem hiding this comment.
This API is hidden from users. The user-facing API is UpdatePartitionSpec accessible via Table. That one actually ensures we don't hit this case. The spec evolution in v1 tables is actually limited as described here.
There could be some tables where people evolved partitioning before the public API appeared. It is an edge case but this test ensures we get a reasonable exception for such tables.
There was a problem hiding this comment.
I see, this part, https://iceberg.apache.org/spec/#partition-evolution.
| table.updateSpec() | ||
| .removeField("data") | ||
| .commit(); |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
RussellSpitzer
commented
Aug 4, 2021
Do we have to worry about the Manifests Table? Or is it ok because we are always displaying in the context of the current spec? |
RussellSpitzer
left a comment
There was a problem hiding this comment.
A few minor comments, but looks good to me overall
jackye1995
left a comment
There was a problem hiding this comment.
looks good to me, thanks for the fix!
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
3e5ba47 to
93a7fd8Compareaokolnychyi
commented
Aug 5, 2021
@RussellSpitzer, somehow tests for Checking what is actually going on. |
@RussellSpitzer, I think simply using |
RussellSpitzer
commented
Aug 5, 2021
@aokolnychyi Sounds good to me, I thought I mimicd the way we were doing it in the FilesTable using the "fileSchema" as the projected schema, if that isn't the scan.schema we should change it |
aokolnychyi
commented
Aug 5, 2021
Well, I am not sure. I'll need your help to verify whether my assumption is correct. We are using the same |
93a7fd8 to
ec1f573CompareUh oh!
There was an error while loading. Please reload this page.
| List<NestedField> sortedCommonFields = commonFields.values().stream() | ||
| .sorted(Comparator.comparingInt(NestedField::fieldId)) | ||
| .collect(Collectors.toList()); |
kbendick
left a comment
There was a problem hiding this comment.
Overall, this looks good to me.
Same question that Ryan has regarding checking name during validation in partitionType, but overall this looks good to me. Thanks Anton!
| List<NestedField> structFields = Lists.newArrayList(); | ||
| // sort the spec IDs in descending order to pick up the most recent field names | ||
| List<Integer> specIds = table.specs().keySet().stream() |
There was a problem hiding this comment.
Added a sort by spec ID to make sure we pick up the most recent field name (see a dedicated test too).
| } | ||
| @Test | ||
| public void testPartitionTypeWithAddingBackSamePartitionFieldInV1Table() { |
There was a problem hiding this comment.
This test validates we ignore field names when building the common type. The original spec will have 1000:data and the last spec will have 1000:data_1000 as the old field was renamed to avoid naming conflicts.
Uh oh!
There was an error while loading. Please reload this page.
| structFields.add(structField); | ||
| } else { | ||
| // verify the fields are compatible as they may conflict in v1 tables | ||
| ValidationException.check(field.compatibleWith(existingField), |
There was a problem hiding this comment.
I would probably just make equivalentIgnoringName a private method in this class for this.
| NestedField.optional(1001, "data", Types.StringType.get()) | ||
| ); | ||
| StructType actualType = Partitioning.partitionType(table); | ||
| Assert.assertEquals("Types must match", expectedType, actualType); |
There was a problem hiding this comment.
I think you could argue that adding data back should re-use the old ID. Not something to fix here, but we should probably fix it at some point.
There was a problem hiding this comment.
It is indeed wierd. However, I would not worry too much here as we have already stated not to rename and drop fields in v1 tables.
rdblue
left a comment
There was a problem hiding this comment.
Looks good to me, other than the compatibleWith method that conflicts with the one in PartitionSpec.
aokolnychyi
commented
Aug 14, 2021
Yeah, I wasn't sure about the method name. Updated. |
aokolnychyi
commented
Aug 14, 2021
Thanks for reviewing, @flyrain@karuppayya@RussellSpitzer@rdblue@kbendick@jackye1995! |
This PR adds a utility method to derive a common type for all partition specs.
Prior to this change, querying metadata tables in v2 format with evolved partitioning failed with runtime exceptions.