-
Notifications
You must be signed in to change notification settings - Fork 45
[default values] ORC/Spark: forward-port default-value reads via idToConstant (LI #76) #267
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
cbb330
merged 7 commits into
openhouse-1.2.0
from
chbush/oh120-orc-defaults-raymond-pr1
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
92ccc2d
ORC/Spark: forward-port default-value reads via idToConstant (LI #76)
cbb330 9c90f1a
ORC/Spark: apply spotless formatting for CI
cbb330 006163b
ORC/Spark: keep defaulted projections on the row reader
cbb330 7d2b5f0
ORC/Spark: trim process notes from source comments
cbb330 95fbc27
ORC/Spark: fix spotless wrap in default-value test javadoc
cbb330 fd10372
ORC/Spark: drop unused vectorized default-fill leftovers
cbb330 609e8b9
ORC/Spark: Spark inject visitor is row-reader only
cbb330 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
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
122 changes: 122 additions & 0 deletions
122
spark/v3.1/spark/src/main/java/org/apache/iceberg/spark/OrcSchemaWithTypeVisitorSpark.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,122 @@ | ||
| /* | ||
| * 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.spark; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.stream.Collectors; | ||
| import org.apache.iceberg.MetadataColumns; | ||
| import org.apache.iceberg.orc.ORCSchemaUtil; | ||
| import org.apache.iceberg.orc.OrcSchemaWithTypeVisitor; | ||
| import org.apache.iceberg.relocated.com.google.common.base.Preconditions; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Maps; | ||
| import org.apache.iceberg.spark.source.BaseDataReader; | ||
| import org.apache.iceberg.types.Types; | ||
| import org.apache.orc.TypeDescription; | ||
|
|
||
| /** | ||
| * Spark ORC schema visitor that injects {@code initial-default} values into {@code idToConstant} | ||
| * for fields omitted from the per-file ORC projection. | ||
| * | ||
| * <p>{@link org.apache.iceberg.spark.data.SparkOrcReader} uses this inject. Vectorized ORC does | ||
| * not; {@code SparkBatchScan} keeps defaulted projections on the row reader. | ||
| */ | ||
| public abstract class OrcSchemaWithTypeVisitorSpark<T> extends OrcSchemaWithTypeVisitor<T> { | ||
|
|
||
| private final Map<Integer, Object> idToConstant; | ||
|
|
||
| public Map<Integer, Object> getIdToConstant() { | ||
| return idToConstant; | ||
| } | ||
|
|
||
| protected OrcSchemaWithTypeVisitorSpark(Map<Integer, ?> idToConstant) { | ||
| this.idToConstant = Maps.newHashMap(); | ||
| this.idToConstant.putAll(idToConstant); | ||
| } | ||
|
|
||
| @Override | ||
| protected T visitRecord( | ||
| Types.StructType struct, TypeDescription record, OrcSchemaWithTypeVisitor<T> visitor) { | ||
| Preconditions.checkState( | ||
| icebergFieldIdsContainOrcFieldIdsInOrder(struct, record), | ||
| "Iceberg schema and ORC schema doesn't align, please call ORCSchemaUtil.buildOrcProjection" | ||
| + " to get an aligned ORC schema first!"); | ||
| List<Types.NestedField> iFields = struct.fields(); | ||
| List<TypeDescription> fields = record.getChildren(); | ||
| List<String> names = record.getFieldNames(); | ||
| List<T> results = Lists.newArrayListWithExpectedSize(fields.size()); | ||
|
|
||
| for (int i = 0, j = 0; i < iFields.size(); i++) { | ||
| Types.NestedField iField = iFields.get(i); | ||
| TypeDescription field = j < fields.size() ? fields.get(j) : null; | ||
| if (field == null || (iField.fieldId() != ORCSchemaUtil.fieldId(field))) { | ||
| // Cases that use idToConstant for an iField: | ||
| // 1. MetadataColumns.ROW_POSITION → RowPositionReader | ||
| // 2. Partition column → ConstantReader (already in idToConstant from PartitionUtil) | ||
| // 3. Field omitted because it declares initial-default → ConstantReader (inject here) | ||
| if (MetadataColumns.nonMetadataColumn(iField.name()) | ||
| && !idToConstant.containsKey(iField.fieldId()) | ||
| && iField.initialDefault() != null) { | ||
| idToConstant.put( | ||
|
cbb330 marked this conversation as resolved.
|
||
| iField.fieldId(), | ||
| BaseDataReader.convertConstant(iField.type(), iField.initialDefault())); | ||
| } | ||
| } else { | ||
| results.add(visit(iField.type(), field, visitor)); | ||
| j++; | ||
| } | ||
| } | ||
| return visitor.record(struct, record, names, results); | ||
| } | ||
|
|
||
| private static boolean icebergFieldIdsContainOrcFieldIdsInOrder( | ||
| Types.StructType struct, TypeDescription record) { | ||
| List<Integer> icebergIDList = | ||
| struct.fields().stream().map(Types.NestedField::fieldId).collect(Collectors.toList()); | ||
| List<Integer> orcIDList = | ||
| record.getChildren().stream().map(ORCSchemaUtil::fieldId).collect(Collectors.toList()); | ||
|
|
||
| return containsInOrder(icebergIDList, orcIDList); | ||
| } | ||
|
|
||
| /** | ||
| * Checks whether {@code list1} contains all integers from {@code list2} in the same relative | ||
| * order. {@code list1} may contain extra integers that {@code list2} does not. | ||
| */ | ||
| private static boolean containsInOrder(List<Integer> list1, List<Integer> list2) { | ||
|
cbb330 marked this conversation as resolved.
|
||
| if (list1.size() < list2.size()) { | ||
| return false; | ||
| } | ||
|
|
||
| for (int i = 0, j = 0; j < list2.size(); j++) { | ||
| if (i >= list1.size()) { | ||
| return false; | ||
| } | ||
| while (!list1.get(i).equals(list2.get(j))) { | ||
| i++; | ||
| if (i >= list1.size()) { | ||
| return false; | ||
| } | ||
| } | ||
| i++; | ||
| } | ||
| return true; | ||
| } | ||
| } | ||
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.
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.