| Modifier and Type | Class and Description |
|---|---|
static class |
Schema.Field
Represents a field inside a
Schema.Type.RECORD schema. |
static class |
Schema.Type
Types known to Schema.
|
| Modifier and Type | Method and Description |
|---|---|
static Schema |
arrayOf(Schema componentSchema)
|
static Schema |
enumWith(Class<Enum<?>> enumClass)
|
static Schema |
enumWith(Iterable<String> values)
|
static Schema |
enumWith(String... values)
|
boolean |
equals(Object other) |
Schema |
getComponentSchema() |
int |
getEnumIndex(String value) |
String |
getEnumValue(int idx) |
Set<String> |
getEnumValues() |
Schema.Field |
getField(String name)
Returns the record
Schema.Field of the given name. |
List<Schema.Field> |
getFields() |
Map.Entry<Schema,Schema> |
getMapSchema() |
Schema |
getNonNullable()
Assuming this is a union of a null and one non-null type, return the non-null schema.
|
String |
getRecordName() |
SchemaHash |
getSchemaHash() |
Schema.Type |
getType() |
Schema |
getUnionSchema(int idx) |
List<Schema> |
getUnionSchemas() |
int |
hashCode() |
boolean |
isCompatible(Schema target)
Checks if the given target schema is compatible with this schema, meaning datum being written with this
schema could be projected correctly into the given target schema.
|
boolean |
isNullable()
Check if this is a nullable type, which is a union of a null and one other non-null type.
|
boolean |
isNullableSimple()
Check if this is a nullable simple type, which is a union of a null and one other non-null simple type, where
a simple type is a boolean, int, long, float, double, bytes, or string type.
|
boolean |
isSimpleOrNullableSimple()
Check if this is a simple type or a nullable simple type, which is a union of a null and one other non-null
simple type, where a simple type is a boolean, int, long, float, double, bytes, or string type.
|
static Schema |
mapOf(Schema keySchema,
Schema valueSchema)
|
static Schema |
nullableOf(Schema schema)
Creates a nullable
Schema for the given schema, which is a union of the given schema with the null type. |
static Schema |
of(Schema.Type type)
Creates a
Schema for the given type. |
static Schema |
parseJson(Reader reader)
Parse the given json representation of a schema object contained in a reader into a schema object.
|
static Schema |
parseJson(String schemaJson)
Parse the given JSON representation, as returned by
toString() into a Schema object. |
static Schema |
parseSQL(String schemaString)
Parse the given sql-like schema representation into a schema object.
|
static Schema |
recordOf(String name)
|
static Schema |
recordOf(String name,
Iterable<Schema.Field> fields)
|
static Schema |
recordOf(String name,
Schema.Field... fields)
|
String |
toString() |
static Schema |
unionOf(Iterable<Schema> schemas)
|
static Schema |
unionOf(Schema... schemas)
|
public static Schema parseJson(String schemaJson) throws IOException
toString() into a Schema object.schemaJson - the json representation of the schemaIOException - if there was an exception parsing the schemapublic static Schema parseJson(Reader reader) throws IOException
reader - the reader for reading the json representation of a schemaIOException - if there was an exception parsing the schemapublic static Schema parseSQL(String schemaString) throws IOException
column_name data_type, ...
data_type : primitive_type
| array_type
| map_type
| record_type
| union_type
[ not null ]
primitive_type: boolean
| int
| long
| float
| double
| bytes
| string
array_type: array<data_type>
map_type: map<data_type, data_type>
record_type: record<field_name:data_type, ...>
union_type: union<data_type, data_type, ...>
schemaString - the schema to parseIOException - if there was an exception parsing the schemapublic static Schema of(Schema.Type type)
Schema for the given type. The type given must be a
Simple Type.type - Type of the schema to create.Schema with the given type.public static Schema nullableOf(Schema schema)
Schema for the given schema, which is a union of the given schema with the null type.
The type given must not be the null type.schema - Schema to union with the null type.Schema.public static Schema enumWith(Iterable<String> values)
Schema of ENUM type, with the given enum values.
The set of values given should be unique and must contains at least one value.
The ordering of values in the enum type schema would be the same as the Iterable.iterator() order.public static Schema enumWith(Class<Enum<?>> enumClass)
Schema of ENUM type, with values extracted from the given Enum class.
The ordering of values in the enum type schema would be the same as the Enum.ordinal() order.public static Schema recordOf(String name, Schema.Field... fields)
public static Schema recordOf(String name, Iterable<Schema.Field> fields)
RECORD Schema with the given name and Fields.
The ordering of the fields inside the record would be the same as the Iterable.iterator() order.public static Schema unionOf(Iterable<Schema> schemas)
UNION Schema which represents a union of all the given schemas.
The ordering of the schemas inside the union would be the same as the Iterable.iterator() order.public Schema.Type getType()
Schema.Type that this schema represents.public Set<String> getEnumValues()
Set of enum values or null if this is not a ENUM schema.
The Set.iterator() order would be the enum values orders.public int getEnumIndex(String value)
value - The enum value-1 if this is not a
ENUM schema.public String getEnumValue(int idx)
idx - The index in the enum valuesnull if this is not a ENUM schema or
the given index is invalid.public Schema getComponentSchema()
null if this is not a ARRAY schema.public Map.Entry<Schema,Schema> getMapSchema()
Map.Entry if this is a Type#MAP MAP schema or null otherwise.
The Map.Entry#getKey() would returns the key schema, while Map.Entry#getValue()
would returns the value schema.public String getRecordName()
RECORD schema or null otherwise.public List<Schema.Field> getFields()
public Schema.Field getField(String name)
Schema.Field of the given name.name - Name of the fieldSchema.Field or null if there is no such field in this record
or this is not a RECORD schema.public Schema getUnionSchema(int idx)
public String toString()
toString in class ObjectparseJson(java.lang.String)public SchemaHash getSchemaHash()
public boolean isCompatible(Schema target)
target - Schema to check for compatibility to this targettrue if the schemas are compatible, false otherwise.public boolean isNullable()
public boolean isNullableSimple()
public boolean isSimpleOrNullableSimple()
public Schema getNonNullable()
Copyright © 2016 Cask Data, Inc. Licensed under the Apache License, Version 2.0.