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

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
              extended byorg.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.

Author:
jamie

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
IS_NULL, methodName, NOT, operand, operator, UNARY_MINUS, UNARY_PLUS
 
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
AggregateNode()
           
 
Method Summary
 ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.Vector aggregateVector)
          Bind this operator.
private  void checkAggregatorClassName(java.lang.String className)
           
 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 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
accept, bindParameter, bindUnaryOperator, categorize, constantExpression, getOperand, getOperatorString, getOrderableVariantType, getReceiverInterfaceName, init, init, isConstantExpression, preprocess, printSubNodes, remapColumnReferencesToExpressions, setClause, setMethodName, setOperator
 
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, 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, isAtomic, isInstanceOf, isSessionSchema, isSessionSchema, makeConstantAction, makeResultDescription, makeTableName, needsSavepoint, nodeHeader, optimize, parseQueryText, printLabel, referencesSessionSchema, 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

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:
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.

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.

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
Returns:
An expression to evaluate this operator
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


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