|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.avro.Schema
public abstract class Schema
An abstract data type.
A schema may be one of:
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.
Nested Class Summary | |
---|---|
static class |
Schema.Field
A field within a record. |
static class |
Schema.Parser
A parser for JSON-format schemas. |
static class |
Schema.Type
The type of a schema. |
Method Summary | |
---|---|
void |
addAlias(String alias)
If this is a record, enum or fixed, add an alias. |
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 |
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)
Create an anonymous record schema. |
static Schema |
createRecord(String name,
String doc,
String namespace,
boolean isError)
Create a named record schema. |
static Schema |
createUnion(List<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. |
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. |
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. |
String |
getProp(String name)
Returns the value of the named property in this schema. |
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. |
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. |
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. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Method Detail |
---|
public static Schema create(Schema.Type type)
public String getProp(String name)
public void addProp(String name, String value)
name
- The name of the property to addvalue
- The value for the property to addpublic static Schema createRecord(List<Schema.Field> fields)
public static Schema createRecord(String name, String doc, String namespace, boolean isError)
public static Schema createEnum(String name, String doc, String namespace, List<String> values)
public static Schema createArray(Schema elementType)
public static Schema createMap(Schema valueType)
public static Schema createUnion(List<Schema> types)
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 List<String> getEnumSymbols()
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 Set<String> getAliases()
public boolean isError()
public Schema getElementType()
public Schema getValueType()
public List<Schema> getTypes()
public int getFixedSize()
public String toString()
toString
in class Object
public String toString(boolean pretty)
pretty
- if true, pretty-print JSON.public boolean equals(Object o)
equals
in class Object
public int hashCode()
hashCode
in class Object
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
JsonParseException
- if the contents are invalidpublic 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
JsonParseException
- if the contents are invalidpublic static Schema parse(String jsonSchema)
Schema.Parser
instead.
public static Schema parse(String jsonSchema, boolean validate)
Schema.Parser
instead.
validate
- true if names should be validated, false if not.public static Schema applyAliases(Schema writer, Schema reader)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |