public class DataModelUtil extends Object
| Constructor and Description |
|---|
DataModelUtil() |
| Modifier and Type | Method and Description |
|---|---|
static <E> EntityAccessor<E> |
accessor(Class<E> type,
Schema schema) |
static <E> E |
createRecord(Class<E> type,
Schema schema)
If E implements GenericRecord, but does not implement SpecificRecord, then
create a new instance of E using reflection so that GenericDataumReader
will use the expected type.
|
static <E> GenericData |
getDataModelForType(Class<E> type)
Get the data model for the given type.
|
static <E> DatumReader<E> |
getDatumReaderForType(Class<E> type,
Schema writerSchema)
Get the DatumReader for the given type.
|
static <E> Schema |
getReaderSchema(Class<E> type,
Schema schema)
Get the reader schema based on the given type and writer schema.
|
static <E> Schema |
getWriterSchema(Class<E> type,
Schema schema)
Get the writer schema based on the given type and dataset schema.
|
static boolean |
isGeneric(Class<?> type)
Test whether the class is a generic
GenericRecord and not a
SpecificRecord. |
static <E> Class<E> |
resolveType(Class<E> type,
Schema schema)
Resolves the type based on the given schema.
|
public static <E> GenericData getDataModelForType(Class<E> type)
E - The entity typetype - The Java class of the entity typepublic static boolean isGeneric(Class<?> type)
GenericRecord and not a
SpecificRecord. This is necessary instead of testing if
GenericRecord is assignable from the class because
SpecificRecordBase implements
GenericRecord.type - a Java classpublic static <E> DatumReader<E> getDatumReaderForType(Class<E> type, Schema writerSchema)
E - The entity typetype - The Java class of the entity typewriterSchema - The Schema for entitiespublic static <E> Class<E> resolveType(Class<E> type, Schema schema)
E - The entity typetype - The Java class of the entity typeschema - The Schema for the entitypublic static <E> Schema getReaderSchema(Class<E> type, Schema schema)
E - The entity typetype - The Java class of the entity typeschema - The Schema for the entitypublic static <E> Schema getWriterSchema(Class<E> type, Schema schema)
E - The entity typetype - The Java class of the entity typeschema - The Schema for the entitypublic static <E> E createRecord(Class<E> type, Schema schema)
Schema parameter
in the constructor should implement SpecificData.SchemaConstructable.
Otherwise, your implementation must have a no-args constructor.E - The entity typetype - The Java class of the entity typeschema - The reader schemapublic static <E> EntityAccessor<E> accessor(Class<E> type, Schema schema)
Copyright © 2013–2015. All rights reserved.