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

java.lang.Object
  extended by org.apache.derby.impl.sql.compile.QueryTreeNode
      extended by org.apache.derby.impl.sql.compile.ValueNode
          extended by org.apache.derby.impl.sql.compile.UnaryOperatorNode
              extended by org.apache.derby.impl.sql.compile.WindowFunctionNode
All Implemented Interfaces:
Visitable
Direct Known Subclasses:
AggregateWindowFunctionNode, RowNumberFunctionNode

public abstract class WindowFunctionNode
extends UnaryOperatorNode

Superclass of any window function call.


Field Summary
private  ResultColumn generatedRC
           
private  ColumnReference generatedRef
           
private  WindowNode window
           
 
Fields inherited from class org.apache.derby.impl.sql.compile.UnaryOperatorNode
methodName, operand, operator, receiverInterfaceType, resultInterfaceType, UnaryArgTypes, UnaryMethodNames, UnaryOperators, UnaryResultTypes, XMLPARSE_OP, XMLSERIALIZE_OP
 
Fields inherited from class org.apache.derby.impl.sql.compile.ValueNode
transformed
 
Fields inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX, isPrivilegeCollectionRequired
 
Constructor Summary
WindowFunctionNode()
           
 
Method Summary
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          ValueNode override.
 boolean constantExpression(PredicateList whereClause)
          ValueNode override.
private  WindowDefinitionNode definedWindow(WindowList windows, java.lang.String name)
           
 ColumnReference getGeneratedRef()
          Get the generated ColumnReference to this window function after the parent called replaceCallsWithColumnReferences().
 ValueNode getNewNullResultExpression()
          Get the null result expression column.
 WindowNode getWindow()
           
 void init(java.lang.Object arg1, java.lang.Object arg2, java.lang.Object arg3)
          Initializer for a WindowFunctionNode
 boolean isConstantExpression()
          ValueNode override.
 void printSubNodes(int depth)
          QueryTreeNode override.
 ValueNode replaceCallsWithColumnReferences(ResultColumnList rcl, int tableNumber)
          Replace window function calls in the expression tree with a ColumnReference to that window function, append the aggregate to the supplied RCL (assumed to be from the child ResultSetNode) and return the ColumnReference.
 void setWindow(WindowDefinitionNode wdn)
          Set window associated with this window function call.
 
Methods inherited from class org.apache.derby.impl.sql.compile.UnaryOperatorNode
acceptChildren, addXmlOpMethodParams, bindOperand, bindParameter, categorize, generateExpression, getOperand, getOperatorString, getOrderableVariantType, getParameterOperand, getReceiverInterfaceName, init, isEquivalent, preprocess, remapColumnReferencesToExpressions, setMethodName, setOperator, toString
 
Methods inherited from class org.apache.derby.impl.sql.compile.ValueNode
bindExpression, changeToCNF, checkIsBoolean, checkTopPredicatesForEqualsConditions, copyFields, eliminateNots, evaluateConstantExpressions, genEqualsFalseTree, generate, generateFilter, genIsNullTree, genSQLJavaSQLTree, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, getTypeServices, init, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isCloneable, isInListProbeNode, isParameterNode, isRelationalOperator, isSameNodeType, optimizableEqualityNode, putAndsOnTop, requiresTypeFromContext, selectivity, setCollationInfo, setCollationInfo, setCollationUsingCompilationSchema, setCollationUsingCompilationSchema, setNullability, setTransformed, setType, setType, setType, updatableByCursor, verifyChangeToCNF, verifyEliminateNots, verifyPutAndsOnTop
 
Methods inherited from class org.apache.derby.impl.sql.compile.QueryTreeNode
accept, bindOffsetFetch, bindRowMultiSet, bindUserType, checkReliability, checkReliability, convertDefaultNode, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, foundString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContextManager, getCursorInfo, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getNodeFactory, getNodeType, getNullNode, getParameterTypes, getRowEstimate, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, init, init, init, init, init, init, init, init, init, init, init, isAtomic, isInstanceOf, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, orReliability, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setContextManager, setEndOffset, setNodeType, setRefActionInfo, stackPrint, treePrint, treePrint, verifyClassExist
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

