Top Description Inners Fields Constructors Methods
org.apache.avro

public abstract Class Schema

extends JsonProperties
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Known Direct Subclasses
org.apache.avro.Schema.NamedSchema, org.apache.avro.Schema.ArraySchema, org.apache.avro.Schema.MapSchema, org.apache.avro.Schema.UnionSchema, org.apache.avro.Schema.StringSchema, org.apache.avro.Schema.BytesSchema, org.apache.avro.Schema.IntSchema, org.apache.avro.Schema.LongSchema, org.apache.avro.Schema.FloatSchema, org.apache.avro.Schema.DoubleSchema, org.apache.avro.Schema.BooleanSchema, org.apache.avro.Schema.NullSchema
Imports
com.fasterxml.jackson.core.JsonFactory, .JsonGenerator, .JsonParseException, .JsonParser, com.fasterxml.jackson.databind.JsonNode, .ObjectMapper, com.fasterxml.jackson.databind.node.DoubleNode, .NullNode, java.io.ByteArrayOutputStream, .File, .IOException, .InputStream, .Serializable, .StringWriter, java.nio.charset.StandardCharsets, java.util.ArrayList, .Arrays, .Collection, .Collections, .HashMap, .HashSet, .IdentityHashMap, .Iterator, .LinkedHashMap, .LinkedHashSet, .List, .Locale, .Map, .Objects, .Set, org.apache.avro.util.internal.Accessor, .Accessor.FieldAccessor, .JacksonUtils, .ThreadLocalWithInitial, org.slf4j.Logger, .LoggerFactory

An abstract data type.

A schema may be one of:

A schema can be constructed using one of its static createXXX methods, or more conveniently using 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.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class
private static class
private static class
private static class
public static class
Schema.Field

A field within a record.

private static class
private static class
private static class
pack-priv static class
Schema.LockableArrayList<E>

No change is permitted on LockableArrayList once lock() has been called on it.

private static class
private static class
pack-priv static class
private abstract static class
pack-priv static class
private static class
public static class
Schema.Parser

A parser for JSON-format schemas.

private static class
public static class
Schema.SeenPair

Useful as key of Maps when traversing two schemas at the same time and need to watch for recursion.

private static class
private static class
public static enum
Schema.Type

The type of a schema.

private static class

Field Summary

Modifier and TypeField and Description
private static final Set<String>
pack-priv static final JsonFactory
private static final Set<String>
pack-priv int
pack-priv static final Logger
private LogicalType
pack-priv static final ObjectMapper
private static final int
pack-priv static final Map<String, Schema.Type>
private static final Set<String>
private static final ThreadLocal<Set<E>>
private static final ThreadLocal<Map<K, V>>
private static final long
private final Schema.Type
private static final ThreadLocal<Boolean>
private static ThreadLocal<Boolean>
Inherited from org.apache.avro.JsonProperties:
NULL_VALUE

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
addAlias(String alias)

If this is a record, enum or fixed, add an alias.

public void
addAlias(String alias, String space)

If this is a record, enum or fixed, add an alias.

public void
addProp(String
The name of the property to add
name
,
String
The value for the property to add
value
)

Overrides org.apache.avro.JsonProperties.addProp.

Adds a property with the given name name and value value.
public void
public static Schema
applyAliases(Schema writer, Schema reader)

Rewrite a writer's schema using the aliases from a reader's schema.

private static Schema
applyAliases(Schema s, Map<Schema, Schema> seen, Map<Schema.Name, Schema.Name> aliases, Map<Schema.Name, Map<String, String>> fieldAliases)

pack-priv int
public static Schema
create(Schema.Type type)

Create a schema for a primitive type.

public static Schema
createArray(Schema elementType)

Create an array schema.

public static Schema
createEnum(String name, String doc, String namespace, List<String> values)

Create an enum schema.

public static Schema
createEnum(String name, String doc, String namespace, List<String> values, String enumDefault)

Create an enum schema.

public static Schema
createFixed(String name, String doc, String space, int size)

Create a fixed schema.

public static Schema
createMap(Schema valueType)

Create a map schema.

public static Schema
createRecord(List<Schema.Field> fields)

Deprecated This method allows to create Schema objects that cannot be parsed by Schema.Parser#parse(String).
Create an anonymous record schema.
public static Schema
createRecord(String name, String doc, String namespace, boolean isError)

Create a named record schema.

public static Schema
createRecord(String name, String doc, String namespace, boolean isError, List<Schema.Field> fields)

