Class AggregateNode
- java.lang.Object
-
- org.apache.derby.impl.sql.compile.QueryTreeNode
-
- org.apache.derby.impl.sql.compile.ValueNode
-
- org.apache.derby.impl.sql.compile.OperatorNode
-
- org.apache.derby.impl.sql.compile.UnaryOperatorNode
-
- org.apache.derby.impl.sql.compile.AggregateNode
-
- All Implemented Interfaces:
Visitable
class AggregateNode extends UnaryOperatorNode
An Aggregate Node is a node that represents a set function/aggregate. It used for all system aggregates as well as user defined aggregates.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classAggregateNode.BuiltinAggDescriptor
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Class<?>aggregateDefinitionClassprivate java.lang.StringaggregateDefinitionClassNameprivate java.lang.StringaggregateNameprivate java.lang.StringBufferaggregatorClassNameprivate static AggregateNode.BuiltinAggDescriptor[]BUILTIN_MODERN_AGGSprivate ClassInspectorclassInspectorprivate booleandistinctprivate ResultColumngeneratedRCprivate ColumnReferencegeneratedRefprivate AggregateDefinitionuadprivate TableNameuserAggregateName-
Fields inherited from class org.apache.derby.impl.sql.compile.UnaryOperatorNode
K_BASE, K_XMLPARSE, K_XMLSERIALIZE, kind, methodName, operand, operator, receiverInterfaceType, resultInterfaceType, UnaryArgTypes, UnaryMethodNames, UnaryOperators, UnaryResultTypes
-
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_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX
-
-
Constructor Summary
Constructors Constructor Description AggregateNode(ValueNode operand, java.lang.Class<?> uadClass, boolean distinct, java.lang.String aggregateName, ContextManager cm)AggregateNode(ValueNode operand, TableName uadClass, boolean distinct, java.lang.String aggregateName, ContextManager cm)AggregateNode(ValueNode operand, UserAggregateDefinition uadClass, TableName alias, boolean distinct, java.lang.String aggregateName, ContextManager cm)Constructed when binding a StaticMethodNode that we realize is an aggregate.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) voidacceptChildren(Visitor v)Accept the visitor for all visitable children of this node.(package private) ValueNodebindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates)Bind this operator.private voidcheckAggregatorClassName(java.lang.String className)(package private) booleanconstantExpression(PredicateList where)Return whether or not this expression tree represents a constant value.(package private) voidgenerateExpression(ExpressionClassBuilder acb, MethodBuilder mb)Do code generation for this unary operator.(package private) AggregateDefinitiongetAggregateDefinition()Get the AggregateDefinition.(package private) java.lang.StringgetAggregateName()Get the class that implements that aggregator for this node.(package private) java.lang.StringgetAggregatorClassName()Get the class that implements that aggregator for this node.(package private) ResultColumngetGeneratedRC()Get the generated ResultColumn where this aggregate now resides after a call to replaceAggregatesWithColumnReference().(package private) ColumnReferencegetGeneratedRef()Get the generated ColumnReference to this aggregate after the parent called replaceAggregatesWithColumnReference().(package private) ResultColumngetNewAggregatorResultColumn(DataDictionary dd)Get the result column that has a new aggregator.(package private) ResultColumngetNewExpressionResultColumn(DataDictionary dd)Get the aggregate expression in a new result column.(package private) ValueNodegetNewNullResultExpression()Get the null aggregate result expression column.java.lang.StringgetSQLName()Get the SQL name of the aggregateprivate voidinstantiateAggDef()(package private) booleanisConstant()(package private) booleanisDistinct()Indicate whether this aggregate is distinct or not.private booleanisUserDefinedAggregate()Return true if this is a user-defined aggregate(package private) ValueNodereplaceAggregatesWithColumnReferences(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.(package private) static AliasDescriptorresolveAggregate(DataDictionary dd, SchemaDescriptor sd, java.lang.String rawName, boolean noSchema)Resolve a user-defined aggregate.private static AliasDescriptorresolveBuiltinAggregate(DataDictionary dd, java.lang.String rawName, boolean noSchema)Construct an AliasDescriptor for a modern builtin aggregate.private voidsetUserDefinedAggregate(UserAggregateDefinition userAgg)initialize fields for user defined aggregatejava.lang.StringtoString()Print a string ref of this node.-
Methods inherited from class org.apache.derby.impl.sql.compile.UnaryOperatorNode
addXmlOpMethodParams, bindOperand, bindParameter, categorize, getOperand, getOperatorString, getOrderableVariantType, getParameterOperand, getReceiverInterfaceName, isConstantExpression, isEquivalent, isSameNodeKind, preprocess, printSubNodes, remapColumnReferencesToExpressions, setMethodName, setOperator
-
Methods inherited from class org.apache.derby.impl.sql.compile.OperatorNode
pushSqlXmlUtil
-
Methods inherited from class org.apache.derby.impl.sql.compile.ValueNode
bindExpression, changeToCNF, checkIsBoolean, checkTopPredicatesForEqualsConditions, copyFields, eliminateNots, evaluateConstantExpressions, genEqualsFalseTree, generate, genIsNullTree, genSQLJavaSQLTree, getClone, getColumnName, getConstantValueAsObject, getDataValueFactory, getSchemaName, getSourceResultColumn, getTableName, getTablesReferenced, getTransformed, getTypeCompiler, getTypeId, getTypeServices, isBinaryEqualsOperatorNode, isBooleanFalse, isBooleanTrue, isCloneable, isInListProbeNode, isParameterNode, isRelationalOperator, 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, addTag, addUDTUsagePriv, addUDTUsagePriv, bindOffsetFetch, bindRowMultiSet, bindUserCatalogType, bindUserType, checkReliability, checkReliability, convertDefaultNode, copyTagsFrom, createTypeDependency, debugFlush, debugPrint, disablePrivilegeCollection, formatNodeString, generateAuthorizeCheck, getBeginOffset, getClassFactory, getCompilerContext, getContext, getContextManager, getDataDictionary, getDependencyManager, getEndOffset, getExecutionFactory, getGenericConstantActionFactory, getIntProperty, getLanguageConnectionContext, getLongProperty, getNullNode, getOffsetOrderedNodes, getOptimizerFactory, getOptimizerTracer, getParameterTypes, getSchemaDescriptor, getSchemaDescriptor, getStatementType, getTableDescriptor, getTypeCompiler, getUDTDesc, isAtomic, isPrivilegeCollectionRequired, isSessionSchema, isSessionSchema, makeConstantAction, makeTableName, makeTableName, nodeHeader, optimizerTracingIsOn, orReliability, parseSearchCondition, parseStatement, printLabel, referencesSessionSchema, resolveTableToSynonym, setBeginOffset, setEndOffset, setRefActionInfo, stackPrint, taggedWith, treePrint, treePrint, verifyClassExist
-
-
-
-
Field Detail
-
BUILTIN_MODERN_AGGS
private static AggregateNode.BuiltinAggDescriptor[] BUILTIN_MODERN_AGGS
-
distinct
private boolean distinct
-
uad
private AggregateDefinition uad
-
userAggregateName
private TableName userAggregateName
-
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
AggregateNode(ValueNode operand, UserAggregateDefinition uadClass, TableName alias, boolean distinct, java.lang.String aggregateName, ContextManager cm) throws StandardException
Constructed when binding a StaticMethodNode that we realize is an aggregate.- Parameters:
operand- the value expression for the aggregateuadClass- the class of the user aggregate definitionalias- the name by which the aggregate was calleddistinct- boolean indicating whether this is distinct or not.aggregateName- the name of the aggregate from the user's perspective, e.g. MAXcm- context manager- Throws:
StandardException
-
AggregateNode
AggregateNode(ValueNode operand, TableName uadClass, boolean distinct, java.lang.String aggregateName, ContextManager cm) throws StandardException
- Parameters:
operand- the value expression for the aggregateuadClass- the class name for user aggregate definition for the aggregatedistinct- boolean indicating whether this is distinct or not.aggregateName- the name of the aggregate from the user's perspective, e.g. MAXcm- context manager- Throws:
StandardException
-
AggregateNode
AggregateNode(ValueNode operand, java.lang.Class<?> uadClass, boolean distinct, java.lang.String aggregateName, ContextManager cm) throws StandardException
- Parameters:
operand- the value expression for the aggregateuadClass- Class for the internal aggregate typedistinct- boolean indicating whether this is distinct or not.aggregateName- the name of the aggregate from the user's perspective, e.g. MAXcm- context manager- Throws:
StandardException
-
-
Method Detail
-
setUserDefinedAggregate
private void setUserDefinedAggregate(UserAggregateDefinition userAgg)
initialize fields for user defined aggregate
-
replaceAggregatesWithColumnReferences
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
ResultColumn getGeneratedRC()
Get the generated ResultColumn where this aggregate now resides after a call to replaceAggregatesWithColumnReference().- Returns:
- the result column
-
getGeneratedRef
ColumnReference getGeneratedRef()
Get the generated ColumnReference to this aggregate after the parent called replaceAggregatesWithColumnReference().- Returns:
- the column reference
-
bindExpression
ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, java.util.List<AggregateNode> aggregates) throws StandardException
Bind this operator. Determine the type of the subexpression, and pass that into the UserAggregate.- Overrides:
bindExpressionin classUnaryOperatorNode- Parameters:
fromList- The query's FROM listsubqueryList- The subquery list being built as we find SubqueryNodesaggregates- The aggregate list being built as we find AggregateNodes- Returns:
- The new top of the expression tree.
- Throws:
StandardException- Thrown on error
-
resolveAggregate
static AliasDescriptor resolveAggregate(DataDictionary dd, SchemaDescriptor sd, java.lang.String rawName, boolean noSchema) throws StandardException
Resolve a user-defined aggregate.- Throws:
StandardException
-
resolveBuiltinAggregate
private static AliasDescriptor resolveBuiltinAggregate(DataDictionary dd, java.lang.String rawName, boolean noSchema) throws StandardException
Construct an AliasDescriptor for a modern builtin aggregate.- Throws:
StandardException
-
checkAggregatorClassName
private void checkAggregatorClassName(java.lang.String className) throws StandardException- Throws:
StandardException
-
instantiateAggDef
private void instantiateAggDef() throws StandardException- Throws:
StandardException
-
isDistinct
boolean isDistinct()
Indicate whether this aggregate is distinct or not.- Returns:
- true/false
-
getAggregatorClassName
java.lang.String getAggregatorClassName()
Get the class that implements that aggregator for this node.- Returns:
- the class name
-
getAggregateName
java.lang.String getAggregateName()
Get the class that implements that aggregator for this node.- Returns:
- the class name
-
getNewAggregatorResultColumn
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
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
ValueNode getNewNullResultExpression() throws StandardException
Get the null aggregate result expression column.- Returns:
- the value node
- Throws:
StandardException- on error
-
generateExpression
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:
generateExpressionin classUnaryOperatorNode- Parameters:
acb- The ExpressionClassBuilder for the class we're generatingmb- 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:
toStringin classUnaryOperatorNode- Returns:
- a string representation of this node
-
isConstant
boolean isConstant()
-
constantExpression
boolean constantExpression(PredicateList where)
Description copied from class:ValueNodeReturn 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:
constantExpressionin classUnaryOperatorNode- Returns:
- True means this expression tree represents a constant value.
- See Also:
ValueNode.constantExpression(org.apache.derby.impl.sql.compile.PredicateList)
-
getSQLName
public java.lang.String getSQLName()
Get the SQL name of the aggregate
-
isUserDefinedAggregate
private boolean isUserDefinedAggregate()
Return true if this is a user-defined aggregate
-
acceptChildren
void acceptChildren(Visitor v) throws StandardException
Description copied from class:UnaryOperatorNodeAccept the visitor for all visitable children of this node.- Overrides:
acceptChildrenin classUnaryOperatorNode- Parameters:
v- the visitor- Throws:
StandardException- on error
-
-