org.apache.avro
Class Schema

java.lang.Object
  extended by org.apache.avro.Schema

public abstract class Schema
extends Object

An abstract data type.

A schema may be one of:


Nested Class Summary
static class Schema.Field
          A field within a record.
static class Schema.Type
          The type of a schema.
 
Method Summary
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 namespace, List<String> values)
          Create an enum schema.
static Schema createFixed(String name, String space, int size)
          Create a union schema.
static Schema createMap(Schema valueType)
          Create a map schema.
static Schema createRecord(LinkedHashMap<String,Schema.Field> fields)
          Create an anonymous record schema.
static Schema createRecord(String name, String namespace, boolean isError)
          Create a named record schema.
static Schema createUnion(List<Schema> types)
          Create a union schema.
 boolean equals(Object o)
           
 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.
 Map<String,Schema.Field> getFields()
          If this is a record, returns its fields.
 Iterable<Map.Entry<String,Schema>> getFieldSchemas()
          If this is a record, enumerate its field names and their schemas.
 int getFixedSize()
          If this is fixed, returns its size.
 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.
 int hashCode()
           
 boolean isError()
          Returns true if this record is an error type.
static Schema parse(File file)
           
static Schema parse(String jsonSchema)
          Construct a schema from JSON text.
 void setFields(LinkedHashMap<String,Schema.Field> fields)
          If this is a record, set its fields.
 String toString()
          Render this as JSON.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Method Detail

create

public static Schema create(Schema.Type type)
Create a schema for a primitive type.


createRecord

public static Schema createRecord(LinkedHashMap<String,Schema.Field> fields)
Create an anonymous record schema.


createRecord

public static Schema createRecord(String name,
                                  String namespace,
                                  boolean isError)
Create a named record schema.


createEnum

public static Schema createEnum(String name,
                                String namespace,
                                List<String> values)
Create an enum schema.


createArray

public static Schema createArray(Schema elementType)
Create an array schema.


createMap

public static Schema createMap(Schema valueType)
Create a map schema.


createUnion

public static Schema createUnion(List<Schema> types)
Create a union schema.


createFixed

public static Schema createFixed(String name,
                                 String space,
                                 int size)
Create a union schema.


getType

public Schema.Type getType()
Return the type of this schema.


getFields

public Map<String,Schema.Field> getFields()
If this is a record, returns its fields.


getFieldSchemas

public Iterable<Map.Entry<String,Schema>> getFieldSchemas()
If this is a record, enumerate its field names and their schemas.


setFields

public void setFields(LinkedHashMap<String,Schema.Field> fields)
If this is a record, set its fields.


getEnumSymbols

public List<String> getEnumSymbols()
If this is an enum, return its symbols.


getEnumOrdinal

public int getEnumOrdinal(String symbol)
If this is an enum, return a symbol's ordinal value.


getName

public String getName()
If this is a record, enum or fixed, returns its name, otherwise the name of the primitive type.


getNamespace

public String getNamespace()
If this is a record, enum or fixed, returns its namespace, if any.


isError

public boolean isError()
Returns true if this record is an error type.


getElementType

public Schema getElementType()
If this is an array, returns its element type.


getValueType

public Schema getValueType()
If this is a map, returns its value type.


getTypes

public List<Schema> getTypes()
If this is a union, returns its types.


getFixedSize

public int getFixedSize()
If this is fixed, returns its size.


toString

public String toString()
Render this as JSON.

Overrides:
toString in class Object

equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

parse

public static Schema parse(File file)
                    throws IOException
Throws:
IOException

parse

public static Schema parse(String jsonSchema)
Construct a schema from JSON text.



Copyright © 2009 The Apache Software Foundation