Create a named record schema with fields already set.

public static Schema
createUnion(List<Schema> types)

Create a union schema.

public static Schema
createUnion(Schema... types)

Create a union schema.

pack-priv final boolean
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
pack-priv void
public Set<String>
getAliases()

If this is a record, enum or fixed, return its aliases, if any.

private static void
getAliases(Schema schema, Map<Schema, Schema> seen, Map<Schema.Name, Schema.Name> aliases, Map<Schema.Name, Map<String, String>> fieldAliases)

public String
getDoc()

If this is a record, enum, or fixed, returns its docstring, if available.

public Schema
getElementType()

If this is an array, returns its element type.

public String
getEnumDefault()

If this is an enum, return its default value.

public int
getEnumOrdinal(String symbol)

If this is an enum, return a symbol's ordinal value.

public List<String>
getEnumSymbols()

If this is an enum, return its symbols.

public Schema.Field
getField(String fieldname)

If this is a record, returns the Field with the given name fieldName.

private static String
getFieldAlias(Schema.Name record, String field, Map<Schema.Name, Map<String, String>> fieldAliases)

public List<Schema.Field>
getFields()

If this is a record, returns the fields in it.

public int
getFixedSize()

If this is fixed, returns its size.

public String
getFullName()

If this is a record, enum or fixed, returns its namespace-qualified name, otherwise returns the name of the primitive type.

public Integer
getIndexNamed(String name)

If this is a union, return the branch with the provided full name.

public LogicalType
public String
getName()

If this is a record, enum or fixed, returns its name, otherwise the name of the primitive type.

public String
getNamespace()

If this is a record, enum or fixed, returns its namespace, if any.

private static String
getOptionalText(JsonNode container, String key)

Extracts text value associated to key from the container JsonNode.

private static String
getRequiredText(JsonNode
Container where to find key.
container
,
String
Key to look for in container.
key
,
String
String to prepend to the SchemaParseException.
error
)

Extracts text value associated to key from the container JsonNode, and throws SchemaParseException if it doesn't exist.

public Schema.Type
getType()

Return the type of this schema.

public List<Schema>
getTypes()

If this is a union, returns its types.

public Schema
getValueType()

If this is a map, returns its value type.

public boolean
hasEnumSymbol(String symbol)

If this is an enum, returns true if it contains given symbol.

public boolean
hasFields()

If this is a record, returns whether the fields have been set.

public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public boolean
isError()

Returns true if this record is an error type.

public boolean
isNullable()

Returns true if this record is an union type containing null.

public boolean
isUnion()

Returns true if this record is an union type.

private static boolean
isValidDefault(Schema schema, JsonNode defaultValue)

public static Schema

Returns:

The freshly built Schema.
parse
(File
The file to read the schema from.
file
)

Deprecated use Schema.Parser instead.
Constructs a Schema object from JSON schema file file.
public static Schema

Returns:

The freshly built Schema.
parse
(InputStream
The input stream to read the schema from.
in
)

Deprecated use Schema.Parser instead.
Constructs a Schema object from JSON schema stream in.
public static Schema
parse(String jsonSchema)

Deprecated use Schema.Parser instead.
Construct a schema from JSON text.
public static Schema
parse(String jsonSchema, boolean
true if names should be validated, false if not.
validate
)

Deprecated use Schema.Parser instead.
Construct a schema from JSON text.
pack-priv static Schema
parse(JsonNode schema, Schema.Names names)

pack-priv static Set<String>
pack-priv static JsonNode
public static Object
parseJsonToObject(String s)

Parses the specified json string to an object.

public void
setFields(List<Schema.Field> fields)

If this is a record, set its fields.

pack-priv void
pack-priv void
public String
toString()

Overrides java.lang.Object.toString.

Render this as JSON.
public String
toString(boolean
if true, pretty-print JSON.
pretty
)

Render this as JSON.

public String
toString(Collection<Schema>
referenced schemas
referencedSchemas
,
boolean
if true, pretty-print JSON.
pretty
)

Deprecated
Render this as JSON, but without inlining the referenced schemas.
pack-priv String
toString(Schema.Names names, boolean pretty)

private static JsonNode
validateDefault(String fieldName, Schema schema, JsonNode defaultValue)

private static String
protected Object
Inherited from org.apache.avro.JsonProperties:
addAllPropsgetObjectPropgetObjectPropsgetProphasPropspropsEqualpropsHashCodeputAllwriteProps