com.datasalt.pangool.io
Class Schema.Field

java.lang.Object
  extended by com.datasalt.pangool.io.Schema.Field
All Implemented Interfaces:
Serializable
Enclosing class:
Schema

public static class Schema.Field
extends Object
implements Serializable

A field is an abstract data type that can be one of this:

A field can be constructed using one of its static createXXX methods. A field object is immutable.

See Also:
Serialized Form

Nested Class Summary
static interface Schema.Field.FieldConfigurable
          Interface that allows to receive ITuple field's metadata.
static class Schema.Field.Type
           
 
Field Summary
static String METADATA_BYTES_AS_OBJECT
           
static String METADATA_DEFAULT_VALUE
           
static String METADATA_OBJECT_CLASS
           
static String METADATA_OBJECT_SERIALIZATION
           
static Set<String> RESERVED_KEYWORDS
           
 
Method Summary
 void addProp(String key, String value)
           
static Schema.Field cloneField(Schema.Field field, String newName)
          Clones a Field with a new name.
static Schema.Field cloneField(Schema.Field field, String newName, boolean nullable)
          Clones a Field with a new name.
static Schema.Field create(String name, Schema.Field.Type type)
          Crates a non nullable field of the given type.
static Schema.Field create(String name, Schema.Field.Type type, boolean nullable)
          Crates a field of the given type.
static Schema.Field create(String name, Schema.Field.Type type, boolean nullable, Object defaultValue)
          Crates a field of the given type.
static Schema.Field createEnum(String name, Class<?> clazz)
          Creates a non-nullable enum field, based in a enum class
static Schema.Field createEnum(String name, Class<?> clazz, boolean nullable)
          Creates an enum field, based in a enum class
static Schema.Field createEnum(String name, Class<?> clazz, boolean nullable, Object defaultValue)
          Creates an enum field, based in a enum class
static Schema.Field createObject(String name, Class<?> clazz)
          Creates a non nullable object field.
static Schema.Field createObject(String name, Class<?> clazz, boolean nullable)
          Creates an object field.
static Schema.Field createTupleField(String name, Schema schema)
          Creates a non-nullable field containing a Pangool Tuple.
static Schema.Field createTupleField(String name, Schema schema, boolean nullable)
          Creates a field containing a Pangool Tuple.
 boolean equals(Object a)
           
 Object getDefaultValue()
           
 String getName()
           
 Class<?> getObjectClass()
           
 Class<? extends org.apache.hadoop.io.serializer.Serialization> getObjectSerialization()
           
 String getProp(String name)
           
 Map<String,String> getProps()
           
 Schema.Field.Type getType()
           
 int hashCode()
           
 boolean isNullable()
           
 void setObjectSerialization(Class<? extends org.apache.hadoop.io.serializer.Serialization> serialization)
          Sets custom serialization for fields with type OBJECT.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RESERVED_KEYWORDS

public static final Set<String> RESERVED_KEYWORDS

METADATA_OBJECT_CLASS

public static final String METADATA_OBJECT_CLASS
See Also:
Constant Field Values

METADATA_OBJECT_SERIALIZATION

public static final String METADATA_OBJECT_SERIALIZATION
See Also:
Constant Field Values

METADATA_BYTES_AS_OBJECT

public static final String METADATA_BYTES_AS_OBJECT
See Also:
Constant Field Values

METADATA_DEFAULT_VALUE

public static final String METADATA_DEFAULT_VALUE
See Also:
Constant Field Values
Method Detail

addProp

public void addProp(String key,
                    String value)

getProps

public Map<String,String> getProps()

getProp

public String getProp(String name)

create

public static Schema.Field create(String name,
                                  Schema.Field.Type type,
                                  boolean nullable,
                                  Object defaultValue)
Crates a field of the given type.

Parameters:
name - Field's name
type - Schema.Field.Type of the field
nullable - True if null values are allowed for this field
defaultValue - The default value for this field if the field is missing in some read schema

create

public static Schema.Field create(String name,
                                  Schema.Field.Type type,
                                  boolean nullable)
Crates a field of the given type.

Parameters:
name - Field's name
type - Schema.Field.Type of the field
nullable - True if null values are allowed for this field

create

public static Schema.Field create(String name,
                                  Schema.Field.Type type)
Crates a non nullable field of the given type.

Parameters:
name - Field's name
type - Schema.Field.Type of the field

createObject

public static Schema.Field createObject(String name,
                                        Class<?> clazz,
                                        boolean nullable)
Creates an object field.

Parameters:
name - Field's name
clazz - Object's instance class
nullable - True if null values are allowed for this field

createObject

public static Schema.Field createObject(String name,
                                        Class<?> clazz)
Creates a non nullable object field.

Parameters:
name - Field's name
clazz - Object's instance class
Returns:

createTupleField

public static Schema.Field createTupleField(String name,
                                            Schema schema,
                                            boolean nullable)
Creates a field containing a Pangool Tuple.

Parameters:
name - Field's name
schema - The schema of the field
nullable - True if null values are allowed for this field
Returns:

createTupleField

public static Schema.Field createTupleField(String name,
                                            Schema schema)
Creates a non-nullable field containing a Pangool Tuple.

Parameters:
name - Field's name
schema - The schema of the field
Returns:

cloneField

public static Schema.Field cloneField(Schema.Field field,
                                      String newName,
                                      boolean nullable)
Clones a Field with a new name. Useful for mutating schemas.

Parameters:
field - The field to clone.
newName - The new name of the field.
nullable - If the new field must be nullable or not
Returns:
The cloned field.

cloneField

public static Schema.Field cloneField(Schema.Field field,
                                      String newName)
Clones a Field with a new name. Useful for mutating schemas.

Parameters:
field - The field to clone.
newName - The new name of the field.
Returns:
The cloned field.

createEnum

public static Schema.Field createEnum(String name,
                                      Class<?> clazz,
                                      boolean nullable,
                                      Object defaultValue)
Creates an enum field, based in a enum class

Parameters:
name - Field's name
clazz - Enum class
nullable - True if null values are allowed for this field.
defaultValue - The defaultValue to assign if this field is not present in some read schema.
Returns:

createEnum

public static Schema.Field createEnum(String name,
                                      Class<?> clazz,
                                      boolean nullable)
Creates an enum field, based in a enum class

Parameters:
name - Field's name
clazz - Enum class
nullable - True if null values are allowed for this field.
Returns:

createEnum

public static Schema.Field createEnum(String name,
                                      Class<?> clazz)
Creates a non-nullable enum field, based in a enum class

Parameters:
name - Field's name
clazz - Enum class
Returns:

getDefaultValue

public Object getDefaultValue()
Returns:
Null if this field has no associated default value, or the strongly typed default value otherwise. Default values can be set by Field constructor and are enforced to its corret type, then serialized to string.

getType

public Schema.Field.Type getType()

getName

public String getName()

getObjectClass

public Class<?> getObjectClass()

isNullable

public boolean isNullable()

getObjectSerialization

public Class<? extends org.apache.hadoop.io.serializer.Serialization> getObjectSerialization()

setObjectSerialization

public void setObjectSerialization(Class<? extends org.apache.hadoop.io.serializer.Serialization> serialization)
Sets custom serialization for fields with type OBJECT. If the Serialization class also implements Schema.Field.FieldConfigurable then the field's metadata (properties) is passed to the instance allowing stateful serialization.


equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object


Copyright © –2014 Datasalt Systems S.L.. All rights reserved.