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

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.AggregateNode
All Implemented Interfaces:
Visitable

public class AggregateNode
extends UnaryOperatorNode

An Aggregate Node is a node that reprsents a set function/aggregate. It used for all system aggregates as well as user defined aggregates.


Field Summary
private  java.lang.Class aggregateDefinitionClass
           
private  java.lang.String aggregateDefinitionClassName
           
private  java.lang.String aggregateName
           
private  java.lang.StringBuffer aggregatorClassName
           
private  ClassInspector classInspector
           
private  boolean distinct
           
private  ResultColumn generatedRC
           
private  ColumnReference generatedRef
           
private  AggregateDefinition uad
           
 
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
AggregateNode()
           
 
Method Summary
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this operator.
private  void checkAggregatorClassName(java.lang.String className)
           
 boolean constantExpression(PredicateList where)
          Return whether or not this expression tree represents a constant value.
 void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb)
          Do code generation for this unary operator.
(package private)  AggregateDefinition getAggregateDefinition()
          Get the AggregateDefinition.
 java.lang.String getAggregateName()
          Get the class that implements that aggregator for this node.
 java.lang.String getAggregatorClassName()
          Get the class that implements that aggregator for this node.
 ResultColumn getGeneratedRC()
          Get the generated ResultColumn where this aggregate now resides after a call to replaceAggregatesWithColumnReference().
 ColumnReference getGeneratedRef()
          Get the generated ColumnReference to this aggregate after the parent called replaceAggregatesWithColumnReference().
 ResultColumn getNewAggregatorResultColumn(DataDictionary dd)
          Get the result column that has a new aggregator.
 ResultColumn getNewExpressionResultColumn(DataDictionary dd)
          Get the aggregate expression in a new result column.
 ValueNode getNewNullResultExpression()
          Get the null aggregate result expression column.
 void init(java.lang.Object operand, java.lang.Object uadClass, java.lang.Object distinct, java.lang.Object aggregateName)
          Intializer.
private  void instantiateAggDef()
           
 boolean isConstant()
           
 boolean isDistinct()
          Indicate whether this aggregate is distinct or not.
 ValueNode replaceAggregatesWithColumnReferences(ResultColumnList rcl, int tableNumber)
          Replace aggregates in the expression tree with a ColumnReference to that aggregate, append the aggregate to the supplied RCL (assumed to be from the child ResultSetNode) and return the ColumnReference.
 java.lang.String toString()
          Print a string ref of this node.
 
Methods inherited from class org.apache.derby.impl.sql.compile.UnaryOperatorNode
acceptChildren, addXmlOpMethodParams, bindOperand, bindParameter, categorize, getOperand, getOperatorString, getOrderableVariantType, getParameterOperand, getReceiverInterfaceName, init, init, isConstantExpression, isEquivalent, preprocess, printSubNodes, remapColumnReferencesToExpressions, setMethodName, setOperator
 
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, 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

distinct

private boolean distinct

uad

private AggregateDefinition uad

aggregatorClassName

private java.lang.StringBuffer aggregatorClassName

aggregateDefinitionClassName

private java.lang.String aggregateDefinitionClassName

aggregateDefinitionClass

private java.lang.Class aggregateDefinitionClass

classInspector

private ClassInspector classInspector

aggregateName

private java.lang.String aggregateName

generatedRC

private ResultColumn generatedRC

generatedRef

private ColumnReference generatedRef
Constructor Detail

AggregateNode

public AggregateNode()
Method Detail

init

public void init(java.lang.Object operand,
                 java.lang.Object uadClass,
                 java.lang.Object distinct,
                 java.lang.Object aggregateName)
          throws StandardException
Intializer. Used for user defined and internally defined aggregates. Called when binding a StaticMethodNode that we realize is an aggregate.

Overrides:
init in class QueryTreeNode
Parameters:
operand - the value expression for the aggregate
uadClass - the class name for user aggregate definition for the aggregate or the Class for the internal aggregate type.
distinct - boolean indicating whether this is distinct or not.
aggregateName - the name of the aggregate from the user's perspective, e.g. MAX
Throws:
StandardException - on error

