@Override public Type field(Types.NestedField field, Supplier<Type> future) { Preconditions.checkArgument(sourceType.isStructType(), "Not a struct: " + sourceType); Types.StructType sourceStruct = sourceType.asStructType(); this.sourceType = sourceStruct.field(field.fieldId()).type(); try { return future.get(); } finally { sourceType = sourceStruct; } }
@Override public Type field(Types.NestedField field, Supplier<Type> future) { Preconditions.checkArgument(sourceType.isStructType(), "Not a struct: " + sourceType); Types.StructType sourceStruct = sourceType.asStructType(); Types.NestedField sourceField = sourceStruct.field(field.name()); this.sourceType = sourceField.type(); try { return future.get(); } finally { sourceType = sourceStruct; } }
Preconditions.checkNotNull(readStruct, "Evaluation must start with a schema."); if (!currentType.isStructType()) { return ImmutableList.of(String.format(": %s cannot be read as a struct", currentType));
@Override public Type struct(Types.StructType struct, Iterable<Type> fieldTypes) { Preconditions.checkNotNull(sourceType, "Evaluation must start with a schema."); Preconditions.checkArgument(sourceType.isStructType(), "Not a struct: " + sourceType); Types.StructType sourceStruct = sourceType.asStructType(); List<Types.NestedField> fields = struct.fields(); int length = fields.size(); List<Type> types = Lists.newArrayList(fieldTypes); List<Types.NestedField> newFields = Lists.newArrayListWithExpectedSize(length); for (int i = 0; i < length; i += 1) { Types.NestedField field = fields.get(i); int sourceFieldId = sourceStruct.field(field.name()).fieldId(); if (field.isRequired()) { newFields.add(Types.NestedField.required(sourceFieldId, field.name(), types.get(i))); } else { newFields.add(Types.NestedField.optional(sourceFieldId, field.name(), types.get(i))); } } return Types.StructType.of(newFields); }
@Override public Type struct(Types.StructType struct, Iterable<Type> fieldTypes) { Preconditions.checkArgument(sourceType.isStructType(), "Not a struct: " + sourceType); List<Types.NestedField> fields = struct.fields(); int length = fields.size(); List<Type> types = Lists.newArrayList(fieldTypes); List<Types.NestedField> newFields = Lists.newArrayListWithExpectedSize(length); boolean hasChange = false; for (int i = 0; i < length; i += 1) { Types.NestedField field = fields.get(i); Type resultType = types.get(i); if (field.type() == resultType) { newFields.add(field); } else if (field.isRequired()) { hasChange = true; newFields.add(Types.NestedField.required(field.fieldId(), field.name(), resultType)); } else { hasChange = true; newFields.add(Types.NestedField.optional(field.fieldId(), field.name(), resultType)); } } if (hasChange) { return Types.StructType.of(newFields); } return struct; }
if (listType.elementType().isStructType()) { result.setFields(elementFieldSchemas); } else {