public final class Schema extends Object
| 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() |
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.
|
static Schema |
mapOf(Schema keySchema,
Schema valueSchema)
|
static Schema |
of(Schema.Type type)
Creates a
Schema for the given type. |
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 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 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 SchemaHash getSchemaHash()
public boolean isCompatible(Schema target)
target - Schema to check for compatibility to this targettrue if the schemas are compatible, false otherwise.Copyright © 2019 CDAP Licensed under the Apache License, Version 2.0.