replaceAggregatesWithColumnReferences

public ValueNode replaceAggregatesWithColumnReferences(ResultColumnList rcl,
                                                       int tableNumber)
                                                throws StandardException
Replace aggregates in the expression tree with a ColumnReference to that aggregate, append the aggregate to the supplied RCL (assumed to be from the child ResultSetNode) and return the ColumnReference. This is useful for pushing aggregates in the Having clause down to the user's select at parse time. It is also used for moving around Aggregates in the select list when creating the Group By node. In that case it is called after bind time, so we need to create the column differently.

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

getAggregateDefinition

AggregateDefinition getAggregateDefinition()
Get the AggregateDefinition.

Returns:
The AggregateDefinition

getGeneratedRC

public ResultColumn getGeneratedRC()
Get the generated ResultColumn where this aggregate now resides after a call to replaceAggregatesWithColumnReference().

Returns:
the result column

getGeneratedRef

public ColumnReference getGeneratedRef()
Get the generated ColumnReference to this aggregate after the parent called replaceAggregatesWithColumnReference().

Returns:
the column reference

bindExpression

public ValueNode bindExpression(FromList fromList,
                                SubqueryList subqueryList,
                                java.util.Vector aggregateVector)
                         throws StandardException
Bind this operator. Determine the type of the subexpression, and pass that into the UserAggregate.

Overrides:
bindExpression in class UnaryOperatorNode
Parameters:
fromList - The query's FROM list
subqueryList - The subquery list being built as we find SubqueryNodes
aggregateVector - The aggregate list being built as we find AggregateNodes
Returns:
The new top of the expression tree.
Throws:
StandardException - Thrown on error

checkAggregatorClassName

private void checkAggregatorClassName(java.lang.String className)
                               throws StandardException
Throws:
StandardException

instantiateAggDef

private void instantiateAggDef()
                        throws StandardException
Throws:
StandardException

isDistinct

public boolean isDistinct()
Indicate whether this aggregate is distinct or not.

Returns:
true/false

getAggregatorClassName

public java.lang.String getAggregatorClassName()
Get the class that implements that aggregator for this node.

Returns:
the class name

getAggregateName

public java.lang.String getAggregateName()
Get the class that implements that aggregator for this node.

Returns:
the class name

getNewAggregatorResultColumn

public ResultColumn getNewAggregatorResultColumn(DataDictionary dd)
                                          throws StandardException
Get the result column that has a new aggregator. This aggregator will be fed into the sorter.

Parameters:
dd - the data dictionary
Returns:
the result column. WARNING: it still needs to be bound
Throws:
StandardException - on error

getNewExpressionResultColumn

public ResultColumn getNewExpressionResultColumn(DataDictionary dd)
                                          throws StandardException
Get the aggregate expression in a new result column.

Parameters:
dd - the data dictionary
Returns:
the result column. WARNING: it still needs to be bound
Throws:
StandardException - on error

getNewNullResultExpression

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

Returns:
the value node
Throws:
StandardException - on error

generateExpression

public void generateExpression(ExpressionClassBuilder acb,
                               MethodBuilder mb)
                        throws StandardException
Do code generation for this unary operator. Should never be called for an aggregate -- it should be converted into something else by code generation time.

Overrides:
generateExpression in class UnaryOperatorNode
Parameters:
acb - The ExpressionClassBuilder for the class we're generating
mb - The method the code to place the code
Throws:
StandardException - Thrown on error

toString

public java.lang.String toString()
Print a string ref of this node.

Overrides:
toString in class UnaryOperatorNode
Returns:
a string representation of this node

isConstant

public boolean isConstant()

constantExpression

public boolean constantExpression(PredicateList where)
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 UnaryOperatorNode
Returns:
True means this expression tree represents a constant value.
See Also:
ValueNode.constantExpression(org.apache.derby.impl.sql.compile.PredicateList)

Built on Thu 2011-03-10 11:54:14+0000, from revision ???

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