Class SchemaRegistry
SchemaRegistry allows registering Schemas for a given Java Class or a
TypeDescriptor.
Types registered in a pipeline's schema registry will automatically be discovered by any
PCollection that uses SchemaCoder. This allows users
to write pipelines in terms of their own Java types, yet still register schemas for these types.
TODO: Provide support for schemas registered via a ServiceLoader interface. This will allow optional modules to register schemas as well.
-
Method Summary
Modifier and TypeMethodDescriptionstatic SchemaRegistry<T> SerializableFunction<Row, T> getFromRowFunction(Class<T> clazz) Retrieve the function that converts aRowobject to the specified type.<T> SerializableFunction<Row, T> getFromRowFunction(TypeDescriptor<T> typeDescriptor) Retrieve the function that converts aRowobject to the specified type.<T> Schema<T> SchemagetSchema(TypeDescriptor<T> typeDescriptor) Retrieve aSchemafor a givenTypeDescriptortype.<T> SchemaCoder<T> getSchemaCoder(Class<T> clazz) Retrieve aSchemaCoderfor a givenClasstype.<T> SchemaCoder<T> getSchemaCoder(TypeDescriptor<T> typeDescriptor) Retrieve aSchemaCoderfor a givenTypeDescriptortype.<T> SchemaProvidergetSchemaProvider(Class<T> clazz) Retrieve a registeredSchemaProviderfor a givenClass.<T> SchemaProvidergetSchemaProvider(TypeDescriptor<T> typeDescriptor) Retrieve a registeredSchemaProviderfor a givenTypeDescriptor.<T> SerializableFunction<T, Row> getToRowFunction(Class<T> clazz) Retrieve the function that converts an object of the specified type to aRowobject.<T> SerializableFunction<T, Row> getToRowFunction(TypeDescriptor<T> typeDescriptor) Retrieve the function that converts an object of the specified type to aRowobject.<T> voidregisterJavaBean(Class<T> clazz) Register a JavaBean type for automatic schema inference.<T> voidregisterJavaBean(TypeDescriptor<T> typeDescriptor) Register a JavaBean type for automatic schema inference.<T> voidregisterPOJO(Class<T> clazz) Register a POJO type for automatic schema inference.<T> voidregisterPOJO(TypeDescriptor<T> typeDescriptor) Register a POJO type for automatic schema inference.<T> voidregisterSchemaForClass(Class<T> clazz, Schema schema, SerializableFunction<T, Row> toRow, SerializableFunction<Row, T> fromRow) Register a schema for a specificClasstype.<T> voidregisterSchemaForType(TypeDescriptor<T> type, Schema schema, SerializableFunction<T, Row> toRow, SerializableFunction<Row, T> fromRow) Register a schema for a specificTypeDescriptortype.<T> voidregisterSchemaProvider(Class<T> clazz, SchemaProvider schemaProvider) Register aSchemaProviderto be used for a specific type.voidregisterSchemaProvider(SchemaProvider schemaProvider) Register aSchemaProvider.<T> voidregisterSchemaProvider(TypeDescriptor<T> typeDescriptor, SchemaProvider schemaProvider) Register aSchemaProviderto be used for a specific type.
-
Method Details
-
createDefault
-
registerSchemaForClass
public <T> void registerSchemaForClass(Class<T> clazz, Schema schema, SerializableFunction<T, Row> toRow, SerializableFunction<Row, T> fromRow) Register a schema for a specificClasstype. -
registerSchemaForType
public <T> void registerSchemaForType(TypeDescriptor<T> type, Schema schema, SerializableFunction<T, Row> toRow, SerializableFunction<Row, T> fromRow) Register a schema for a specificTypeDescriptortype. -
registerSchemaProvider
Register aSchemaProvider.A
SchemaProviderallows for deferred lookups of per-type schemas. This can be used when schemas are registered in an external service. The SchemaProvider will lookup the type in the external service and return the correctSchema. -
registerSchemaProvider
Register aSchemaProviderto be used for a specific type. * -
registerSchemaProvider
public <T> void registerSchemaProvider(TypeDescriptor<T> typeDescriptor, SchemaProvider schemaProvider) Register aSchemaProviderto be used for a specific type. * -
registerPOJO
Register a POJO type for automatic schema inference.Currently schema field names will match field names in the POJO, and all fields must be mutable (i.e. no final fields).
-
registerPOJO
Register a POJO type for automatic schema inference.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.
-
registerJavaBean
Register a JavaBean type for automatic schema inference.Currently schema field names will match getter names in the bean, and all getters must have matching setters. 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.
-
registerJavaBean
Register a JavaBean type for automatic schema inference.Currently schema field names will match getter names in the bean, and all getters must have matching setters.
-
getSchema
- Throws:
NoSuchSchemaException
-
getSchema
Retrieve aSchemafor a givenTypeDescriptortype. If no schema exists, throwsNoSuchSchemaException.- Throws:
NoSuchSchemaException
-
getToRowFunction
public <T> SerializableFunction<T,Row> getToRowFunction(Class<T> clazz) throws NoSuchSchemaException Retrieve the function that converts an object of the specified type to aRowobject.- Throws:
NoSuchSchemaException
-
getToRowFunction
public <T> SerializableFunction<T,Row> getToRowFunction(TypeDescriptor<T> typeDescriptor) throws NoSuchSchemaException Retrieve the function that converts an object of the specified type to aRowobject.- Throws:
NoSuchSchemaException
-
getFromRowFunction
public <T> SerializableFunction<Row,T> getFromRowFunction(Class<T> clazz) throws NoSuchSchemaException Retrieve the function that converts aRowobject to the specified type.- Throws:
NoSuchSchemaException
-
getFromRowFunction
public <T> SerializableFunction<Row,T> getFromRowFunction(TypeDescriptor<T> typeDescriptor) throws NoSuchSchemaException Retrieve the function that converts aRowobject to the specified type.- Throws:
NoSuchSchemaException
-
getSchemaCoder
Retrieve aSchemaCoderfor a givenClasstype. If no schema exists, throwsNoSuchSchemaException}.invalid @link
{@link *- Throws:
NoSuchSchemaException
-
getSchemaCoder
public <T> SchemaCoder<T> getSchemaCoder(TypeDescriptor<T> typeDescriptor) throws NoSuchSchemaException Retrieve aSchemaCoderfor a givenTypeDescriptortype. If no schema exists, throwsNoSuchSchemaException}.invalid @link
{@link *- Throws:
NoSuchSchemaException
-
getSchemaProvider
public <T> SchemaProvider getSchemaProvider(TypeDescriptor<T> typeDescriptor) throws NoSuchSchemaException Retrieve a registeredSchemaProviderfor a givenTypeDescriptor. If no schema exists, throwsNoSuchSchemaException}.invalid @link
{@link *- Throws:
NoSuchSchemaException
-
getSchemaProvider
Retrieve a registeredSchemaProviderfor a givenClass. If no schema exists, throwsNoSuchSchemaException}.invalid @link
{@link *- Throws:
NoSuchSchemaException
-