Class 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.
    • Field Detail

      • distinct

        private boolean distinct
      • userAggregateName

        private TableName userAggregateName
      • aggregatorClassName

        private java.lang.StringBuffer aggregatorClassName
      • aggregateDefinitionClassName

        private java.lang.String aggregateDefinitionClassName
      • aggregateDefinitionClass

        private java.lang.Class<?> aggregateDefinitionClass
      • aggregateName

        private java.lang.String aggregateName
    • 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 aggregate
        uadClass - the class of the user aggregate definition
        alias - the name by which the aggregate was called
        distinct - boolean indicating whether this is distinct or not.
        aggregateName - the name of the aggregate from the user's perspective, e.g. MAX
        cm - 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 aggregate
        uadClass - the class name for user aggregate definition for the aggregate
        distinct - boolean indicating whether this is distinct or not.
        aggregateName - the name of the aggregate from the user's perspective, e.g. MAX
        cm - 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 aggregate
        uadClass - 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
        cm - 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:
        bindExpression in class UnaryOperatorNode
        Parameters:
        fromList - The query's FROM list
        subqueryList - The subquery list being built as we find SubqueryNodes
        aggregates - The aggregate list being built as we find AggregateNodes
        Returns:
        The new top of the expression tree.
        Throws:
        StandardException - Thrown on error
      • 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
      • 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

        boolean isConstant()
      • 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