@Experimental(value=SCHEMAS) public class SchemaRegistry extends java.lang.Object
SchemaRegistry
allows registering Schema
s 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.
Modifier and Type | Method and Description |
---|---|
static SchemaRegistry |
createDefault() |
<T> SerializableFunction<Row,T> |
getFromRowFunction(java.lang.Class<T> clazz)
Rerieve the function that converts a
Row object to an object of the specified type. |
<T> SerializableFunction<Row,T> |
getFromRowFunction(TypeDescriptor<T> typeDescriptor)
Rerieve the function that converts a
Row object to an object of the specified type. |
<T> Schema |
getSchema(java.lang.Class<T> clazz)
Get a schema for a given
Class type. |
<T> Schema |
getSchema(TypeDescriptor<T> typeDescriptor)
Retrieve a schema for a given
TypeDescriptor type. |
<T> SerializableFunction<T,Row> |
getToRowFunction(java.lang.Class<T> clazz)
Rerieve the function that converts an object of the specified type to a
Row object. |
<T> SerializableFunction<T,Row> |
getToRowFunction(TypeDescriptor<T> typeDescriptor)
Rerieve the function that converts an object of the specified type to a
Row object. |
<T> void |
registerSchemaForClass(java.lang.Class<T> clazz,
Schema schema,
SerializableFunction<T,Row> toRow,
SerializableFunction<Row,T> fromRow)
Register a schema for a specific
Class type. |
<T> void |
registerSchemaForType(TypeDescriptor<T> type,
Schema schema,
SerializableFunction<T,Row> toRow,
SerializableFunction<Row,T> fromRow)
Register a schema for a specific
TypeDescriptor type. |
void |
registerSchemaProvider(SchemaProvider schemaProvider)
Register a
SchemaProvider . |
public static SchemaRegistry createDefault()
public <T> void registerSchemaForClass(java.lang.Class<T> clazz, Schema schema, SerializableFunction<T,Row> toRow, SerializableFunction<Row,T> fromRow)
Class
type.public <T> void registerSchemaForType(TypeDescriptor<T> type, Schema schema, SerializableFunction<T,Row> toRow, SerializableFunction<Row,T> fromRow)
TypeDescriptor
type.public void registerSchemaProvider(SchemaProvider schemaProvider)
SchemaProvider
.
A SchemaProvider
allows 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 correct Schema
.
public <T> Schema getSchema(java.lang.Class<T> clazz) throws NoSuchSchemaException
Class
type. If no schema exists, throws NoSuchSchemaException
.NoSuchSchemaException
public <T> Schema getSchema(TypeDescriptor<T> typeDescriptor) throws NoSuchSchemaException
TypeDescriptor
type. If no schema exists, throws NoSuchSchemaException
.NoSuchSchemaException
public <T> SerializableFunction<T,Row> getToRowFunction(java.lang.Class<T> clazz) throws NoSuchSchemaException
Row
object.NoSuchSchemaException
public <T> SerializableFunction<T,Row> getToRowFunction(TypeDescriptor<T> typeDescriptor) throws NoSuchSchemaException
Row
object.NoSuchSchemaException
public <T> SerializableFunction<Row,T> getFromRowFunction(java.lang.Class<T> clazz) throws NoSuchSchemaException
Row
object to an object of the specified type.NoSuchSchemaException
public <T> SerializableFunction<Row,T> getFromRowFunction(TypeDescriptor<T> typeDescriptor) throws NoSuchSchemaException
Row
object to an object of the specified type.NoSuchSchemaException