public class Schema extends Object implements Serializable, Cloneable
Modifier and Type | Class and Description |
---|---|
static class |
Schema.FieldSchema |
Constructor and Description |
---|
Schema() |
Schema(List<Schema.FieldSchema> fields) |
Schema(Schema.FieldSchema fieldSchema)
Create a schema with only one field.
|
Schema(Schema s)
Copy Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Schema.FieldSchema f) |
void |
addAlias(String alias,
Schema.FieldSchema fs) |
static boolean |
castable(Schema cast,
Schema input)
Recursively compare two schemas to check if the input schema
can be cast to the cast schema
|
Schema |
clone()
Make a deep copy of a schema.
|
boolean |
equals(Object other)
For two schemas to be equal, they have to be deeply equal.
|
static boolean |
equals(Schema schema,
Schema other,
boolean relaxInner,
boolean relaxAlias)
Recursively compare two schemas for equality
|
Schema.FieldSchema |
findFieldSchema(String canonicalName)
Look for a FieldSchema instance in the schema hierarchy which has the given canonical name.
|
static Schema |
generateNestedSchema(byte topLevelType,
byte... innerTypes) |
Set<String> |
getAliases() |
Schema.FieldSchema |
getField(int fieldNum)
Given a field number, find the associated FieldSchema.
|
Schema.FieldSchema |
getField(String alias)
Given an alias name, find the associated FieldSchema.
|
List<Schema.FieldSchema> |
getFields() |
Schema.FieldSchema |
getFieldSubNameMatch(String alias)
Given an alias name, find the associated FieldSchema.
|
static Schema |
getPigSchema(ResourceSchema rSchema) |
int |
getPosition(String alias)
Given an alias, find the associated position of the field schema.
|
int |
getPositionSubName(String alias)
Given an alias, find the associated position of the field schema.
|
int |
hashCode() |
boolean |
isTwoLevelAccessRequired()
Deprecated.
twoLevelAccess is no longer needed
|
Schema |
merge(Schema other,
boolean otherTakesAliasPrecedence)
Merge this schema with the other schema
|
Schema |
mergePrefixSchema(Schema other,
boolean otherTakesAliasPrecedence)
Recursively prefix merge two schemas
|
Schema |
mergePrefixSchema(Schema other,
boolean otherTakesAliasPrecedence,
boolean allowMergeableTypes)
Recursively prefix merge two schemas
|
static Schema |
mergeSchema(Schema schema,
Schema other,
boolean otherTakesAliasPrecedence)
Recursively merge two schemas
|
static Schema |
mergeSchema(Schema schema,
Schema other,
boolean otherTakesAliasPrecedence,
boolean allowDifferentSizeMerge,
boolean allowIncompatibleTypes)
Recursively merge two schemas
|
static Schema |
mergeSchemaByAlias(Schema schema1,
Schema schema2)
Merges two schemas using their column aliases
(unlike mergeSchema(..) functions which merge using positions)
Schema will not be merged if types are incompatible,
as per DataType.mergeType(..)
For Tuples and Bags, SubSchemas have to be equal be considered compatible
|
static Schema |
mergeSchemasByAlias(Collection<Schema> schemas)
Merges collection of schemas using their column aliases
(unlike mergeSchema(..) functions which merge using positions)
Schema will not be merged if types are incompatible,
as per DataType.mergeType(..)
For Tuples and Bags, SubSchemas have to be equal be considered compatible
|
String |
prettyPrint() |
void |
printAliases() |
void |
reconcile(Schema other)
Reconcile this schema with another schema.
|
static void |
setSchemaDefaultType(Schema s,
byte t)
Recursively set NULL type to the specifid type in a schema
|
void |
setTwoLevelAccessRequired(boolean twoLevelAccess)
Deprecated.
twoLevelAccess is no longer needed
|
int |
size()
Find the number of fields in the schema.
|
static void |
stringifySchema(StringBuilder sb,
Schema schema,
byte type) |
static void |
stringifySchema(StringBuilder sb,
Schema schema,
byte type,
int indentLevel) |
String |
toString() |
public Schema()
public Schema(List<Schema.FieldSchema> fields)
fields
- List of field schemas that describes the fields.public Schema(Schema.FieldSchema fieldSchema)
fieldSchema
- field to put in this schema.public Schema(Schema s)
s
- source schemapublic Schema.FieldSchema getField(String alias) throws FrontendException
alias
- Alias to look up.FrontendException
public Schema.FieldSchema getFieldSubNameMatch(String alias) throws FrontendException
alias
- Alias to look up.FrontendException
public Schema.FieldSchema getField(int fieldNum) throws FrontendException
fieldNum
- Field number to look up.ParseException
- if the field number exceeds the number of fields in the
tuple.FrontendException
public int size()
public void reconcile(Schema other) throws FrontendException
other
- Schema to reconcile with.ParseException
- if this cannot be reconciled.FrontendException
public boolean equals(Object other)
public Schema clone() throws CloneNotSupportedException
clone
in class Object
CloneNotSupportedException
public String prettyPrint()
public static void stringifySchema(StringBuilder sb, Schema schema, byte type) throws FrontendException
FrontendException
public static void stringifySchema(StringBuilder sb, Schema schema, byte type, int indentLevel) throws FrontendException
FrontendException
public void add(Schema.FieldSchema f)
public int getPosition(String alias) throws FrontendException
alias
- alias of the FieldSchema.FrontendException
public int getPositionSubName(String alias) throws FrontendException
alias
- alias of the FieldSchema.FrontendException
public void addAlias(String alias, Schema.FieldSchema fs)
public void printAliases()
public List<Schema.FieldSchema> getFields()
public static boolean castable(Schema cast, Schema input)
cast
- schema of the cast operatorinput
- schema of the cast inputpublic static boolean equals(Schema schema, Schema other, boolean relaxInner, boolean relaxAlias)
schema
- other
- relaxInner
- if true, inner schemas will not be checkedrelaxAlias
- if true, aliases will not be checkedpublic Schema merge(Schema other, boolean otherTakesAliasPrecedence)
other
- the other schema to be merged withotherTakesAliasPrecedence
- true if aliases from the other
schema take precedencepublic static Schema mergeSchema(Schema schema, Schema other, boolean otherTakesAliasPrecedence)
schema
- the initial schemaother
- the other schema to be merged withotherTakesAliasPrecedence
- true if aliases from the other
schema take precedencepublic static Schema mergeSchema(Schema schema, Schema other, boolean otherTakesAliasPrecedence, boolean allowDifferentSizeMerge, boolean allowIncompatibleTypes) throws SchemaMergeException
schema
- the initial schemaother
- the other schema to be merged withotherTakesAliasPrecedence
- true if aliases from the other
schema take precedenceallowDifferentSizeMerge
- allow merging of schemas of different typesallowIncompatibleTypes
- 1) if types in schemas are not compatible
they will be treated as ByteArray (untyped)
2) if schemas in schemas are not compatible
and allowIncompatibleTypes is true
those inner schemas in the output
will be null.SchemaMergeException
- if they cannot be mergedpublic static Schema mergeSchemasByAlias(Collection<Schema> schemas) throws SchemaMergeException
schemas
- - list of schemas to be merged using their column aliasSchemaMergeException
public static Schema mergeSchemaByAlias(Schema schema1, Schema schema2) throws SchemaMergeException
schema1
- schema2
- SchemaMergeException
- if schemas cannot be mergedpublic static Schema generateNestedSchema(byte topLevelType, byte... innerTypes) throws FrontendException
topLevelType
- DataType type of the top level elementinnerTypes
- DataType types of the inner level elementFrontendException
public Schema mergePrefixSchema(Schema other, boolean otherTakesAliasPrecedence) throws SchemaMergeException
other
- the other schema to be merged withotherTakesAliasPrecedence
- true if aliases from the other
schema take precedenceSchemaMergeException
- if they cannot be mergedpublic Schema mergePrefixSchema(Schema other, boolean otherTakesAliasPrecedence, boolean allowMergeableTypes) throws SchemaMergeException
other
- the other schema to be merged withotherTakesAliasPrecedence
- true if aliases from the other
schema take precedenceallowMergeableTypes
- true if "mergeable" types should be allowed.
Two types are mergeable if any of the following conditions is true IN THE
BELOW ORDER of checks:
1) if either one has a type null or unknown and other has a type OTHER THAN
null or unknown, the result type will be the latter non null/unknown type
2) If either type is bytearray, then result type will be the other (possibly non BYTEARRAY) type
3) If current type can be cast to the other type, then the result type will be the
other typeSchemaMergeException
- if they cannot be mergedpublic static void setSchemaDefaultType(Schema s, byte t)
s
- the schema whose NULL type has to be sett
- the specified type@Deprecated public boolean isTwoLevelAccessRequired()
@Deprecated public void setTwoLevelAccessRequired(boolean twoLevelAccess)
twoLevelAccess
- the twoLevelAccess to setpublic static Schema getPigSchema(ResourceSchema rSchema) throws FrontendException
FrontendException
public Schema.FieldSchema findFieldSchema(String canonicalName)
canonicalName
- canonical nameCopyright © 2007-2012 The Apache Software Foundation