-
Notifications
You must be signed in to change notification settings - Fork 2.9k
ORC: Add name mapping support #1208
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f340ce0
ORC: Implement name mapping strategy
edgarRd 4796b2b
Add tests for ORC name mapping
edgarRd 4e49814
Reuse field name tracking in OrcSchemaVisitor
edgarRd 2b365e8
Minor changes
edgarRd c0c4eb5
Check mapped IDs in test
edgarRd 75fc9fd
Compute name mapping if no ids are found
edgarRd ff01d48
Add more tests
edgarRd b74abd8
Remove Ids only
edgarRd 91b6a0e
Fix typo
edgarRd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
orc/src/main/java/org/apache/iceberg/orc/ApplyNameMapping.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iceberg.orc; | ||
|
|
||
| import java.util.List; | ||
| import org.apache.iceberg.mapping.MappedField; | ||
| import org.apache.iceberg.mapping.NameMapping; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.orc.TypeDescription; | ||
|
|
||
| class ApplyNameMapping extends OrcSchemaVisitor<TypeDescription> { | ||
| private final NameMapping nameMapping; | ||
|
|
||
| ApplyNameMapping(NameMapping nameMapping) { | ||
| this.nameMapping = nameMapping; | ||
| } | ||
|
|
||
| @Override | ||
| public String elementName() { | ||
| return "element"; | ||
| } | ||
|
|
||
| @Override | ||
| public String keyName() { | ||
| return "key"; | ||
| } | ||
|
|
||
| @Override | ||
| public String valueName() { | ||
| return "value"; | ||
| } | ||
|
|
||
| TypeDescription setId(TypeDescription type, MappedField mappedField) { | ||
| if (mappedField != null) { | ||
| type.setAttribute(ORCSchemaUtil.ICEBERG_ID_ATTRIBUTE, mappedField.id().toString()); | ||
| } | ||
| return type; | ||
| } | ||
|
|
||
| @Override | ||
| public TypeDescription record(TypeDescription record, List<String> names, List<TypeDescription> fields) { | ||
| Preconditions.checkArgument(names.size() == fields.size(), "All fields must have names"); | ||
| MappedField field = nameMapping.find(currentPath()); | ||
| TypeDescription structType = TypeDescription.createStruct(); | ||
|
|
||
| for (int i = 0; i < fields.size(); i++) { | ||
| String fieldName = names.get(i); | ||
| TypeDescription fieldType = fields.get(i); | ||
| if (fieldType != null) { | ||
| structType.addField(fieldName, fieldType); | ||
| } | ||
| } | ||
| return setId(structType, field); | ||
| } | ||
|
|
||
| @Override | ||
| public TypeDescription list(TypeDescription array, TypeDescription element) { | ||
| Preconditions.checkArgument(element != null, "List type must have element type"); | ||
|
|
||
| MappedField field = nameMapping.find(currentPath()); | ||
| TypeDescription listType = TypeDescription.createList(element); | ||
| return setId(listType, field); | ||
| } | ||
|
|
||
| @Override | ||
| public TypeDescription map(TypeDescription map, TypeDescription key, TypeDescription value) { | ||
| Preconditions.checkArgument(key != null && value != null, "Map type must have both key and value types"); | ||
|
|
||
| MappedField field = nameMapping.find(currentPath()); | ||
| TypeDescription mapType = TypeDescription.createMap(key, value); | ||
| return setId(mapType, field); | ||
| } | ||
|
|
||
| @Override | ||
| public TypeDescription primitive(TypeDescription primitive) { | ||
| MappedField field = nameMapping.find(currentPath()); | ||
| return setId(primitive.clone(), field); | ||
rdsr marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
|
|
||
| package org.apache.iceberg.orc; | ||
|
|
||
| import java.util.List; | ||
| import java.util.function.Predicate; | ||
| import org.apache.orc.TypeDescription; | ||
|
|
||
| class HasIds extends OrcSchemaVisitor<Boolean> { | ||
|
|
||
| @Override | ||
| public Boolean record(TypeDescription record, List<String> names, List<Boolean> fields) { | ||
| return ORCSchemaUtil.icebergID(record).isPresent() || fields.stream().anyMatch(Predicate.isEqual(true)); | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean list(TypeDescription array, Boolean element) { | ||
| return ORCSchemaUtil.icebergID(array).isPresent() || element; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean map(TypeDescription map, Boolean key, Boolean value) { | ||
| return ORCSchemaUtil.icebergID(map).isPresent() || key || value; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean primitive(TypeDescription primitive) { | ||
| return ORCSchemaUtil.icebergID(primitive).isPresent(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.