private static <T> T visitField(Types.NestedField iField, Type field, TypeWithSchemaVisitor<T> visitor) { visitor.fieldNames.push(field.getName()); try { return visit(iField != null ? iField.type() : null, field, visitor); } finally { visitor.fieldNames.pop(); } }
public static <T> T visit(com.netflix.iceberg.types.Type iType, Type type, TypeWithSchemaVisitor<T> visitor) { if (type instanceof MessageType) { Types.StructType struct = iType != null ? iType.asStructType() : null; return visitor.message(struct, (MessageType) type, visitFields(struct, type.asGroupType(), visitor)); return visitor.primitive(iPrimitive, type.asPrimitiveType()); T elementResult = null; if (repeatedElement.getFieldCount() > 0) { elementResult = visitField(element, repeatedElement.getType(0), visitor); return visitor.list(list, group, elementResult); case 2: keyResult = visitField(keyField, repeatedKeyValue.getType(0), visitor); valueResult = visitField(valueField, repeatedKeyValue.getType(1), visitor); case 1: keyResult = visitField(keyField, keyOrValue, visitor); valueResult = visitField(valueField, keyOrValue, visitor); return visitor.map(map, group, keyResult, valueResult); return visitor.struct(struct, group, visitFields(struct, group, visitor));
private static <T> List<T> visitFields(Types.StructType struct, GroupType group, TypeWithSchemaVisitor<T> visitor) { List<T> results = Lists.newArrayListWithExpectedSize(group.getFieldCount()); for (Type field : group.getFields()) { int id = -1; if (field.getId() != null) { id = field.getId().intValue(); } Types.NestedField iField = (struct != null && id >= 0) ? struct.field(id) : null; results.add(visitField(iField, field, visitor)); } return results; }
@SuppressWarnings("unchecked") public static ParquetValueReader<Record> buildReader(com.netflix.iceberg.Schema expectedSchema, MessageType fileSchema) { return (ParquetValueReader<Record>) TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, new ReadBuilder(expectedSchema, fileSchema)); }
@SuppressWarnings("unchecked") public static ParquetValueReader<Tuple> buildReader(MessageType fileSchema, Schema expectedSchema, Map<Integer, Object> partitionValues) { if (hasIds(fileSchema)) { return (ParquetValueReader<Tuple>) TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, new ReadBuilder(fileSchema, partitionValues)); } else { return (ParquetValueReader<Tuple>) TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, new FallbackReadBuilder(fileSchema, partitionValues)); } }
@SuppressWarnings("unchecked") public static ParquetValueReader<InternalRow> buildReader(Schema expectedSchema, MessageType fileSchema) { if (hasIds(fileSchema)) { return (ParquetValueReader<InternalRow>) TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, new ReadBuilder(fileSchema)); } else { return (ParquetValueReader<InternalRow>) TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, new FallbackReadBuilder(fileSchema)); } }
@SuppressWarnings("unchecked") public static ParquetValueReader<GenericRecord> buildReader(Schema expectedSchema, MessageType fileSchema) { if (hasIds(fileSchema)) { return (ParquetValueReader<GenericRecord>) TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, new ReadBuilder(fileSchema)); } else { return (ParquetValueReader<GenericRecord>) TypeWithSchemaVisitor.visit(expectedSchema.asStruct(), fileSchema, new FallbackReadBuilder(fileSchema)); } }