window

private WindowNode window

generatedRC

private ResultColumn generatedRC

generatedRef

private ColumnReference generatedRef
Constructor Detail

WindowFunctionNode

public WindowFunctionNode()
Method Detail

init

public void init(java.lang.Object arg1,
                 java.lang.Object arg2,
                 java.lang.Object arg3)
Initializer for a WindowFunctionNode

Overrides:
init in class UnaryOperatorNode
Parameters:
arg1 - null (operand)
arg2 - function mame (operator)
arg3 - window node (definition or reference)
Throws:
StandardException

isConstantExpression

public boolean isConstantExpression()
ValueNode override.

Overrides:
isConstantExpression in class UnaryOperatorNode
Returns:
Whether or not this expression tree represents a constant expression.
See Also:
ValueNode.isConstantExpression()

constantExpression

public boolean constantExpression(PredicateList whereClause)
ValueNode override.

Overrides:
constantExpression in class UnaryOperatorNode
Returns:
True means this expression tree represents a constant value.
See Also:
ValueNode.isConstantExpression()

getWindow

public WindowNode getWindow()
Returns:
window associated with this window function

setWindow

public void setWindow(WindowDefinitionNode wdn)
Set window associated with this window function call.

Parameters:
wdn - window definition

bindExpression

public ValueNode bindExpression(FromList fromList,
                                SubqueryList subqueryList,
                                java.util.Vector aggregateVector)
                         throws StandardException
ValueNode override.

Overrides:
bindExpression in class UnaryOperatorNode
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
See Also:
ValueNode.bindExpression(org.apache.derby.impl.sql.compile.FromList, org.apache.derby.impl.sql.compile.SubqueryList, java.util.Vector)

definedWindow

private WindowDefinitionNode definedWindow(WindowList windows,
                                           java.lang.String name)
Returns:
if name matches a defined window (in windows), return the definition of that window, else null.

printSubNodes

public void printSubNodes(int depth)
QueryTreeNode override.

Overrides:
printSubNodes in class UnaryOperatorNode
Parameters:
depth - The depth of this node in the tree
See Also:
QueryTreeNode.printSubNodes(int)

replaceCallsWithColumnReferences

public ValueNode replaceCallsWithColumnReferences(ResultColumnList rcl,
                                                  int tableNumber)
                                           throws StandardException
Replace window function calls in the expression tree with a ColumnReference to that window function, append the aggregate to the supplied RCL (assumed to be from the child ResultSetNode) and return the ColumnReference.

Parameters:
rcl - The RCL to append to.
tableNumber - The tableNumber for the new ColumnReference
Returns:
ValueNode The (potentially) modified tree.
Throws:
StandardException - Thrown on error

getGeneratedRef

public ColumnReference getGeneratedRef()
Get the generated ColumnReference to this window function after the parent called replaceCallsWithColumnReferences().

There are cases where this will not have been done because the tree has been re-written to eliminate the window function, e.g. for this query:

     SELECT * FROM t WHERE EXISTS
           (SELECT ROW_NUMBER() OVER () FROM t)
 

in which case the top PRN of the subquery sitting over a WindowResultSetNode just contains a RC which is boolean constant true. This means that the replaceCallsWithColumnReferences will not have been called for this, so the returned generatedRef is null.

Returns:
the column reference

getNewNullResultExpression

public ValueNode getNewNullResultExpression()
                                     throws StandardException
Get the null result expression column.

Returns:
the value node
Throws:
StandardException - on error

Built on Thu 2012-03-29 21:53:33+0000, from revision ???

Apache Derby V10.6 Internals - Copyright © 2004,2007 The Apache Software Foundation. All Rights Reserved.