com.akiban.sql.compiler
Class TypeComputer

java.lang.Object
  extended by com.akiban.sql.compiler.TypeComputer
All Implemented Interfaces:
Visitor

public class TypeComputer
extends Object
implements Visitor

Calculate types from schema information.


Constructor Summary
TypeComputer()
           
 
Method Summary
protected  boolean addDominantCast(DataTypeDescriptor toType, DataTypeDescriptor fromType)
           
protected  DataTypeDescriptor aggregateNode(AggregateNode node)
           
protected  DataTypeDescriptor betweenOperatorNode(BetweenOperatorNode node)
           
protected  DataTypeDescriptor binaryArithmeticOperatorNode(BinaryArithmeticOperatorNode node)
           
protected  DataTypeDescriptor binaryComparisonOperatorNode(BinaryComparisonOperatorNode node)
           
protected  DataTypeDescriptor binaryLogicalOperatorNode(BinaryLogicalOperatorNode node)
           
protected  DataTypeDescriptor coalesceFunctionNode(CoalesceFunctionNode node)
           
protected  ValueNode collateNode(ExplicitCollateNode node)
           
 void compute(StatementNode stmt)
           
protected  DataTypeDescriptor computeType(ValueNode node)
          Probably need to subclass and handle NodeTypes.COLUMN_REFERENCE to get type propagation started.
protected  DataTypeDescriptor concatenationOperatorNode(ConcatenationOperatorNode node)
           
protected  DataTypeDescriptor conditionalNode(ConditionalNode node)
           
protected  DataTypeDescriptor dominantType(ValueNodeList nodeList)
           
protected  void fromSubquery(FromSubquery node)
           
protected  TypeCompiler getTypeCompiler(TypeId typeId)
          Get the TypeCompiler associated with the given TypeId
protected  TypeCompiler getTypeCompiler(ValueNode valueNode)
          Get the TypeCompiler from this ValueNode, based on its TypeId using getTypeId().
protected  DataTypeDescriptor inListOperatorNode(InListOperatorNode node)
           
protected  void insertNode(InsertNode node)
           
protected  boolean isNestedTupleNullable(RowConstructorNode row)
           
protected static boolean isParameterOrUntypedNull(ValueNode node)
          Nodes whose type is inferred from the context.
protected  DataTypeDescriptor resultColumn(ResultColumn node)
           
protected  void selectNode(SelectNode node)
           
protected  ValueNode setType(ValueNode node)
           
 boolean skipChildren(Visitable node)
          Method that is called to indicate whether we should skip all nodes below this node for traversal.
 boolean stopTraversal()
          Method that is called to see if query tree traversal should be stopped before visiting all nodes.
protected  DataTypeDescriptor subqueryNode(SubqueryNode node)
           
protected  DataTypeDescriptor unaryLogicalOperatorNode(UnaryLogicalOperatorNode node)
           
 Visitable visit(Visitable node)
          This is the default visit operation on a QueryTreeNode.
 boolean visitChildrenFirst(Visitable node)
          Method that is called to see if visit() should be called on the children of node before it is called on node itself.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TypeComputer

public TypeComputer()
Method Detail

compute

public void compute(StatementNode stmt)
             throws StandardException
Throws:
StandardException

setType

protected ValueNode setType(ValueNode node)
                     throws StandardException
Throws:
StandardException

computeType

protected DataTypeDescriptor computeType(ValueNode node)
                                  throws StandardException
Probably need to subclass and handle NodeTypes.COLUMN_REFERENCE to get type propagation started.

Throws:
StandardException

isParameterOrUntypedNull

protected static boolean isParameterOrUntypedNull(ValueNode node)
Nodes whose type is inferred from the context.


resultColumn

protected DataTypeDescriptor resultColumn(ResultColumn node)
                                   throws StandardException
Throws:
StandardException

unaryLogicalOperatorNode

protected DataTypeDescriptor unaryLogicalOperatorNode(UnaryLogicalOperatorNode node)
                                               throws StandardException
Throws:
StandardException

binaryLogicalOperatorNode

protected DataTypeDescriptor binaryLogicalOperatorNode(BinaryLogicalOperatorNode node)
                                                throws StandardException
Throws:
StandardException

binaryArithmeticOperatorNode

protected DataTypeDescriptor binaryArithmeticOperatorNode(BinaryArithmeticOperatorNode node)
                                                   throws StandardException
Throws:
StandardException

binaryComparisonOperatorNode

protected DataTypeDescriptor binaryComparisonOperatorNode(BinaryComparisonOperatorNode node)
                                                   throws StandardException
Throws:
StandardException

betweenOperatorNode

