public class SchemaUtil extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
SchemaUtil.SchemaVisitor<T> |
| Constructor and Description |
|---|
SchemaUtil() |
| Modifier and Type | Method and Description |
|---|---|
static void |
checkPartitionedBy(DatasetDescriptor descriptor,
String fieldName) |
static void |
checkTypeConsistency(Schema schema,
PartitionStrategy strategy,
String fieldName,
Object... values)
Checks that the type of each of
values is consistent with the type of
field fieldName declared in the Avro schema (from descriptor). |
static void |
checkTypeConsistency(Schema schema,
String fieldName,
Object... values)
Checks that the type of each of
values is consistent with the type of
field fieldName declared in the Avro schema (from descriptor). |
static Schema.Field |
copy(Schema.Field field)
Creates a new field with the same name, schema, doc, and default value as
the incoming schema.
|
static Schema |
fieldSchema(Schema schema,
PartitionStrategy strategy,
String name)
Returns a
Schema for the given field name, which could be either a
schema field or a partition field. |
static Schema |
fieldSchema(Schema schema,
String name)
Returns the nested
Schema for the given field name. |
static <T> T |
fromString(String value,
Schema schema) |
static Class<?> |
getClassForType(Schema.Type type) |
static <S,T> Class<? extends T> |
getPartitionType(FieldPartitioner<S,T> fp,
Schema schema) |
static <S> Class<? extends S> |
getSourceType(FieldPartitioner<S,?> fp,
Schema schema) |
static boolean |
isConsistentWithExpectedType(Schema.Type type,
Class<?> expectedClass)
Checks that a schema type should produce an object of the expected class.
|
static boolean |
isConsistentWithMappingType(Schema.Type type,
FieldMapping.MappingType mappingType) |
static boolean |
isField(Schema schema,
PartitionStrategy strategy,
String name)
Return whether there is a field named
name in the schema or
partition strategy. |
static Schema |
keySchema(Schema schema,
PartitionStrategy strategy)
|
static Schema |
merge(Iterable<Schema> schemas)
Merges
Schema instances if they are compatible. |
static Schema |
merge(Schema left,
Schema right)
Merges two
Schema instances if they are compatible. |
static Schema |
mergeOrUnion(Iterable<Schema> schemas)
Merges
Schema instances and creates a union of schemas if any are
incompatible. |
static boolean |
nullOk(Schema schema)
Returns whether null is allowed by the schema.
|
static Schema |
partitionFieldSchema(FieldPartitioner<?,?> fp,
Schema schema)
Builds a Schema for the FieldPartitioner using the given Schema to
determine types not fixed by the FieldPartitioner.
|
static String |
toString(Object value,
Schema schema) |
static <T> T |
visit(Schema schema,
SchemaUtil.SchemaVisitor<T> visitor) |
public static Class<?> getClassForType(Schema.Type type)
public static <S> Class<? extends S> getSourceType(FieldPartitioner<S,?> fp, Schema schema)
public static <S,T> Class<? extends T> getPartitionType(FieldPartitioner<S,T> fp, Schema schema)
public static boolean isConsistentWithExpectedType(Schema.Type type, Class<?> expectedClass)
Class.isAssignableFrom(Class).type - an avro Schema.TypeexpectedClass - a java classtrue if the type produces objects assignable to the class,
false if the class is not assignable from the avro type.public static boolean isConsistentWithMappingType(Schema.Type type, FieldMapping.MappingType mappingType)
public static void checkTypeConsistency(Schema schema, String fieldName, Object... values)
values is consistent with the type of
field fieldName declared in the Avro schema (from descriptor).public static void checkTypeConsistency(Schema schema, PartitionStrategy strategy, String fieldName, Object... values)
values is consistent with the type of
field fieldName declared in the Avro schema (from descriptor).public static Schema partitionFieldSchema(FieldPartitioner<?,?> fp, Schema schema)
fp - a FieldPartitionerschema - an entity Schema that will be partitionedpublic static boolean isField(Schema schema, PartitionStrategy strategy, String name)
name in the schema or
partition strategy.schema - a Schemastrategy - a PartitionStrategyname - a String field nametrue if name identifies a fieldpublic static Schema fieldSchema(Schema schema, PartitionStrategy strategy, String name)
Schema for the given field name, which could be either a
schema field or a partition field.schema - an entity Schema that will be partitionedstrategy - a PartitionStrategy used to partition entitiesname - a schema or partition field namepublic static Schema fieldSchema(Schema schema, String name)
Schema for the given field name.schema - a record Schemaname - a String field namepublic static Schema keySchema(Schema schema, PartitionStrategy strategy)
Schema for the keys of a PartitionStrategy based
on an entity Schema.
The partition strategy and schema are assumed to be compatible and this will result in NullPointerExceptions if they are not.
schema - an entity schema Schemastrategy - a PartitionStrategySchema for the storage keys of the partition strategypublic static void checkPartitionedBy(DatasetDescriptor descriptor, String fieldName)
public static <T> T visit(Schema schema, SchemaUtil.SchemaVisitor<T> visitor)
public static Schema merge(Iterable<Schema> schemas)
Schema instances if they are compatible.
Schemas are incompatible if:
Schema.Type does not match.Map value, array element, and record field types types will use unions if necessary, and union schemas are merged recursively.
schemas - a set of Schema instances to mergeSchemaIncompatibleSchemaException - if the schemas are not compatiblepublic static Schema mergeOrUnion(Iterable<Schema> schemas)
Schema instances and creates a union of schemas if any are
incompatible.
Schemas are incompatible if:
Schema.Type does not match.Map value, array element, and record field types types will use unions if necessary, and union schemas are merged recursively.
schemas - a set of Schema instances to mergeSchemapublic static Schema merge(Schema left, Schema right)
Schema instances if they are compatible.
Two schemas are incompatible if:
Schema.Type does not match.Map value and array element types will use unions if necessary, and union schemas are merged recursively.
left - a Schemaright - a SchemaSchemaIncompatibleSchemaException - if the schemas are not compatiblepublic static Schema.Field copy(Schema.Field field)
Fields cannot be used in more than one record (not Immutable?).
public static boolean nullOk(Schema schema)
schema - a SchemaCopyright © 2013–2015. All rights reserved.