org.apache.pig.newplan.logical.relational
Class LogicalSchema

java.lang.Object
  extended by org.apache.pig.newplan.logical.relational.LogicalSchema

public class LogicalSchema
extends Object

Schema, from a logical perspective.


Nested Class Summary
static class LogicalSchema.LogicalFieldSchema
           
static class LogicalSchema.MergeMode
           
 
Constructor Summary
LogicalSchema()
           
 
Method Summary
 void addField(LogicalSchema.LogicalFieldSchema field)
          Add a field to this schema.
static boolean castable(LogicalSchema inSch, LogicalSchema outSch)
          Recursively compare two schemas to check if the input schema can be cast to the cast schema
 LogicalSchema deepCopy()
           
static boolean equals(LogicalSchema schema, LogicalSchema other, boolean relaxInner, boolean relaxAlias)
          Recursively compare two schemas for equality
 int findField(long uid)
          Look for the index of the field that contains the specified uid
 LogicalSchema.LogicalFieldSchema getField(int fieldNum)
          Fetch a field by field number
 LogicalSchema.LogicalFieldSchema getField(String alias)
          Fetch a field by alias
 int getFieldPosition(String alias)
           
 List<LogicalSchema.LogicalFieldSchema> getFields()
          Get all fields
 LogicalSchema.LogicalFieldSchema getFieldSubNameMatch(String alias)
          Given an alias name, find the associated LogicalFieldSchema.
 boolean isEqual(Object other)
          Two schemas are equal if they are of equal size and their fields schemas considered in order are equal.
 boolean isEqual(Object other, boolean compareAlias)
          Two schemas are equal if they are of equal size and their fields schemas considered in order are equal.
static LogicalSchema merge(LogicalSchema s1, LogicalSchema s2, LogicalSchema.MergeMode mode)
          Merge two schemas.
static LogicalSchema mergeSchemaByAlias(LogicalSchema schema1, LogicalSchema 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 LogicalSchema mergeSchemasByAlias(List<LogicalSchema> 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
 LogicalSchema mergeUid(LogicalSchema uidOnlySchema)
           
 void normalize()
          Old Pig schema does not require a tuple schema inside a bag; Now it is required to have that; this method is to fill the gap
 void resetUid()
          Reset uids of all fieldschema that the schema contains
 int size()
          Get the size of the schema.
 String toString()
           
 String toString(boolean verbose)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LogicalSchema

public LogicalSchema()
Method Detail

resetUid

public void resetUid()
Reset uids of all fieldschema that the schema contains


castable

public static boolean castable(LogicalSchema inSch,
                               LogicalSchema outSch)
Recursively compare two schemas to check if the input schema can be cast to the cast schema

Parameters:
inSch - schema of the cast input
outSch - schema of the cast operator
Returns:
true if castable

addField

public void addField(LogicalSchema.LogicalFieldSchema field)
Add a field to this schema.

Parameters:
field - to be added to the schema

getField

public LogicalSchema.LogicalFieldSchema getField(String alias)
                                          throws FrontendException
Fetch a field by alias

Parameters:
alias -
Returns:
field associated with alias, or null if no such field
Throws:
FrontendException

getFieldSubNameMatch

public LogicalSchema.LogicalFieldSchema getFieldSubNameMatch(String alias)
                                                      throws FrontendException
Given an alias name, find the associated LogicalFieldSchema. If exact name is not found see if any field matches the part of the 'namespaced' alias. eg. if given alias is nm::a , and schema is (a,b). It will return FieldSchema of a. if given alias is nm::a and schema is (nm2::a, b), it will return null

Parameters:
alias - Alias to look up.
Returns:
LogicalFieldSchema, or null if no such alias is in this tuple.
Throws:
FrontendException

getFieldPosition

public int getFieldPosition(String alias)

getField

public LogicalSchema.LogicalFieldSchema getField(int fieldNum)
Fetch a field by field number

Parameters:
fieldNum - field number to fetch
Returns:
field

getFields

public List<LogicalSchema.LogicalFieldSchema> getFields()
Get all fields

Returns:
list of all fields

size

public int size()
Get the size of the schema.

Returns:
size

isEqual

public boolean isEqual(Object other)
Two schemas are equal if they are of equal size and their fields schemas considered in order are equal. This function does not compare the alias of the fields.


isEqual

public boolean isEqual(Object other,
                       boolean compareAlias)
Two schemas are equal if they are of equal size and their fields schemas considered in order are equal. If compareAlias argument is set to true, the alias of the fields are also compared.

Parameters:
other -
compareAlias -
Returns:
true if equal

findField

public int findField(long uid)
Look for the index of the field that contains the specified uid

Parameters:
uid - the uid to look for
Returns:
the index of the field, -1 if not found

merge

public static LogicalSchema merge(LogicalSchema s1,
                                  LogicalSchema s2,
                                  LogicalSchema.MergeMode mode)
                           throws FrontendException
Merge two schemas.

Parameters:
s1 - In Load/ForEach, s1 is user declared schema; In Union, s1 is left side.
s2 - In Load/ForEach, s2 is infered schema; In Union, s2 is right side.
mode - We merge schema in Load/Foreach/Union. In Load/Foreach, we always take s1 if compatible (s1 is set to be user defined schema), In union, we take more specific type (between numeric and string, we take string). In the case type mismatch in s1/s2, we expect TypeCheckingVisitor will fill the gap later.
Returns:
a merged schema, or null if the merge fails
Throws:
FrontendException

toString

public String toString(boolean verbose)

toString

public String toString()
Overrides:
toString in class Object

mergeUid

public LogicalSchema mergeUid(LogicalSchema uidOnlySchema)
                       throws FrontendException
Throws:
FrontendException

deepCopy

public LogicalSchema deepCopy()

mergeSchemasByAlias

public static LogicalSchema mergeSchemasByAlias(List<LogicalSchema> schemas)
                                         throws FrontendException
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

Parameters:
schemas - - list of schemas to be merged using their column alias
Returns:
merged schema
Throws:
FrontendException

mergeSchemaByAlias

public static LogicalSchema mergeSchemaByAlias(LogicalSchema schema1,
                                               LogicalSchema schema2)
                                        throws FrontendException
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

Throws:
FrontendException

equals

public static boolean equals(LogicalSchema schema,
                             LogicalSchema other,
                             boolean relaxInner,
                             boolean relaxAlias)
Recursively compare two schemas for equality

Parameters:
schema -
other -
relaxInner - if true, inner schemas will not be checked
relaxAlias - if true, aliases will not be checked
Returns:
true if schemas are equal, false otherwise

normalize

public void normalize()
Old Pig schema does not require a tuple schema inside a bag; Now it is required to have that; this method is to fill the gap



Copyright © 2007-2012 The Apache Software Foundation