pvary commented on code in PR #15776:
URL: https://github.com/apache/iceberg/pull/15776#discussion_r3201623918
##########
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:
What happens with old ORC files here?
When the Iceberg `ICEBERG_ID_ATTRIBUTE` is not yet set in the ORC column
metadata?
--
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]