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

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.UnaryOperatorNode
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
AggregateNode, DB2LengthOperatorNode, ExtractOperatorNode, LengthOperatorNode, QuantifiedUnaryOperatorNode, SimpleStringOperatorNode, UnaryArithmeticOperatorNode, UnaryComparisonOperatorNode, UnaryDateTimestampOperatorNode, UnaryLogicalOperatorNode

public class UnaryOperatorNode
extends ValueNode

A UnaryOperatorNode represents a built-in unary operator as defined by the ANSI/ISO SQL standard. This covers operators like +, -, NOT, and IS NULL. Java operators are not represented here: the JSQL language allows Java methods to be called from expressions, but not Java operators.

Author:
Jeff Lichtman

Field Summary
private  java.lang.Object[] additionalArgs
           
static int IS_NULL
           
(package private)  java.lang.String methodName
           
static int NOT
           
(package private)  ValueNode operand
          WARNING: operand may be NULL for COUNT(*).
(package private)  java.lang.String operator
           
(package private)  int operatorType
           
(package private)  java.lang.String receiverInterfaceType
           
(package private)  java.lang.String resultInterfaceType
           
static int UNARY_MINUS
           
static int UNARY_PLUS
           
(package private) static java.lang.String[] UnaryArgTypes
           
(package private) static java.lang.String[] UnaryMethodNames
           
(package private) static java.lang.String[] UnaryOperators
           
(package private) static java.lang.String[] UnaryResultTypes
           
static int XMLPARSE_OP
           
static int XMLSERIALIZE_OP
           
 
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
UnaryOperatorNode()
           
 
Method Summary
 Visitable accept(Visitor v)
          Accept a visitor, and call v.visit() on child nodes as necessary.
protected  int addMethodParams(MethodBuilder mb)
          This method allows different operators to add primitive arguments to the generated method call, if needed.
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this expression.
(package private)  void bindParameter()
          By default unary operators don't accept ?
protected  ValueNode bindUnaryOperator(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Workhorse for bindExpression.
 void bindXMLParse()
          Bind an XMLPARSE operator.
 void bindXMLSerialize()
          Bind an XMLSERIALIZE operator.
 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 unary operator.
 ValueNode getOperand()
          Get the operand of this unary operator.
(package private)  java.lang.String getOperatorString()
          Get the operator of this unary operator.
protected  int getOrderableVariantType()
          Return the variant type for the underlying expression.
 java.lang.String getReceiverInterfaceName()
          Determine the type the binary method is called on.
 void init(java.lang.Object operand)
          Initializer for a UnaryOperatorNode
 void init(java.lang.Object operand, java.lang.Object operatorOrOpType, java.lang.Object methodNameOrAddedArgs)
          Initializer for a UnaryOperatorNode
 boolean isConstantExpression()
          Return whether or not this expression tree represents a constant expression.
 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.
(package private)  void setMethodName(java.lang.String methodName)
          Set the methodName.
(package private)  void setOperator(java.lang.String operator)
          Set the operator.
 java.lang.String toString()
          Convert this object to a String.
 
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, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, getTypeServices, init, 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, 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

resultInterfaceType

java.lang.String resultInterfaceType

receiverInterfaceType

java.lang.String receiverInterfaceType

operand

ValueNode operand
WARNING: operand may be NULL for COUNT(*).


UNARY_PLUS

public static final int UNARY_PLUS
See Also:
Constant Field Values

UNARY_MINUS

public static final int UNARY_MINUS
See Also:
Constant Field Values

NOT

public static final int NOT
See Also:
Constant Field Values

IS_NULL

public static final int IS_NULL
See Also:
Constant Field Values

XMLPARSE_OP

public static final int XMLPARSE_OP
See Also:
Constant Field Values

XMLSERIALIZE_OP

public static final int XMLSERIALIZE_OP
See Also:
Constant Field Values

UnaryOperators

static final java.lang.String[] UnaryOperators

UnaryMethodNames

static final java.lang.String[] UnaryMethodNames

UnaryResultTypes

static final java.lang.String[] UnaryResultTypes

UnaryArgTypes

static final java.lang.String[] UnaryArgTypes

additionalArgs

private java.lang.Object[] additionalArgs
Constructor Detail

UnaryOperatorNode

public UnaryOperatorNode()
Method Detail

init

public void init(java.lang.Object operand,
                 java.lang.Object operatorOrOpType,
                 java.lang.Object methodNameOrAddedArgs)
Initializer for a UnaryOperatorNode

Overrides:
init in class QueryTreeNode
Parameters:
operand - The operand of the node
operatorOrOpType - Either 1) the name of the operator, OR 2) an Integer holding the operatorType for this operator.

init

public void init(java.lang.Object operand)
Initializer for a UnaryOperatorNode

Overrides:
init in class QueryTreeNode
Parameters:
operand - The operand of the node

setOperator

void setOperator(java.lang.String operator)
Set the operator.

Parameters:
operator - The operator.
Returns:
Nothing.

getOperatorString

java.lang.String getOperatorString()
Get the operator of this unary operator.

Returns:
The operator of this unary operator.

setMethodName

void setMethodName(java.lang.String methodName)
Set the methodName.

Parameters:
methodName - The methodName.
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

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

getOperand

public ValueNode getOperand()
Get the operand of this unary operator.

Returns:
The operand of this unary operator.

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.

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

bindUnaryOperator

protected ValueNode bindUnaryOperator(FromList fromList,
                                      SubqueryList subqueryList,
                                      java.util.Vector aggregateVector)
                               throws StandardException
Workhorse for bindExpression. This exists so it can be called by child classes.

Throws:
StandardException

bindXMLParse

public void bindXMLParse()
                  throws StandardException
Bind an XMLPARSE operator. Makes sure the operand type is correct, and sets the result type.

Throws:
StandardException - Thrown on error

bindXMLSerialize

public void bindXMLSerialize()
                      throws StandardException
Bind an XMLSERIALIZE operator. Makes sure the operand type and target type are both correct, and sets the result type.

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

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)

bindParameter

void bindParameter()
             throws StandardException
By default unary operators don't accept ? parameters as operands. This can be over-ridden for particular unary operators. We throw an exception if the parameter doesn't have a datatype assigned to it yet.

Returns:
Nothing
Throws:
StandardException - Thrown if ? parameter doesn't have a type bound to it yet. ? parameter where it isn't allowed.

generateExpression

public void generateExpression(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
Do code generation for this unary 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

getReceiverInterfaceName

public java.lang.String getReceiverInterfaceName()
                                          throws StandardException
Determine the type the binary method is called on. By default, based on the receiver. Override in nodes that use methods on super-interfaces of the receiver's interface, such as comparisons.

Throws:
StandardException - Thrown on error

getOrderableVariantType

protected int getOrderableVariantType()
                               throws StandardException
Return the variant type for the underlying expression. The variant type can be: VARIANT - variant within a scan (method calls and non-static field access) SCAN_INVARIANT - invariant within a scan (column references from outer tables) QUERY_INVARIANT - invariant within the life of a query (constant expressions) CONSTANT - immutable

Overrides:
getOrderableVariantType in class ValueNode
Returns:
The variant type for the underlying expression.
Throws:
StandardException - thrown on error

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

addMethodParams

protected int addMethodParams(MethodBuilder mb)
This method allows different operators to add primitive arguments to the generated method call, if needed.

Parameters:
mb - The MethodBuilder that will make the call.
Returns:
Number of parameters added.

Built on Mon 2007-06-04 09:58:47+0400, from revision ???

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