@Override public T get() { return visitor.field(field, new VisitFuture<>(field.type(), visitor)); } }
@SuppressWarnings("unchecked") private Class<T> javaType() { return (Class<T>) type.asPrimitiveType().typeId().javaClass(); } }
@Test public void testComplexMapKey() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, StructType.of( required(4, "i", Types.IntegerType.get()), optional(5, "s", Types.StringType.get())), Types.StringType.get()))); writeAndValidate(schema); }
@Test public void testComplex() throws IOException { convertToPigSchema( new Schema( optional(1, "bag", ListType.ofOptional(2, BooleanType.get())), optional(3, "map", MapType.ofOptional(4,5, StringType.get(), DoubleType.get())), optional(6, "tuple", StructType.of(optional(7, "i", IntegerType.get()), optional(8,"f", FloatType.get()))) ),"bag:{(boolean)},map:[double],tuple:(i:int,f:float)", null ); }
@Test public void testLongInBag() throws IOException { Schema icebergSchema = new Schema( optional( 1, "nested_list", MapType.ofOptional( 2, 3, StringType.get(), ListType.ofRequired(5, LongType.get())))); SchemaUtil.convert(icebergSchema); }
private static Schema applyChanges(Schema schema, List<Integer> deletes, Map<Integer, Types.NestedField> updates, Multimap<Integer, Types.NestedField> adds) { Types.StructType struct = TypeUtil .visit(schema, new ApplyChanges(deletes, updates, adds)) .asNestedType().asStructType(); return new Schema(struct.fields()); }
/** * Assigns fresh ids from the {@link NextID nextId function} for all fields in a schema. * * @param schema a schema * @param nextId an id assignment function * @return an structurally identical schema with new ids assigned by the nextId function */ public static Schema assignFreshIds(Schema schema, NextID nextId) { return new Schema(TypeUtil .visit(schema.asStruct(), new AssignFreshIds(nextId)) .asNestedType() .fields()); }
public static Set<Integer> getProjectedIds(Type schema) { if (schema.isPrimitiveType()) { return ImmutableSet.of(); } return ImmutableSet.copyOf(visit(schema, new GetProjectedIds())); }
/** * Returns a list of compatibility errors for writing with the given write schema. * * @param readSchema a read schema * @param writeSchema a write schema * @return a list of error details, or an empty list if there are no compatibility problems */ public static List<String> writeCompatibilityErrors(Schema readSchema, Schema writeSchema) { return TypeUtil.visit(readSchema, new CheckCompatibility(writeSchema, true)); }
/** * Assigns fresh ids from the {@link NextID nextId function} for all fields in a type. * * @param type a type * @param nextId an id assignment function * @return an structurally identical type with new ids assigned by the nextId function */ public static Type assignFreshIds(Type type, NextID nextId) { return TypeUtil.visit(type, new AssignFreshIds(nextId)); }
private PartitionFieldStats(Type type) { this.type = type; this.comparator = Comparators.forType(type.asPrimitiveType()); }
@Test public void testComplexMapKey() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, Types.StructType.of( required(4, "i", Types.IntegerType.get()), optional(5, "s", Types.StringType.get())), Types.StringType.get()))); writeAndValidate(schema); }
/** * Returns a list of compatibility errors for reading with the given read schema. * * @param readSchema a read schema * @param writeSchema a write schema * @return a list of error details, or an empty list if there are no compatibility problems */ public static List<String> readCompatibilityErrors(Schema readSchema, Schema writeSchema) { return TypeUtil.visit(readSchema, new CheckCompatibility(writeSchema, false)); }
@Test public void testComplexMapKey() throws IOException { Schema schema = new Schema( required(0, "id", LongType.get()), optional(1, "data", MapType.ofOptional(2, 3, Types.StructType.of( required(4, "i", Types.IntegerType.get()), optional(5, "s", Types.StringType.get())), Types.StringType.get()))); writeAndValidate(schema); }