Top Description Inners Fields Constructors Methods
org.apache.derby.impl.sql.compile

pack-priv Class AggregateNode

extends UnaryOperatorNode
Class Inheritance
Imports
java.util.List, org.apache.derby.catalog.AliasInfo, .TypeDescriptor, org.apache.derby.catalog.types.AggregateAliasInfo, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.iapi.services.compiler.MethodBuilder, org.apache.derby.iapi.services.context.ContextManager, org.apache.derby.iapi.services.loader.ClassFactory, .ClassInspector, org.apache.derby.shared.common.sanity.SanityManager, org.apache.derby.iapi.sql.compile.CompilerContext, .Visitor, org.apache.derby.iapi.sql.dictionary.AliasDescriptor, .DataDictionary, .SchemaDescriptor, org.apache.derby.iapi.types.DataTypeDescriptor

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 and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static class

Field Summary

Modifier and TypeField and Description
private Class<?>
private String
private String
private StringBuffer
private static AggregateNode.BuiltinAggDescriptor[]
private ClassInspector
private boolean
private ResultColumn
private ColumnReference
private AggregateDefinition
private TableName
Inherited from org.apache.derby.impl.sql.compile.UnaryOperatorNode:
K_BASEK_XMLPARSEK_XMLSERIALIZEkindmethodNameoperandoperatorreceiverInterfaceTyperesultInterfaceTypeUnaryArgTypesUnaryMethodNamesUnaryOperatorsUnaryResultTypes

Constructor Summary

AccessConstructor and Description
pack-priv
AggregateNode(ValueNode
the value expression for the aggregate
operand
,
UserAggregateDefinition
the class of the user aggregate definition
uadClass
,
TableName
the name by which the aggregate was called
alias
,
boolean
boolean indicating whether this is distinct or not.
distinct
,
String
the name of the aggregate from the user's perspective, e.g. MAX
aggregateName
,
ContextManager
context manager
cm
)

Constructed when binding a StaticMethodNode that we realize is an aggregate.

pack-priv
AggregateNode(ValueNode
the value expression for the aggregate
operand
,
TableName
the class name for user aggregate definition for the aggregate
uadClass
,
boolean
boolean indicating whether this is distinct or not.
distinct
,
String
the name of the aggregate from the user's perspective, e.g. MAX
aggregateName
,
ContextManager
context manager
cm
)

pack-priv
AggregateNode(ValueNode
the value expression for the aggregate
operand
,
Class<?>
Class for the internal aggregate type
uadClass
,
boolean
boolean indicating whether this is distinct or not.
distinct
,
String
the name of the aggregate from the user's perspective, e.g. MAX
aggregateName
,
ContextManager
context manager
cm
)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
acceptChildren(Visitor
the visitor
v
)

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.acceptChildren.

Accept the visitor for all visitable children of this node.

pack-priv ValueNode

Returns:

The new top of the expression tree.
bindExpression
(FromList
The query's FROM list
fromList
,
SubqueryList
The subquery list being built as we find SubqueryNodes
subqueryList
,
List<AggregateNode>
The aggregate list being built as we find AggregateNodes
aggregates
)

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.bindExpression.

Bind this operator.

private void
pack-priv boolean
constantExpression(PredicateList where)

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.constantExpression.

Return whether or not this expression tree represents a constant value.

pack-priv void
generateExpression(ExpressionClassBuilder
The ExpressionClassBuilder for the class we're generating
acb
,
MethodBuilder
The method the code to place the code
mb
)

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.generateExpression.

Do code generation for this unary operator.

pack-priv AggregateDefinition

Returns:

The AggregateDefinition
getAggregateDefinition
()

Get the AggregateDefinition.

pack-priv String

Returns:

the class name
getAggregateName
()

Get the class that implements that aggregator for this node.

pack-priv String

Returns:

the class name
getAggregatorClassName
()

Get the class that implements that aggregator for this node.

pack-priv ResultColumn

Returns:

the result column
getGeneratedRC
()

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

pack-priv ColumnReference

Returns:

the column reference
getGeneratedRef
()

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

pack-priv ResultColumn

Returns:

the result column.

Warning

it still needs to be bound

getNewAggregatorResultColumn
(DataDictionary
the data dictionary
dd
)

Get the result column that has a new aggregator.

pack-priv ResultColumn

Returns:

the result column.

Warning

it still needs to be bound

getNewExpressionResultColumn
(DataDictionary
the data dictionary
dd
)

Get the aggregate expression in a new result column.

pack-priv ValueNode

Returns:

the value node
getNewNullResultExpression
()

Get the null aggregate result expression column.

public String
getSQLName()

Get the SQL name of the aggregate

private void
pack-priv boolean
pack-priv boolean

