public interface Schema
Definition of an abstract data type. Data types can be primitive types (integer types, floating point types, boolean, strings, and bytes) or complex types (typed arrays, maps with one key schema and value schema, and structs that have a fixed set of field names each with an associated value schema). Any type can be specified as optional, allowing it to be omitted (resulting in null values when it is missing) and can specify a default value.
All schemas may have some associated metadata: a name, version, and documentation. These are all considered part of the schema itself and included when comparing schemas. Besides adding important metadata, these fields enable the specification of logical types that specify additional constraints and semantics (e.g. UNIX timestamps are just an int64, but the user needs the know about the additional semantics to interpret it properly).
Schemas can be created directly, but in most cases using SchemaBuilder
will be simpler.
Modifier and Type | Interface and Description |
---|---|
static class |
Schema.Type
The type of a schema.
|
Modifier and Type | Field and Description |
---|---|
static Schema |
BOOLEAN_SCHEMA |
static Schema |
BYTES_SCHEMA |
static Schema |
FLOAT32_SCHEMA |
static Schema |
FLOAT64_SCHEMA |
static Schema |
INT16_SCHEMA |
static Schema |
INT32_SCHEMA |
static Schema |
INT64_SCHEMA |
static Schema |
INT8_SCHEMA |
static Schema |
OPTIONAL_BOOLEAN_SCHEMA |
static Schema |
OPTIONAL_BYTES_SCHEMA |
static Schema |
OPTIONAL_FLOAT32_SCHEMA |
static Schema |
OPTIONAL_FLOAT64_SCHEMA |
static Schema |
OPTIONAL_INT16_SCHEMA |
static Schema |
OPTIONAL_INT32_SCHEMA |
static Schema |
OPTIONAL_INT64_SCHEMA |
static Schema |
OPTIONAL_INT8_SCHEMA |
static Schema |
OPTIONAL_STRING_SCHEMA |
static Schema |
STRING_SCHEMA |
Modifier and Type | Method and Description |
---|---|
Object |
defaultValue() |
String |
doc() |
Field |
field(String fieldName)
Get a
Field for this Schema by name. |
List<Field> |
fields()
Get the list of Fields for this Schema.
|
boolean |
isOptional() |
Schema |
keySchema()
Get the key schema for this map schema.
|
String |
name() |
Map<String,String> |
parameters()
Get a map of schema parameters.
|
Schema |
schema()
Return a concrete instance of the
Schema |
Schema.Type |
type() |
Schema |
valueSchema()
Get the value schema for this map or array schema.
|
Integer |
version()
Get the optional version of the schema.
|
static final Schema INT8_SCHEMA
static final Schema INT16_SCHEMA
static final Schema INT32_SCHEMA
static final Schema INT64_SCHEMA
static final Schema FLOAT32_SCHEMA
static final Schema FLOAT64_SCHEMA
static final Schema BOOLEAN_SCHEMA
static final Schema STRING_SCHEMA
static final Schema BYTES_SCHEMA
static final Schema OPTIONAL_INT8_SCHEMA
static final Schema OPTIONAL_INT16_SCHEMA
static final Schema OPTIONAL_INT32_SCHEMA
static final Schema OPTIONAL_INT64_SCHEMA
static final Schema OPTIONAL_FLOAT32_SCHEMA
static final Schema OPTIONAL_FLOAT64_SCHEMA
static final Schema OPTIONAL_BOOLEAN_SCHEMA
static final Schema OPTIONAL_STRING_SCHEMA
static final Schema OPTIONAL_BYTES_SCHEMA
Schema.Type type()
boolean isOptional()
Object defaultValue()
String name()
Integer version()
String doc()
Map<String,String> parameters()
Schema keySchema()
DataException
if this schema is not a map.Schema valueSchema()
DataException
if this schema is not a map or array.List<Field> fields()
DataException
if this schema is not a
Schema.Type.STRUCT
.Field field(String fieldName)
Field
for this Schema by name. Throws a DataException
if this schema is not a
Schema.Type.STRUCT
.fieldName
- the name of the field to look up