-
Notifications
You must be signed in to change notification settings - Fork 3k
ORC: Use ConstantReader for identity partition columns #1191
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,7 +22,6 @@ | |
| import java.util.Arrays; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import org.apache.iceberg.relocated.com.google.common.collect.Lists; | ||
| import org.apache.iceberg.types.Types; | ||
| import org.apache.orc.storage.ql.exec.vector.BytesColumnVector; | ||
| import org.apache.orc.storage.ql.exec.vector.ColumnVector; | ||
|
|
@@ -59,6 +58,10 @@ public static OrcValueReader<byte[]> bytes() { | |
| return BytesReader.INSTANCE; | ||
| } | ||
|
|
||
| public static <C> OrcValueReader<C> constants(C constant) { | ||
| return new ConstantReader<>(constant); | ||
| } | ||
|
|
||
| private static class BooleanReader implements OrcValueReader<Boolean> { | ||
| static final BooleanReader INSTANCE = new BooleanReader(); | ||
|
|
||
|
|
@@ -136,31 +139,21 @@ public byte[] nonNullRead(ColumnVector vector, int row) { | |
|
|
||
| public abstract static class StructReader<T> implements OrcValueReader<T> { | ||
| private final OrcValueReader<?>[] readers; | ||
| private final int[] positions; | ||
| private final Object[] constants; | ||
|
|
||
| protected StructReader(List<OrcValueReader<?>> readers) { | ||
| this.readers = readers.toArray(new OrcValueReader[0]); | ||
| this.positions = new int[0]; | ||
| this.constants = new Object[0]; | ||
| } | ||
| private final boolean[] isConstantField; | ||
|
|
||
| protected StructReader(List<OrcValueReader<?>> readers, Types.StructType struct, Map<Integer, ?> idToConstant) { | ||
| this.readers = readers.toArray(new OrcValueReader[0]); | ||
| List<Types.NestedField> fields = struct.fields(); | ||
| List<Integer> positionList = Lists.newArrayListWithCapacity(fields.size()); | ||
| List<Object> constantList = Lists.newArrayListWithCapacity(fields.size()); | ||
| for (int pos = 0; pos < fields.size(); pos += 1) { | ||
| this.readers = new OrcValueReader[fields.size()]; | ||
| this.isConstantField = new boolean[fields.size()]; | ||
| for (int pos = 0, readerIndex = 0; pos < fields.size(); pos += 1) { | ||
| Types.NestedField field = fields.get(pos); | ||
| Object constant = idToConstant.get(field.fieldId()); | ||
| if (constant != null) { | ||
| positionList.add(pos); | ||
| constantList.add(idToConstant.get(field.fieldId())); | ||
| if (idToConstant.containsKey(field.fieldId())) { | ||
| this.isConstantField[pos] = true; | ||
| this.readers[pos] = constants(idToConstant.get(field.fieldId())); | ||
| } else { | ||
| this.readers[pos] = readers.get(readerIndex++); | ||
| } | ||
| } | ||
|
|
||
| this.positions = positionList.stream().mapToInt(Integer::intValue).toArray(); | ||
| this.constants = constantList.toArray(); | ||
| } | ||
|
|
||
| protected abstract T create(); | ||
|
|
@@ -178,15 +171,29 @@ public T nonNullRead(ColumnVector vector, int row) { | |
| } | ||
|
|
||
| private T readInternal(T struct, ColumnVector[] columnVectors, int row) { | ||
| for (int c = 0; c < readers.length; ++c) { | ||
| set(struct, c, reader(c).read(columnVectors[c], row)); | ||
| for (int c = 0, vectorIndex = 0; c < readers.length; ++c) { | ||
| ColumnVector vector = isConstantField[c] ? null : columnVectors[vectorIndex++]; | ||
| set(struct, c, reader(c).read(vector, row)); | ||
| } | ||
| return struct; | ||
| } | ||
| } | ||
|
|
||
| for (int i = 0; i < positions.length; i += 1) { | ||
| set(struct, positions[i], constants[i]); | ||
| } | ||
| private static class ConstantReader<C> implements OrcValueReader<C> { | ||
| private final C constant; | ||
|
|
||
| return struct; | ||
| private ConstantReader(C constant) { | ||
| this.constant = constant; | ||
| } | ||
|
|
||
| @Override | ||
| public C read(ColumnVector ignored, int ignoredRow) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I guess we can do that by not asking ORC to project these columns. Let me give it a try.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's going to be a bigger time savings and that's what we do for Parquet. We just drop it from the projection we pass down to the format. |
||
| return constant; | ||
| } | ||
|
|
||
| @Override | ||
| public C nonNullRead(ColumnVector ignored, int ignoredRow) { | ||
| return constant; | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.