Guosmilesmile commented on code in PR #15776:
URL: https://github.com/apache/iceberg/pull/15776#discussion_r3203015127
##########
orc/src/main/java/org/apache/iceberg/orc/OrcValueReaders.java:
##########
@@ -163,6 +180,122 @@ protected StructReader(
}
}
+ protected StructReader(
+ TypeDescription orcType,
+ List<OrcValueReader<?>> readers,
+ Types.StructType struct,
+ Map<Integer, ?> idToConstant) {
+ List<Types.NestedField> fields = struct.fields();
+ this.readers = new OrcValueReader[fields.size()];
+ this.isConstantOrMetadataField = new boolean[fields.size()];
+ this.orcFieldIndex = new int[fields.size()];
+
+ Map<Integer, OrcValueReader<?>> readersById = readersByFieldId(orcType,
readers);
+ Map<Integer, Integer> fieldIdToOrcIndex =
buildFieldIdToOrcIndex(orcType);
+
+ for (int pos = 0; pos < fields.size(); pos += 1) {
+ Types.NestedField field = fields.get(pos);
+ OrcValueReader<?> fileReader = readersById.get(field.fieldId());
+ int orcIndex = fieldIdToOrcIndex.getOrDefault(field.fieldId(), -1);
+
+ if (field.equals(MetadataColumns.ROW_ID)) {
+ handleRowIdField(pos, field, fileReader, idToConstant, orcIndex);
+ } else if (field.equals(MetadataColumns.LAST_UPDATED_SEQUENCE_NUMBER))
{
+ handleLastUpdatedSeqField(pos, field, fileReader, idToConstant,
orcIndex);
+ } else if (idToConstant.containsKey(field.fieldId())) {
+ this.isConstantOrMetadataField[pos] = true;
+ this.readers[pos] = constants(idToConstant.get(field.fieldId()));
+ } else if (field.equals(MetadataColumns.ROW_POSITION)) {
+ this.isConstantOrMetadataField[pos] = true;
+ this.readers[pos] = new RowPositionReader();
+ } else if (field.equals(MetadataColumns.IS_DELETED)) {
+ this.isConstantOrMetadataField[pos] = true;
+ this.readers[pos] = constants(false);
+ } else if (fileReader != null) {
+ this.isConstantOrMetadataField[pos] = false;
+ this.orcFieldIndex[pos] =
fieldIdToOrcIndex.getOrDefault(field.fieldId(), -1);
+ this.readers[pos] = fileReader;
+ } else if (MetadataColumns.isMetadataColumn(field.name())
+ || field.type().typeId() == Type.TypeID.UNKNOWN) {
+ this.isConstantOrMetadataField[pos] = true;
+ this.readers[pos] = constants(null);
+ } else {
+ throw new IllegalArgumentException(
+ String.format("Missing ORC reader for field %s (%s)",
field.name(), field.fieldId()));
+ }
+ }
+ }
+
+ private Map<Integer, Integer> buildFieldIdToOrcIndex(TypeDescription
orcType) {
+ List<TypeDescription> children = orcType.getChildren();
+ Map<Integer, Integer> mapping = Maps.newHashMap();
+ for (int i = 0; i < children.size(); i++) {
+ mapping.put(ORCSchemaUtil.fieldId(children.get(i)), i);
Review Comment:
Old ORC files are handled before this code path reaches `StructReader`. In
OrcIterable, if `ORCSchemaUtil.hasIds(fileSchema)` is false, `OrcIterable`
applies a name mapping to the file schema
https://github.com/apache/iceberg/blob/f767dad20e9a47495ce37f1acf6acdffbf63664d/orc/src/main/java/org/apache/iceberg/orc/OrcIterable.java#L87-L96
`applyNameMapping` sets `ICEBERG_ID_ATTRIBUTE` on the in-memory
TypeDescription, so `StructReader` receives a projected ORC schema with field
IDs.
So StructReader receives the projected readOrcSchema with field IDs, not the
raw id-less file schema.
This assumes the reader is constructed through the normal OrcIterable path;
directly passing a raw
id-less ORC schema to StructReader would still be invalid.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]