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
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 ClassesModifier and TypeClassDescription(package private) static final class -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Class<?> private Stringprivate Stringprivate StringBufferprivate static AggregateNode.BuiltinAggDescriptor[]private ClassInspectorprivate booleanprivate ResultColumnprivate ColumnReferenceprivate AggregateDefinitionprivate TableNameFields inherited from class UnaryOperatorNode
K_BASE, K_XMLPARSE, K_XMLSERIALIZE, kind, methodName, operand, operator, receiverInterfaceType, resultInterfaceType, UnaryArgTypes, UnaryMethodNames, UnaryOperators, UnaryResultTypesFields inherited from class ValueNode
transformedFields inherited from class QueryTreeNode
AUTOINCREMENT_CREATE_MODIFY, AUTOINCREMENT_CYCLE, AUTOINCREMENT_INC_INDEX, AUTOINCREMENT_IS_AUTOINCREMENT_INDEX, AUTOINCREMENT_START_INDEX -
Constructor Summary
ConstructorsConstructorDescriptionAggregateNode(ValueNode operand, Class<?> uadClass, boolean distinct, String aggregateName, ContextManager cm) AggregateNode(ValueNode operand, TableName uadClass, boolean distinct, String aggregateName, ContextManager cm) AggregateNode(ValueNode operand, UserAggregateDefinition uadClass, TableName alias, boolean distinct, String aggregateName, ContextManager cm) Constructed when binding a StaticMethodNode that we realize is an aggregate. -
Method Summary
Modifier and TypeMethodDescription(package private) voidAccept the visitor for all visitable children of this node.(package private) ValueNodebindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) Bind this operator.private voidcheckAggregatorClassName(String className) (package private) booleanconstantExpression(PredicateList where) Return whether or not this expression tree represents a constant value.(package private) voidDo code generation for this unary operator.(package private) AggregateDefinitionGet the AggregateDefinition.(package private) StringGet the class that implements that aggregator for this node.(package private) StringGet the class that implements that aggregator for this node.(package private) ResultColumnGet the generated ResultColumn where this aggregate now resides after a call to replaceAggregatesWithColumnReference().(package private) ColumnReferenceGet the generated ColumnReference to this aggregate after the parent called replaceAggregatesWithColumnReference().(package private) ResultColumnGet the result column that has a new aggregator.(package private) ResultColumnGet the aggregate expression in a new result column.(package private) ValueNodeGet the null aggregate result expression column.Get the SQL name of the aggregateprivate void(package private) boolean(package private) booleanIndicate whether this aggregate is distinct or not.private booleanReturn 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, String rawName, boolean noSchema) Resolve a user-defined aggregate.private static AliasDescriptorresolveBuiltinAggregate(DataDictionary dd, String rawName, boolean noSchema) Construct an AliasDescriptor for a modern builtin aggregate.private voidinitialize fields for user defined aggregatetoString()Print a string ref of this node.Methods inherited from class UnaryOperatorNode
addXmlOpMethodParams, bindOperand, bindParameter, categorize, getOperand, getOperatorString, getOrderableVariantType, getParameterOperand, getReceiverInterfaceName, isConstantExpression, isEquivalent, isSameNodeKind, preprocess, printSubNodes, remapColumnReferencesToExpressions, setMethodName, setOperatorMethods inherited from class OperatorNode
pushSqlXmlUtilMethods inherited from class 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, verifyPutAndsOnTopMethods inherited from class 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 Details
-
BUILTIN_MODERN_AGGS
-
distinct
private boolean distinct -
uad
-
userAggregateName
-
aggregatorClassName
-
aggregateDefinitionClassName
-
aggregateDefinitionClass
-
classInspector
-
aggregateName
-
generatedRC
-
generatedRef
-
-
Constructor Details
-
AggregateNode
AggregateNode(ValueNode operand, UserAggregateDefinition uadClass, TableName alias, boolean distinct, 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, 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, Class<?> uadClass, boolean distinct, 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 Details
-
setUserDefinedAggregate
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, 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, String rawName, boolean noSchema) throws StandardException Resolve a user-defined aggregate.- Throws:
StandardException
-
resolveBuiltinAggregate
private static AliasDescriptor resolveBuiltinAggregate(DataDictionary dd, String rawName, boolean noSchema) throws StandardException Construct an AliasDescriptor for a modern builtin aggregate.- Throws:
StandardException
-
checkAggregatorClassName
- Throws:
StandardException
-
instantiateAggDef
- Throws:
StandardException
-
isDistinct
boolean isDistinct()Indicate whether this aggregate is distinct or not.- Returns:
- true/false
-
getAggregatorClassName
String getAggregatorClassName()Get the class that implements that aggregator for this node.- Returns:
- the class name
-
getAggregateName
String getAggregateName()Get the class that implements that aggregator for this node.- Returns:
- the class name
-
getNewAggregatorResultColumn
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
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
Get the null aggregate result expression column.- Returns:
- the value node
- Throws:
StandardException- on error
-
generateExpression
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
Print a string ref of this node.- Overrides:
toStringin classUnaryOperatorNode- Returns:
- a string representation of this node
-
isConstant
boolean isConstant() -
constantExpression
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:
-
getSQLName
Get the SQL name of the aggregate -
isUserDefinedAggregate
private boolean isUserDefinedAggregate()Return true if this is a user-defined aggregate -
acceptChildren
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
-