protected DataTypeDescriptor betweenOperatorNode(BetweenOperatorNode node)
                                          throws StandardException
Throws:
StandardException

inListOperatorNode

protected DataTypeDescriptor inListOperatorNode(InListOperatorNode node)
                                         throws StandardException
Throws:
StandardException

isNestedTupleNullable

protected boolean isNestedTupleNullable(RowConstructorNode row)

subqueryNode

protected DataTypeDescriptor subqueryNode(SubqueryNode node)
                                   throws StandardException
Throws:
StandardException

conditionalNode

protected DataTypeDescriptor conditionalNode(ConditionalNode node)
                                      throws StandardException
Throws:
StandardException

coalesceFunctionNode

protected DataTypeDescriptor coalesceFunctionNode(CoalesceFunctionNode node)
                                           throws StandardException
Throws:
StandardException

aggregateNode

protected DataTypeDescriptor aggregateNode(AggregateNode node)
                                    throws StandardException
Throws:
StandardException

concatenationOperatorNode

protected DataTypeDescriptor concatenationOperatorNode(ConcatenationOperatorNode node)
                                                throws StandardException
Throws:
StandardException

collateNode

protected ValueNode collateNode(ExplicitCollateNode node)
                         throws StandardException
Throws:
StandardException

dominantType

protected DataTypeDescriptor dominantType(ValueNodeList nodeList)
                                   throws StandardException
Throws:
StandardException

addDominantCast

protected boolean addDominantCast(DataTypeDescriptor toType,
                                  DataTypeDescriptor fromType)

selectNode

protected void selectNode(SelectNode node)
                   throws StandardException
Throws:
StandardException

fromSubquery

protected void fromSubquery(FromSubquery node)
                     throws StandardException
Throws:
StandardException

insertNode

protected void insertNode(InsertNode node)
                   throws StandardException
Throws:
StandardException

visit

public Visitable visit(Visitable node)
                throws StandardException
Description copied from interface: Visitor
This is the default visit operation on a QueryTreeNode. It just returns the node. This will typically suffice as the default visit operation for most visitors unless the visitor needs to count the number of nodes visited or something like that.

Visitors will overload this method by implementing a version with a signature that matches a specific type of node. For example, if I want to do something special with aggregate nodes, then that Visitor will implement a visit(AggregateNode node) method which does the aggregate specific processing.

Specified by:
visit in interface Visitor
Parameters:
node - the node to process
Returns:
a query tree node. Often times this is the same node that was passed in, but Visitors that replace nodes with other nodes will use this to return the new replacement node.
Throws:
StandardException - may be throw an error as needed by the visitor (i.e. may be a normal error if a particular node is found, e.g. if checking a group by, we don't expect to find any ColumnReferences that aren't under an AggregateNode -- the easiest thing to do is just throw an error when we find the questionable node).

skipChildren

public boolean skipChildren(Visitable node)
                     throws StandardException
Description copied from interface: Visitor
Method that is called to indicate whether we should skip all nodes below this node for traversal. Useful if we want to effectively ignore/prune all branches under a particular node.

Differs from stopTraversal() in that it only affects subtrees, rather than the entire traversal.

Specified by:
skipChildren in interface Visitor
Parameters:
node - the node to process
Returns:
true/false
Throws:
StandardException

visitChildrenFirst

public boolean visitChildrenFirst(Visitable node)
Description copied from interface: Visitor
Method that is called to see if visit() should be called on the children of node before it is called on node itself. If this method always returns true, the visitor will walk the tree bottom-up. If it always returns false, the tree is visited top-down.

Specified by:
visitChildrenFirst in interface Visitor
Parameters:
node - the top node of a sub-tree about to be visited
Returns:
true if node's children should be visited before node, false otherwise

stopTraversal

public boolean stopTraversal()
Description copied from interface: Visitor
Method that is called to see if query tree traversal should be stopped before visiting all nodes. Useful for short circuiting traversal if we already know we are done.

Specified by:
stopTraversal in interface Visitor
Returns:
true/false

getTypeCompiler

protected TypeCompiler getTypeCompiler(TypeId typeId)
Get the TypeCompiler associated with the given TypeId

Parameters:
typeId - The TypeId to get a TypeCompiler for
Returns:
The corresponding TypeCompiler

getTypeCompiler

protected TypeCompiler getTypeCompiler(ValueNode valueNode)
                                throws StandardException
Get the TypeCompiler from this ValueNode, based on its TypeId using getTypeId().

Returns:
This ValueNode's TypeCompiler
Throws:
StandardException


Copyright © 2013 Akiban Technologies, Inc. All rights reserved.