-
Notifications
You must be signed in to change notification settings - Fork 2.9k
ORC: skip non-iceberg columns when converting schema to Iceberg #1140
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
12 commits
Select commit
Hold shift + click to select a range
9104949
Skip columns without iceberg ids on schema conversion
edgarRd 2970838
Fix NPE on null list in ORC type visitor
edgarRd e74640c
Fix #1055 Use visitor to convert ORC schema to Iceberg
edgarRd d66cb47
Add test for skipping non-iceberg columns in ORC
edgarRd 170551c
Update javadoc
edgarRd 693a7fa
Add OrcSchemaVisitor
edgarRd 97c0fa4
Use Types.NestedField.of
edgarRd 79ca745
PR review
edgarRd cf39a31
Create method to visit ORC schema in OrcSchemaVisitor
edgarRd 9a4f68a
Track field names in OrcSchemaVisitor
edgarRd eef07c6
Compare schemas in test case
edgarRd ce01fe5
Move OrcToIcebergVisitor to separate file
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
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
105 changes: 105 additions & 0 deletions
105
orc/src/main/java/org/apache/iceberg/orc/OrcSchemaVisitor.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,105 @@ | ||
| /* | ||
| * 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.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.orc.TypeDescription; | ||
|
|
||
| /** | ||
| * Generic visitor of an ORC Schema. | ||
| */ | ||
| public abstract class OrcSchemaVisitor<T> { | ||
|
|
||
| public static <T> List<T> visitSchema(TypeDescription schema, OrcSchemaVisitor<T> visitor) { | ||
| Preconditions.checkArgument(schema.getId() == 0, "TypeDescription must be root schema."); | ||
|
|
||
| List<TypeDescription> fields = schema.getChildren(); | ||
| List<String> names = schema.getFieldNames(); | ||
|
|
||
| return visitFields(fields, names, visitor); | ||
| } | ||
|
|
||
| public static <T> T visit(TypeDescription schema, OrcSchemaVisitor<T> visitor) { | ||
| switch (schema.getCategory()) { | ||
| case STRUCT: | ||
| return visitRecord(schema, visitor); | ||
|
|
||
| case UNION: | ||
| throw new UnsupportedOperationException("Cannot handle " + schema); | ||
|
|
||
| case LIST: | ||
| return visitor.list(schema, visit(schema.getChildren().get(0), visitor)); | ||
|
|
||
| case MAP: | ||
| return visitor.map(schema, visit(schema.getChildren().get(0), visitor), | ||
| visit(schema.getChildren().get(1), visitor)); | ||
|
|
||
| default: | ||
| return visitor.primitive(schema); | ||
| } | ||
| } | ||
|
|
||
| private static <T> List<T> visitFields(List<TypeDescription> fields, List<String> names, | ||
| OrcSchemaVisitor<T> visitor) { | ||
| Preconditions.checkArgument(fields.size() == names.size(), "Not all fields have names in ORC struct"); | ||
|
|
||
| List<T> results = Lists.newArrayListWithExpectedSize(fields.size()); | ||
| for (int i = 0; i < fields.size(); i++) { | ||
| TypeDescription field = fields.get(i); | ||
| String name = names.get(i); | ||
| visitor.beforeField(name, field); | ||
| try { | ||
| results.add(visit(field, visitor)); | ||
| } finally { | ||
| visitor.afterField(name, field); | ||
| } | ||
| } | ||
| return results; | ||
| } | ||
|
|
||
| private static <T> T visitRecord(TypeDescription record, OrcSchemaVisitor<T> visitor) { | ||
| List<TypeDescription> fields = record.getChildren(); | ||
| List<String> names = record.getFieldNames(); | ||
|
|
||
| return visitor.record(record, names, visitFields(fields, names, visitor)); | ||
| } | ||
|
|
||
| public void beforeField(String name, TypeDescription type) {} | ||
|
|
||
| public void afterField(String name, TypeDescription type) {} | ||
|
|
||
| public T record(TypeDescription record, List<String> names, List<T> fields) { | ||
| return null; | ||
| } | ||
|
|
||
| public T list(TypeDescription array, T element) { | ||
| return null; | ||
| } | ||
|
|
||
| public T map(TypeDescription map, T key, T value) { | ||
| return null; | ||
| } | ||
|
|
||
| public T primitive(TypeDescription primitive) { | ||
| return null; | ||
| } | ||
| } |
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.