org.apache.pig.impl.logicalLayer.validators
Class TypeCheckingVisitor

java.lang.Object
  extended by org.apache.pig.impl.plan.PlanVisitor<LogicalOperator,LogicalPlan>
      extended by org.apache.pig.impl.logicalLayer.LOVisitor
          extended by org.apache.pig.impl.logicalLayer.validators.TypeCheckingVisitor

public class TypeCheckingVisitor
extends LOVisitor

Visitor for type checking. For simplicity of the first implementation, we throw exception immediately once something doesn't look alright. This is not quite smart e.g. if the plan has another unrelated branch.


Field Summary
static MultiMap<Byte,Byte> castLookup
           
 
Fields inherited from class org.apache.pig.impl.plan.PlanVisitor
mCurrentWalker, mPlan
 
Constructor Summary
TypeCheckingVisitor(LogicalPlan plan, CompilationMessageCollector messageCollector)
           
 
Method Summary
 byte getAtomicGroupByType(LOCogroup cg)
          This can be used to get the merged type of output group col only when the group col is of atomic type TODO: This doesn't work with group by complex type
 Schema getTupleGroupBySchema(LOCogroup cg)
           
static boolean schemaEqualsForMatching(Schema inputSchema, Schema udfSchema, boolean ignoreByteArrays)
          Compare two schemas for equality for argument matching purposes.
protected  void visit(ExpressionOperator eOp)
           
 void visit(LOAdd binOp)
           
 void visit(LOAnd binOp)
           
protected  void visit(LOBinCond binCond)
          For Bincond, lhsOp and rhsOp must have the same output type or both sides have to be number
protected  void visit(LOCast cast)
          For Basic Types: 0) Casting to itself is always ok 1) Casting from number to number is always ok 2) ByteArray to anything is ok 3) (number or chararray) to (bytearray or chararray) is ok For Composite Types: Recursively traverse the schemas till you get a basic type
protected  void visit(LOCogroup cg)
          COGroup All group by cols from all inputs have to be of the same type
protected  void visit(LOConst cs)
          LOConst.
protected  void visit(LOCross cs)
          Return concatenated of all fields from all input operators If one of the inputs have no schema then we cannot construct the output schema.
protected  void visit(LODistinct op)
          LODistinct, output schema should be the same as input
 void visit(LODivide binOp)
           
 void visit(LOEqual binOp)
           
protected  void visit(LOFilter filter)
          The schema of filter output will be the same as filter input
protected  void visit(LOForEach f)
          Output schema of LOForEach is a tuple schma which is the output of all inner plans Flatten also has to be taken care on in here
protected  void visit(LogicalOperator lOp)
           
 void visit(LOGreaterThan binOp)
           
 void visit(LOGreaterThanEqual binOp)
           
 void visit(LOIsNull uniOp)
           
protected  void visit(LOJoin join)
          LOJoin visitor
 void visit(LOLesserThan binOp)
           
 void visit(LOLesserThanEqual binOp)
           
protected  void visit(LOLimit op)
           
protected  void visit(LOLoad load)
           
 void visit(LOMapLookup map)
           
 void visit(LOMod binOp)
           
 void visit(LOMultiply binOp)
           
 void visit(LONegative uniOp)
           
 void visit(LONot uniOp)
           
 void visit(LONotEqual binOp)
           
 void visit(LOOr binOp)
           
protected  void visit(LOProject pj)
           
protected  void visit(LORegexp rg)
          LORegexp expects CharArray as input Itself always returns Boolean
protected  void visit(LOSort s)
          The schema of sort output will be the same as sort input.
protected  void visit(LOSplit split)
          The schema of split output will be the same as split input
protected  void visit(LOSplitOutput op)
           
protected  void visit(LOStore store)
           
 void visit(LOSubtract binOp)
           
protected  void visit(LOUnion u)
           
protected  void visit(LOUserFunc func)
          Iterate over each expression that is part of the function argument list
protected  void visit(UnaryExpressionOperator uniOp)
          Currently, there are two unaryOps: Neg and Not.
 
Methods inherited from class org.apache.pig.impl.logicalLayer.LOVisitor
visit, visit, visit
 
Methods inherited from class org.apache.pig.impl.plan.PlanVisitor
getPlan, popWalker, pushWalker, visit
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

castLookup

public static final MultiMap<Byte,Byte> castLookup
Constructor Detail

TypeCheckingVisitor

public TypeCheckingVisitor(LogicalPlan plan,
                           CompilationMessageCollector messageCollector)
Method Detail

visit

protected void visit(ExpressionOperator eOp)
              throws VisitorException
Overrides:
visit in class LOVisitor
Parameters:
eOp - the logical expression operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LogicalOperator lOp)
              throws VisitorException
Overrides:
visit in class LOVisitor
Parameters:
lOp - the logical operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOProject pj)
              throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

protected void visit(LOConst cs)
              throws VisitorException