Returns:

true/false
isDistinct
()

Indicate whether this aggregate is distinct or not.

private boolean
isUserDefinedAggregate()

Return true if this is a user-defined aggregate

pack-priv ValueNode

Returns:

ValueNode The (potentially) modified tree.
replaceAggregatesWithColumnReferences
(ResultColumnList
The RCL to append to.
rcl
,
int
The tableNumber for the new ColumnReference
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.

pack-priv static AliasDescriptor
resolveAggregate(DataDictionary dd, SchemaDescriptor sd, String rawName, boolean noSchema)

Resolve a user-defined aggregate.

private static AliasDescriptor
resolveBuiltinAggregate(DataDictionary dd, String rawName, boolean noSchema)

Construct an AliasDescriptor for a modern builtin aggregate.

private void
setUserDefinedAggregate(UserAggregateDefinition userAgg)

initialize fields for user defined aggregate

public String

Returns:

a string representation of this node
toString
()

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.toString.

Print a string ref of this node.

Inherited from org.apache.derby.impl.sql.compile.UnaryOperatorNode:
addXmlOpMethodParamsbindOperandbindParametercategorizegetOperandgetOperatorStringgetOrderableVariantTypegetParameterOperandgetReceiverInterfaceNameisConstantExpressionisEquivalentisSameNodeKindpreprocessprintSubNodesremapColumnReferencesToExpressionssetMethodNamesetOperator

Field Detail

aggregateDefinitionClassback to summary
private Class<?> aggregateDefinitionClass
aggregateDefinitionClassNameback to summary
private String aggregateDefinitionClassName
aggregateNameback to summary
private String aggregateName
aggregatorClassNameback to summary
private StringBuffer aggregatorClassName
BUILTIN_MODERN_AGGSback to summary
private static AggregateNode.BuiltinAggDescriptor[] BUILTIN_MODERN_AGGS
classInspectorback to summary
private ClassInspector classInspector
distinctback to summary
private boolean distinct
generatedRCback to summary
private ResultColumn generatedRC
generatedRefback to summary
private ColumnReference generatedRef
uadback to summary
private AggregateDefinition uad
userAggregateNameback to summary
private TableName userAggregateName

Constructor Detail

AggregateNodeback to summary
pack-priv 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:ValueNode

the value expression for the aggregate

uadClass:UserAggregateDefinition

the class of the user aggregate definition

alias:TableName

the name by which the aggregate was called

distinct:boolean

boolean indicating whether this is distinct or not.

aggregateName:String

the name of the aggregate from the user's perspective, e.g. MAX

cm:ContextManager

context manager

AggregateNodeback to summary
pack-priv AggregateNode(ValueNode operand, TableName uadClass, boolean distinct, String aggregateName, ContextManager cm) throws StandardException
Parameters
operand:ValueNode

the value expression for the aggregate

uadClass:TableName

the class name for user aggregate definition for the aggregate

distinct:boolean

boolean indicating whether this is distinct or not.

aggregateName:String

the name of the aggregate from the user's perspective, e.g. MAX

cm:ContextManager

context manager

AggregateNodeback to summary
pack-priv AggregateNode(ValueNode operand, Class<?> uadClass, boolean distinct, String aggregateName, ContextManager cm) throws StandardException
Parameters
operand:ValueNode

the value expression for the aggregate

uadClass:Class<?>

Class for the internal aggregate type

distinct:boolean

boolean indicating whether this is distinct or not.

aggregateName:String

the name of the aggregate from the user's perspective, e.g. MAX

cm:ContextManager

context manager

Method Detail

acceptChildrenback to summary
pack-priv void acceptChildren(Visitor v) throws StandardException

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.acceptChildren.

Doc from org.apache.derby.impl.sql.compile.UnaryOperatorNode.acceptChildren.

Accept the visitor for all visitable children of this node.

Parameters
v:Visitor

the visitor

Annotations
@Override
Exceptions
StandardException:
on error
bindExpressionback to summary
pack-priv ValueNode bindExpression(FromList fromList, SubqueryList subqueryList, List<AggregateNode> aggregates) throws StandardException

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.bindExpression.

Bind this operator. Determine the type of the subexpression, and pass that into the UserAggregate.

Parameters
fromList:FromList

The query's FROM list

subqueryList:SubqueryList

The subquery list being built as we find SubqueryNodes

aggregates:List<AggregateNode>

The aggregate list being built as we find AggregateNodes

Returns:ValueNode

The new top of the expression tree.

Annotations
@Override
Exceptions
StandardException:
Thrown on error
checkAggregatorClassNameback to summary
private void checkAggregatorClassName(String className) throws StandardException
constantExpressionback to summary
pack-priv boolean constantExpression(PredicateList where)

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.constantExpression.

Doc from org.apache.derby.impl.sql.compile.ValueNode.constantExpression.

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.

Returns:boolean

True means this expression tree represents a constant value.

Annotations
@Override
generateExpressionback to summary
pack-priv void generateExpression(ExpressionClassBuilder acb, MethodBuilder mb) throws StandardException

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.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.

Parameters
acb:ExpressionClassBuilder

The ExpressionClassBuilder for the class we're generating

mb:MethodBuilder

The method the code to place the code

Annotations
@Override
Exceptions
StandardException:
Thrown on error
getAggregateDefinitionback to summary
pack-priv AggregateDefinition getAggregateDefinition()

Get the AggregateDefinition.

Returns:AggregateDefinition

The AggregateDefinition

getAggregateNameback to summary
pack-priv String getAggregateName()

Get the class that implements that aggregator for this node.

Returns:String

the class name

getAggregatorClassNameback to summary
pack-priv String getAggregatorClassName()

Get the class that implements that aggregator for this node.

Returns:String

the class name

getGeneratedRCback to summary
pack-priv ResultColumn getGeneratedRC()

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

Returns:ResultColumn

the result column

getGeneratedRefback to summary
pack-priv ColumnReference getGeneratedRef()

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

Returns:ColumnReference

the column reference

getNewAggregatorResultColumnback to summary
pack-priv 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:DataDictionary

the data dictionary

Returns:ResultColumn

the result column.

Warning

it still needs to be bound

Exceptions
StandardException:
on error
getNewExpressionResultColumnback to summary
pack-priv ResultColumn getNewExpressionResultColumn(DataDictionary dd) throws StandardException

Get the aggregate expression in a new result column.

Parameters
dd:DataDictionary

the data dictionary

Returns:ResultColumn

the result column.

Warning

it still needs to be bound

Exceptions
StandardException:
on error
getNewNullResultExpressionback to summary
pack-priv ValueNode getNewNullResultExpression() throws StandardException

Get the null aggregate result expression column.

Returns:ValueNode

the value node

Exceptions
StandardException:
on error
getSQLNameback to summary
public String getSQLName()

Get the SQL name of the aggregate

instantiateAggDefback to summary
private void instantiateAggDef() throws StandardException
isConstantback to summary
pack-priv boolean isConstant()
isDistinctback to summary
pack-priv boolean isDistinct()

Indicate whether this aggregate is distinct or not.

Returns:boolean

true/false

isUserDefinedAggregateback to summary
private boolean isUserDefinedAggregate()

Return true if this is a user-defined aggregate

replaceAggregatesWithColumnReferencesback to summary
pack-priv 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:ResultColumnList

The RCL to append to.

tableNumber:int

The tableNumber for the new ColumnReference

Returns:ValueNode

ValueNode The (potentially) modified tree.

Exceptions
StandardException:
Thrown on error
resolveAggregateback to summary
pack-priv static AliasDescriptor resolveAggregate(DataDictionary dd, SchemaDescriptor sd, String rawName, boolean noSchema) throws StandardException

Resolve a user-defined aggregate.

resolveBuiltinAggregateback to summary
private static AliasDescriptor resolveBuiltinAggregate(DataDictionary dd, String rawName, boolean noSchema) throws StandardException

Construct an AliasDescriptor for a modern builtin aggregate.

setUserDefinedAggregateback to summary
private void setUserDefinedAggregate(UserAggregateDefinition userAgg)

initialize fields for user defined aggregate

toStringback to summary
public String toString()

Overrides org.apache.derby.impl.sql.compile.UnaryOperatorNode.toString.

Print a string ref of this node.

Returns:String

a string representation of this node

Annotations
@Override
org.apache.derby.impl.sql.compile back to summary

pack-priv final Class AggregateNode.BuiltinAggDescriptor

extends Object
Class Inheritance
  • java.lang.Object
  • org.apache.derby.impl.sql.compile.AggregateNode.BuiltinAggDescriptor

Field Summary

Modifier and TypeField and Description
public final String
public final String
public final TypeDescriptor
public final TypeDescriptor

Constructor Summary

AccessConstructor and Description
public
BuiltinAggDescriptor(String aggName, String aggClassName, TypeDescriptor argType, TypeDescriptor returnType)

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aggClassNameback to summary
public final String aggClassName
aggNameback to summary
public final String aggName
argTypeback to summary
public final TypeDescriptor argType
returnTypeback to summary
public final TypeDescriptor returnType

Constructor Detail

BuiltinAggDescriptorback to summary
public BuiltinAggDescriptor(String aggName, String aggClassName, TypeDescriptor argType, TypeDescriptor returnType)