org.apache.derby.impl.sql.compile
Class TernaryOperatorNode

java.lang.Object
  extended byorg.apache.derby.impl.sql.compile.QueryTreeNode
      extended byorg.apache.derby.impl.sql.compile.ValueNode
          extended byorg.apache.derby.impl.sql.compile.TernaryOperatorNode
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
LikeEscapeOperatorNode

public class TernaryOperatorNode
extends ValueNode

A TernaryOperatorNode represents a built-in ternary operators. This covers built-in functions like substr(). Java operators are not represented here: the JSQL language allows Java methods to be called from expressions, but not Java operators.

Author:
Jerry Brenner

Field Summary
(package private)  java.lang.String leftInterfaceType
           
(package private)  ValueNode leftOperand
           
static int LIKE
           
static int LOCATE
           
(package private)  java.lang.String methodName
           
(package private)  java.lang.String operator
           
(package private)  int operatorType
           
(package private)  ValueNode receiver
           
(package private)  java.lang.String receiverInterfaceType
           
(package private)  java.lang.String resultInterfaceType
           
(package private)  java.lang.String rightInterfaceType
           
(package private)  ValueNode rightOperand
           
static int SUBSTRING
           
(package private) static java.lang.String[][] TernaryArgType
           
(package private) static java.lang.String[] TernaryMethodNames
           
(package private) static java.lang.String[] TernaryOperators
           
(package private) static java.lang.String[] TernaryResultType
           
static int TIMESTAMPADD
           
static int TIMESTAMPDIFF
           
static int TRIM
           
(package private)  int trimType
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.ValueNode
clause, dataTypeServices, IN_HAVING_CLAUSE, IN_SELECT_LIST, IN_UNKNOWN_CLAUSE, IN_WHERE_CLAUSE, transformed
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, beginOffset, endOffset
 
Constructor Summary
TernaryOperatorNode()
           
 
Method Summary
 Visitable accept(Visitor v)
          Accept a visitor, and call v.visit() on child nodes as necessary.
private  void bindDateTimeArg(ValueNode arg, int argNumber)
           
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this expression.
private  boolean bindParameter(ValueNode arg, int jdbcType)
           
protected  void bindToBuiltIn()
           
protected  ValueNode castArgToString(ValueNode vn)
           
 boolean categorize(JBitSet referencedTabs, boolean simplePredsOnly)
          Categorize this predicate.
 boolean constantExpression(PredicateList whereClause)
          Return whether or not this expression tree represents a constant value.
 void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
          Do code generation for this ternary operator.
 ValueNode getLeftOperand()
          Get the leftOperand
 ValueNode getReceiver()
           
 ValueNode getRightOperand()
          Get the rightOperand
private  DataTypeDescriptor getVarcharDescriptor()
           
 void init(java.lang.Object receiver, java.lang.Object leftOperand, java.lang.Object rightOperand, java.lang.Object operatorType, java.lang.Object trimType)
          Initializer for a TernaryOperatorNode
 boolean isConstantExpression()
          Return whether or not this expression tree represents a constant expression.
 ValueNode locateBind()
          Bind locate operator
 ValueNode preprocess(int numTables, FromList outerFromList, SubqueryList outerSubqueryList, PredicateList outerPredicateList)
          Preprocess an expression tree.
 void printSubNodes(int depth)
          Prints the sub-nodes of this object.
 ValueNode remapColumnReferencesToExpressions()
          Remap all ColumnReferences in this tree to be clones of the underlying expression.
 void setClause(int clause)
          Set the clause that this node appears in.
 void setLeftOperand(ValueNode newLeftOperand)
          Set the leftOperand to the specified ValueNode
private  void setResultType(TypeId resultType)
           
 void setRightOperand(ValueNode newRightOperand)
          Set the rightOperand to the specified ValueNode
 ValueNode substrBind()
          Bind substr expression.
private  void throwBadType(java.lang.String funcName, java.lang.String type)
           
private  ValueNode timestampAddBind()
          Bind TIMESTAMPADD expression.
private  ValueNode timestampDiffBind()
          Bind TIMESTAMPDIFF expression.
 java.lang.String toString()
          Convert this object to a String.
private  ValueNode trimBind()
          Bind trim expression.
 