LOConst. Type information should be associated with LOConst in the parsing stage so we don't need any logic here

Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOMapLookup map)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

protected void visit(LORegexp rg)
              throws VisitorException
LORegexp expects CharArray as input Itself always returns Boolean

Overrides:
visit in class LOVisitor
Parameters:
rg -
Throws:
VisitorException

visit

public void visit(LOAnd binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOOr binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOMultiply binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LODivide binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOAdd binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOSubtract binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOGreaterThan binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOGreaterThanEqual binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOLesserThan binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOLesserThanEqual binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOEqual binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LONotEqual binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOMod binOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LONegative uniOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LONot uniOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

public void visit(LOIsNull uniOp)
           throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

protected void visit(UnaryExpressionOperator uniOp)
              throws VisitorException
Currently, there are two unaryOps: Neg and Not.

Overrides:
visit in class LOVisitor
Parameters:
uniOp - the logical unary operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOUserFunc func)
              throws VisitorException
Description copied from class: LOVisitor
Iterate over each expression that is part of the function argument list

Overrides:
visit in class LOVisitor
Parameters:
func - the user defined function
Throws:
VisitorException

schemaEqualsForMatching

public static boolean schemaEqualsForMatching(Schema inputSchema,
                                              Schema udfSchema,
                                              boolean ignoreByteArrays)
Compare two schemas for equality for argument matching purposes. This is a more relaxed form of Schema.equals wherein first the Datatypes of the field schema are checked for equality. Then if a field schema in the udf schema is for a complex type AND if the inner schema is NOT null, check for schema equality of the inner schemas of the UDF field schema and input field schema

Parameters:
inputSchema -
udfSchema -
ignoreByteArrays -
Returns:
true if FieldSchemas are equal for argument matching, false otherwise

visit

protected void visit(LOBinCond binCond)
              throws VisitorException
For Bincond, lhsOp and rhsOp must have the same output type or both sides have to be number

Overrides:
visit in class LOVisitor
Parameters:
binCond - the logical binCond operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOCast cast)
              throws VisitorException
For Basic Types: 0) Casting to itself is always ok 1) Casting from number to number is always ok 2) ByteArray to anything is ok 3) (number or chararray) to (bytearray or chararray) is ok For Composite Types: Recursively traverse the schemas till you get a basic type

Overrides:
visit in class LOVisitor
Parameters:
cast - the logical cast operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOUnion u)
              throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

protected void visit(LOSplitOutput op)
              throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

protected void visit(LODistinct op)
              throws VisitorException
LODistinct, output schema should be the same as input

Overrides:
visit in class LOVisitor
Parameters:
op -
Throws:
VisitorException

visit

protected void visit(LOLimit op)
              throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

protected void visit(LOCross cs)
              throws VisitorException
Return concatenated of all fields from all input operators If one of the inputs have no schema then we cannot construct the output schema.

Overrides:
visit in class LOVisitor
Parameters:
cs -
Throws:
VisitorException

visit

protected void visit(LOSort s)
              throws VisitorException
The schema of sort output will be the same as sort input.

Overrides:
visit in class LOVisitor
Parameters:
s - the logical sort operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOFilter filter)
              throws VisitorException
The schema of filter output will be the same as filter input

Overrides:
visit in class LOVisitor
Parameters:
filter - the logical filter operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOSplit split)
              throws VisitorException
The schema of split output will be the same as split input

Overrides:
visit in class LOVisitor
Parameters:
split - the logical split operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOJoin join)
              throws VisitorException
LOJoin visitor

Overrides:
visit in class LOVisitor
Parameters:
join - the logical join operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOCogroup cg)
              throws VisitorException
COGroup All group by cols from all inputs have to be of the same type

Overrides:
visit in class LOVisitor
Parameters:
cg - the logical cogroup operator that has to be visited
Throws:
VisitorException

getAtomicGroupByType

public byte getAtomicGroupByType(LOCogroup cg)
                          throws VisitorException
This can be used to get the merged type of output group col only when the group col is of atomic type TODO: This doesn't work with group by complex type

Returns:
The type of the group by
Throws:
VisitorException

getTupleGroupBySchema

public Schema getTupleGroupBySchema(LOCogroup cg)
                             throws VisitorException
Throws:
VisitorException

visit

protected void visit(LOForEach f)
              throws VisitorException
Output schema of LOForEach is a tuple schma which is the output of all inner plans Flatten also has to be taken care on in here

Overrides:
visit in class LOVisitor
Parameters:
f - the logical foreach operator that has to be visited
Throws:
VisitorException

visit

protected void visit(LOLoad load)
              throws VisitorException
Overrides:
visit in class LOVisitor
Throws:
VisitorException

visit

protected void visit(LOStore store)
Overrides:
visit in class LOVisitor


Copyright © ${year} The Apache Software Foundation