public abstract class Schema extends JsonProperties implements Serializable
A schema may be one of:
SchemaBuilder
. The schema objects
are logically immutable. There are only two mutating methods -
setFields(List)
and addProp(String, String)
. The following
restrictions apply on these two methods.
setFields(List)
, can be called at most once. This method exists
in order to enable clients to build recursive schemas.
addProp(String, String)
can be called with property names that
are not present already. It is not possible to change or delete an existing
property.
Modifier and Type | Class and Description |
---|---|
static class |
Schema.Field
A field within a record.
|
static class |
Schema.Parser
A parser for JSON-format schemas.
|
static class |
Schema.SeenPair
Useful as key of
Map s when traversing two schemas at the same time
and need to watch for recursion. |
static class |
Schema.Type
The type of a schema.
|
JsonProperties.Null
NULL_VALUE
Modifier and Type | Method and Description |
---|---|
void |
addAlias(String alias)
If this is a record, enum or fixed, add an alias.
|
void |
addAlias(String alias,
String space)
If this is a record, enum or fixed, add an alias.
|
void |
addProp(String name,
Object value) |
void |
addProp(String name,
String value)
Adds a property with the given name name and value value.
|
static Schema |
applyAliases(Schema writer,
Schema reader)
Rewrite a writer's schema using the aliases from a reader's schema.
|
static Schema |
create(Schema.Type type)
Create a schema for a primitive type.
|
static Schema |
createArray(Schema elementType)
Create an array schema.
|
static Schema |
createEnum(String name,
String doc,
String namespace,
List<String> values)
Create an enum schema.
|
static Schema |
createEnum(String name,
String doc,
String namespace,
List<String> values,
String enumDefault)
Create an enum schema.
|
static Schema |
createFixed(String name,
String doc,
String space,
int size)
Create a union schema.
|
static Schema |
createMap(Schema valueType)
Create a map schema.
|
static Schema |
createRecord(List<Schema.Field> fields)
Deprecated.
This method allows to create Schema objects that cannot be parsed
by
Schema.Parser.parse(String) . It will be removed in a
future version of Avro. Better use
icreateRecord(String, String, String, boolean, List) to
produce a fully qualified Schema. |
static Schema |
createRecord(String name,
String doc,
String namespace,
boolean isError)
Create a named record schema.
|
static Schema |
createRecord(String name,
String doc,
String namespace,
boolean isError,
List<Schema.Field> fields)
Create a named record schema with fields already set.
|
static Schema |
createUnion(List<Schema> types)
Create a union schema.
|
static Schema |
createUnion(Schema... types)
Create a union schema.
|
boolean |
equals(Object o) |
Set<String> |
getAliases()
If this is a record, enum or fixed, return its aliases, if any.
|
String |
getDoc()
If this is a record, enum, or fixed, returns its docstring, if available.
|
Schema |
getElementType()
If this is an array, returns its element type.
|
String |
getEnumDefault()
If this is an enum, return its default value.
|
int |
getEnumOrdinal(String symbol)
If this is an enum, return a symbol's ordinal value.
|
List<String> |
getEnumSymbols()
If this is an enum, return its symbols.
|
Schema.Field |
getField(String fieldname)
If this is a record, returns the Field with the given name
fieldName.
|
List<Schema.Field> |
getFields()
If this is a record, returns the fields in it.
|
int |
getFixedSize()
If this is fixed, returns its size.
|
String |
getFullName()
If this is a record, enum or fixed, returns its namespace-qualified name,
otherwise returns the name of the primitive type.
|
Integer |
getIndexNamed(String name)
If this is a union, return the branch with the provided full name.
|
LogicalType |
getLogicalType() |
String |
getName()
If this is a record, enum or fixed, returns its name, otherwise the name of
the primitive type.
|
String |
getNamespace()
If this is a record, enum or fixed, returns its namespace, if any.
|
Schema.Type |
getType()
Return the type of this schema.
|
List<Schema> |
getTypes()
If this is a union, returns its types.
|
Schema |
getValueType()
If this is a map, returns its value type.
|
boolean |
hasEnumSymbol(String symbol)
If this is an enum, returns true if it contains given symbol.
|
int |
hashCode() |
boolean |
isError()
Returns true if this record is an error type.
|
boolean |
isNullable()
Returns true if this record is an union type containing null.
|
boolean |
isUnion()
Returns true if this record is an union type.
|
static Schema |
parse(File file)
Deprecated.
use
Schema.Parser instead. |
static Schema |
parse(InputStream in)
Deprecated.
use
Schema.Parser instead. |
static Schema |
parse(String jsonSchema)
Deprecated.
use
Schema.Parser instead. |
static Schema |
parse(String jsonSchema,
boolean validate)
Deprecated.
use
Schema.Parser instead. |
static Object |
parseJsonToObject(String s)
Parses the specified json string to an object.
|
void |
setFields(List<Schema.Field> fields)
If this is a record, set its fields.
|
String |
toString()
Render this as JSON.
|
String |
toString(boolean pretty)
Render this as JSON.
|
protected Object |
writeReplace() |
addAllProps, getObjectProp, getObjectProps, getProp, hasProps, putAll
protected Object writeReplace()
public static Schema create(Schema.Type type)
public void addProp(String name, String value)
JsonProperties
addProp
in class JsonProperties
name
- The name of the property to addvalue
- The value for the property to addpublic void addProp(String name, Object value)
addProp
in class JsonProperties
public LogicalType getLogicalType()
@Deprecated public static Schema createRecord(List<Schema.Field> fields)
Schema.Parser.parse(String)
. It will be removed in a
future version of Avro. Better use
icreateRecord(String, String, String, boolean, List)
to
produce a fully qualified Schema.public static Schema createRecord(String name, String doc, String namespace, boolean isError)
public static Schema createRecord(String name, String doc, String namespace, boolean isError, List<Schema.Field> fields)
public static Schema createEnum(String name, String doc, String namespace, List<String> values)
public static Schema createEnum(String name, String doc, String namespace, List<String> values, String enumDefault)
public static Schema createFixed(String name, String doc, String space, int size)
public Schema.Type getType()
public Schema.Field getField(String fieldname)
public List<Schema.Field> getFields()
public void setFields(List<Schema.Field> fields)
public String getEnumDefault()
public int getEnumOrdinal(String symbol)
public boolean hasEnumSymbol(String symbol)
public String getName()
public String getDoc()
public String getNamespace()
public String getFullName()
public void addAlias(String alias)
public void addAlias(String alias, String space)
public Set<String> getAliases()
public boolean isError()
public Schema getElementType()
public Schema getValueType()
public Integer getIndexNamed(String name)
public int getFixedSize()
public String toString(boolean pretty)
pretty
- if true, pretty-print JSON.public boolean isUnion()
public boolean isNullable()
@Deprecated public static Schema parse(File file) throws IOException
Schema.Parser
instead.file
- The file to read the schema from.IOException
- if there was trouble reading the contents or they are
invalid@Deprecated public static Schema parse(InputStream in) throws IOException
Schema.Parser
instead.in
- The input stream to read the schema from.IOException
- if there was trouble reading the contents or they are
invalid@Deprecated public static Schema parse(String jsonSchema)
Schema.Parser
instead.@Deprecated public static Schema parse(String jsonSchema, boolean validate)
Schema.Parser
instead.validate
- true if names should be validated, false if not.public static Object parseJsonToObject(String s)
public static Schema applyAliases(Schema writer, Schema reader)
Copyright © 2009–2020 The Apache Software Foundation. All rights reserved.