Methods inherited from class org.apache.derby.impl.sql.compile.ValueNode
bindExpression, changeToCNF, checkIsBoolean, checkReliability, checkReliability, checkTopPredicatesForEqualsConditions, copyFields, eliminateNots, genEqualsFalseTree, generate, generateFilter, genIsNullTree, genSQLJavaSQLTree, getClause, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getOrderableVariantType, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, getTypeServices, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isCloneable, isParameterNode, isRelationalOperator, optimizableEqualityNode, putAndsOnTop, selectivity, setDescriptor, setTransformed, setType, updatableByCursor, verifyChangeToCNF, verifyEliminateNots, verifyPutAndsOnTop
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
bind, convertDefaultNode, debugFlush, debugPrint, executeSchemaName, executeStatementName, formatNodeString, foundString, generate, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getSPSName, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeResultDescription, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

operator

java.lang.String operator

methodName

java.lang.String methodName

operatorType

int operatorType

receiver

ValueNode receiver

leftOperand

ValueNode leftOperand

rightOperand

ValueNode rightOperand

resultInterfaceType

java.lang.String resultInterfaceType

receiverInterfaceType

java.lang.String receiverInterfaceType

leftInterfaceType

java.lang.String leftInterfaceType

rightInterfaceType

java.lang.String rightInterfaceType

trimType

int trimType

TRIM

public static final int TRIM
See Also:
Constant Field Values

LOCATE

public static final int LOCATE
See Also:
Constant Field Values

SUBSTRING

public static final int SUBSTRING
See Also:
Constant Field Values

LIKE

public static final int LIKE
See Also:
Constant Field Values

TIMESTAMPADD

public static final int TIMESTAMPADD
See Also:
Constant Field Values

TIMESTAMPDIFF

public static final int TIMESTAMPDIFF
See Also:
Constant Field Values

TernaryOperators

static final java.lang.String[] TernaryOperators

TernaryMethodNames

static final java.lang.String[] TernaryMethodNames

TernaryResultType

static final java.lang.String[] TernaryResultType

TernaryArgType

static final java.lang.String[][] TernaryArgType
Constructor Detail

TernaryOperatorNode

public TernaryOperatorNode()
Method Detail

init

public void init(java.lang.Object receiver,
                 java.lang.Object leftOperand,
                 java.lang.Object rightOperand,
                 java.lang.Object operatorType,
                 java.lang.Object trimType)
Initializer for a TernaryOperatorNode

Overrides:
init in class ValueNode
Parameters:
receiver - The receiver (eg, string being operated on in substr())
leftOperand - The left operand of the node
rightOperand - The right operand of the node
operatorType - The type of the operand
trimType - The maximum width of this new node
Returns:
Nothing

toString

public java.lang.String toString()
Convert this object to a String. See comments in QueryTreeNode.java for how this should be done for tree printing.

Overrides:
toString in class ValueNode
Returns:
This object as a String

setClause

public void setClause(int clause)
Set the clause that this node appears in.

Overrides:
setClause in class ValueNode
Parameters:
clause - The clause that this node appears in.
Returns:
Nothing.

printSubNodes

public void printSubNodes(int depth)
Prints the sub-nodes of this object. See QueryTreeNode.java for how tree printing is supposed to work.

Overrides:
printSubNodes in class QueryTreeNode
Parameters:
depth - The depth of this node in the tree
Returns:
Nothing

bindExpression

public ValueNode bindExpression(FromList fromList,
                                SubqueryList subqueryList,
                                java.util.Vector aggregateVector)
                         throws StandardException
Bind this expression. This means binding the sub-expressions, as well as figuring out what the return type is for this expression.

Overrides:
bindExpression in class ValueNode
Parameters:
fromList - The FROM list for the query this expression is in, for binding columns.
subqueryList - The subquery list being built as we find SubqueryNodes
aggregateVector - The aggregate vector being built as we find AggregateNodes
Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

preprocess

public ValueNode preprocess(int numTables,
                            FromList outerFromList,
                            SubqueryList outerSubqueryList,
                            PredicateList outerPredicateList)
                     throws StandardException
Preprocess an expression tree. We do a number of transformations here (including subqueries, IN lists, LIKE and BETWEEN) plus subquery flattening. NOTE: This is done before the outer ResultSetNode is preprocessed.

Overrides:
preprocess in class ValueNode
Parameters:
numTables - Number of tables in the DML Statement
outerFromList - FromList from outer query block
outerSubqueryList - SubqueryList from outer query block
outerPredicateList - PredicateList from outer query block
Returns:
The modified expression
Throws:
StandardException - Thrown on error

generateExpression

