/** Return's a field with the give name and type. */ public static Field of(String name, FieldType fieldType) { return new AutoValue_Schema_Field.Builder() .setName(name) .setDescription("") .setType(fieldType) .setNullable(false) // By default fields are not nullable. .build(); }
public static final FieldType array(FieldType elementType, boolean nullable) { return FieldType.forTypeName(TypeName.ARRAY) .setCollectionElementType(elementType) .setCollectionElementTypeNullable(nullable) .build(); }
public static final FieldType map( FieldType keyType, FieldType valueType, boolean valueTypeNullable) { return FieldType.forTypeName(TypeName.MAP) .setMapKeyType(keyType) .setMapValueType(valueType) .setMapValueTypeNullable(valueTypeNullable) .build(); }
@Test public void testRegisterProvider() throws NoSuchSchemaException { SchemaRegistry registry = SchemaRegistry.createDefault(); registry.registerSchemaProvider(new Provider()); tryGetters(registry); }
/** * Register a POJO type for automatic schema inference. * * <p>Currently schema field names will match field names in the POJO, and all fields must be * mutable (i.e. no final fields). The Java object is expected to have implemented a correct * .equals() and .hashCode methods The equals method must be completely determined by the schema * fields. i.e. if the object has hidden fields that are not reflected in the schema but are * compared in equals, then results will be incorrect. */ public <T> void registerPOJO(TypeDescriptor<T> typeDescriptor) { registerSchemaProvider(typeDescriptor, new JavaFieldSchema()); }
/** * Register a JavaBean type for automatic schema inference. * * <p>Currently schema field names will match getter names in the bean, and all getters must have * matching setters. */ public <T> void registerJavaBean(TypeDescriptor<T> typeDescriptor) { registerSchemaProvider(typeDescriptor, new JavaBeanSchema()); }
/** * By default, fields are sorted by name. If this is set, they will instead be sorted by insertion * order. All sorting happens in the {@link #resolve(Schema)} method. */ public FieldAccessDescriptor withOrderByFieldInsertionOrder() { return toBuilder().setFieldInsertionOrder(true).build(); }
/** Create a map type for the given key and value types. */ public static final FieldType row(Schema schema) { return FieldType.forTypeName(TypeName.ROW).setRowSchema(schema).build(); }
/** Returns a copy of the Field with the description set. */ public Field withDescription(String description) { return toBuilder().setDescription(description).build(); }
/** Returns a copy of the Field with isNullable set. */ public Field withNullable(boolean isNullable) { return toBuilder().setNullable(isNullable).build(); }
/** * Given a type, return a function that converts that type to a {@link Row} object If no schema * exists, returns null. */ @Override public <T> SerializableFunction<T, Row> toRowFunction(TypeDescriptor<T> typeDescriptor) { SchemaProvider schemaProvider = getSchemaProvider(typeDescriptor); return (schemaProvider != null) ? schemaProvider.toRowFunction(typeDescriptor) : null; }
/** * Given a type, returns a function that converts from a {@link Row} object to that type. If no * schema exists, returns null. */ @Override public <T> SerializableFunction<Row, T> fromRowFunction(TypeDescriptor<T> typeDescriptor) { SchemaProvider schemaProvider = getSchemaProvider(typeDescriptor); return (schemaProvider != null) ? schemaProvider.fromRowFunction(typeDescriptor) : null; } }
@Override public <T> Schema schemaFor(TypeDescriptor<T> typeDescriptor) { SchemaProvider schemaProvider = getSchemaProvider(typeDescriptor); return (schemaProvider != null) ? schemaProvider.schemaFor(typeDescriptor) : null; }
/** Return's a nullable field with the give name and type. */ public static Field nullable(String name, FieldType fieldType) { return new AutoValue_Schema_Field.Builder() .setName(name) .setDescription("") .setType(fieldType) .setNullable(true) .build(); }
/** Create a map type for the given key and value types. */ public static final FieldType map(FieldType keyType, FieldType valueType) { return FieldType.forTypeName(TypeName.MAP) .setMapKeyType(keyType) .setMapValueType(valueType) .setMapValueTypeNullable(false) .build(); }
/** Create an array type for the given field type. */ public static final FieldType array(FieldType elementType) { return FieldType.forTypeName(TypeName.ARRAY) .setCollectionElementType(elementType) .setCollectionElementTypeNullable(false) .build(); }