@Override public String toString() { return String.format("list<%s>", elementField.type()); }
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(); } }
private static ResourceFieldSchema convert(Types.NestedField field) throws IOException { ResourceFieldSchema result = convert(field.type()); result.setName(field.name()); result.setDescription(format("FieldId: %s", field.fieldId())); return result; }
public static void assertEqualsSafe(Types.StructType struct, Record rec, Row row) { List<Types.NestedField> fields = struct.fields(); for (int i = 0; i < fields.size(); i += 1) { Type fieldType = fields.get(i).type(); Object expectedValue = rec.get(i); Object actualValue = row.get(i); assertEqualsSafe(fieldType, expectedValue, actualValue); } }
public static void assertEqualsUnsafe(Types.StructType struct, Record rec, InternalRow row) { List<Types.NestedField> fields = struct.fields(); for (int i = 0; i < fields.size(); i += 1) { Type fieldType = fields.get(i).type(); Object expectedValue = rec.get(i); Object actualValue = row.get(i, convert(fieldType)); assertEqualsUnsafe(fieldType, expectedValue, actualValue); } }
@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; } }
public static void assertEquals(Types.StructType struct, Record expected, Record actual) { List<Types.NestedField> fields = struct.fields(); for (int i = 0; i < fields.size(); i += 1) { Type fieldType = fields.get(i).type(); Object expectedValue = expected.get(i); Object actualValue = actual.get(i); assertEquals(fieldType, expectedValue, actualValue); } }
public Builder add(int sourceId, String name, String transform) { checkAndAddPartitionName(name); Types.NestedField column = schema.findField(sourceId); Preconditions.checkNotNull(column, "Cannot find source column: %d", sourceId); fields.add(new PartitionField( sourceId, name, Transforms.fromString(column.type(), transform))); return this; }
@Override public T get() { return visitor.field(field, new VisitFuture<>(field.type(), visitor)); } }
/** * Returns the {@link Type} of a sub-field identified by the field id. * * @param id a field id * @return a Type for the sub-field or null if it is not found */ public Type findType(int id) { Types.NestedField field = lazyIdToField().get(id); if (field != null) { return field.type(); } return null; }
@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; } }
BoundReference(Types.StructType struct, int fieldId) { this.fieldId = fieldId; this.pos = find(fieldId, struct); this.type = struct.fields().get(pos).type(); }
@Override public Type field(Types.NestedField field, Type fieldResult) { if (selected.contains(field.fieldId())) { return field.type(); } else if (fieldResult != null) { // this isn't necessarily the same as field.type() because a struct may not have all // fields selected. return fieldResult; } return null; }
PartitionData(Types.StructType partitionType) { for (Types.NestedField field : partitionType.fields()) { Preconditions.checkArgument(field.type().isPrimitiveType(), "Partitions cannot contain nested types: " + field.type()); } this.partitionType = partitionType; this.size = partitionType.fields().size(); this.data = new Object[size]; this.schema = getSchema(partitionType); this.stringSchema = schema.toString(); }
public Builder hour(String sourceName) { String name = sourceName + "_hour"; checkAndAddPartitionName(name); Types.NestedField sourceColumn = findSourceColumn(sourceName); fields.add(new PartitionField( sourceColumn.fieldId(), name, Transforms.hour(sourceColumn.type()))); return this; }
@Override public Type fieldType(String name) { NestedField field = field(name); if (field != null) { return field.type(); } return null; }
public Builder month(String sourceName) { String name = sourceName + "_month"; checkAndAddPartitionName(name); Types.NestedField sourceColumn = findSourceColumn(sourceName); fields.add(new PartitionField( sourceColumn.fieldId(), name, Transforms.month(sourceColumn.type()))); return this; }
public Builder year(String sourceName) { String name = sourceName + "_year"; checkAndAddPartitionName(name); Types.NestedField sourceColumn = findSourceColumn(sourceName); fields.add(new PartitionField( sourceColumn.fieldId(), name, Transforms.year(sourceColumn.type()))); return this; }
public Builder day(String sourceName) { String name = sourceName + "_day"; checkAndAddPartitionName(name); Types.NestedField sourceColumn = findSourceColumn(sourceName); fields.add(new PartitionField( sourceColumn.fieldId(), name, Transforms.day(sourceColumn.type()))); return this; }