public void generateExpression(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
Do code generation for this ternary operator.

Overrides:
generateExpression in class ValueNode
Parameters:
acb - The ExpressionClassBuilder for the class we're generating
mb - The method the expression will go into
Throws:
StandardException - Thrown on error

setLeftOperand

public void setLeftOperand(ValueNode newLeftOperand)
Set the leftOperand to the specified ValueNode

Parameters:
newLeftOperand - The new leftOperand
Returns:
None.

getLeftOperand

public ValueNode getLeftOperand()
Get the leftOperand

Returns:
The current leftOperand.

setRightOperand

public void setRightOperand(ValueNode newRightOperand)
Set the rightOperand to the specified ValueNode

Parameters:
newRightOperand - The new rightOperand
Returns:
None.

getRightOperand

public ValueNode getRightOperand()
Get the rightOperand

Returns:
The current rightOperand.

categorize

public boolean categorize(JBitSet referencedTabs,
                          boolean simplePredsOnly)
                   throws StandardException
Categorize this predicate. Initially, this means building a bit map of the referenced tables for each predicate. If the source of this ColumnReference (at the next underlying level) is not a ColumnReference or a VirtualColumnNode then this predicate will not be pushed down. For example, in: select * from (select 1 from s) a (x) where x = 1 we will not push down x = 1. NOTE: It would be easy to handle the case of a constant, but if the inner SELECT returns an arbitrary expression, then we would have to copy that tree into the pushed predicate, and that tree could contain subqueries and method calls. RESOLVE - revisit this issue once we have views.

Overrides:
categorize in class ValueNode
Parameters:
referencedTabs - JBitSet with bit map of referenced FromTables
simplePredsOnly - Whether or not to consider method calls, field references and conditional nodes when building bit map
Returns:
boolean Whether or not source.expression is a ColumnReference or a VirtualColumnNode.
Throws:
StandardException - Thrown on error

remapColumnReferencesToExpressions

public ValueNode remapColumnReferencesToExpressions()
                                             throws StandardException
Remap all ColumnReferences in this tree to be clones of the underlying expression.

Overrides:
remapColumnReferencesToExpressions in class ValueNode
Returns:
ValueNode The remapped expression tree.
Throws:
StandardException - Thrown on error

isConstantExpression

public boolean isConstantExpression()
Return whether or not this expression tree represents a constant expression.

Overrides:
isConstantExpression in class ValueNode
Returns:
Whether or not this expression tree represents a constant expression.

constantExpression

public boolean constantExpression(PredicateList whereClause)
Description copied from class: ValueNode
Return whether or not this expression tree represents a constant value. In this case, "constant" means that it will always evaluate to the same thing, even if it includes columns. A column is constant if it is compared to a constant expression.

Overrides:
constantExpression in class ValueNode
Returns:
True means this expression tree represents a constant value.
See Also:
ValueNode.constantExpression(org.apache.derby.impl.sql.compile.PredicateList)

accept

public Visitable accept(Visitor v)
                 throws StandardException
Accept a visitor, and call v.visit() on child nodes as necessary.

Specified by:
accept in interface Visitable
Overrides:
accept in class QueryTreeNode
Parameters:
v - the visitor
Throws:
StandardException - on error

trimBind

private ValueNode trimBind()
                    throws StandardException
Bind trim expression.

Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

setResultType

private void setResultType(TypeId resultType)
                    throws StandardException
Throws:
StandardException

locateBind

public ValueNode locateBind()
                     throws StandardException
Bind locate operator

Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

castArgToString

protected ValueNode castArgToString(ValueNode vn)
                             throws StandardException
Throws:
StandardException

substrBind

public ValueNode substrBind()
                     throws StandardException
Bind substr expression.

Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

timestampAddBind

private ValueNode timestampAddBind()
                            throws StandardException
Bind TIMESTAMPADD expression.

Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

timestampDiffBind

private ValueNode timestampDiffBind()
                             throws StandardException
Bind TIMESTAMPDIFF expression.

Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

bindDateTimeArg

private void bindDateTimeArg(ValueNode arg,
                             int argNumber)
                      throws StandardException
Throws:
StandardException

bindParameter

private boolean bindParameter(ValueNode arg,
                              int jdbcType)
                       throws StandardException
Throws:
StandardException

getReceiver

public ValueNode getReceiver()

throwBadType

private void throwBadType(java.lang.String funcName,
                          java.lang.String type)
                   throws StandardException
Throws:
StandardException

bindToBuiltIn

protected void bindToBuiltIn()
                      throws StandardException
Throws:
StandardException

getVarcharDescriptor

private DataTypeDescriptor getVarcharDescriptor()

Built on Tue 2006-10-10 19:23:47+0200, from revision exported

Apache Derby V10.1 Engine Documentation - Copyright © 1997,2005 The Apache Software Foundation or its licensors, as applicable.