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 Details

  • 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 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, 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, Class<?> uadClass, boolean distinct, 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 Details

    • 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, 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
    • 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

      private void checkAggregatorClassName(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

      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

      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:
      generateExpression in class UnaryOperatorNode
      Parameters:
      acb - The ExpressionClassBuilder for the class we're generating
      mb - The method the code to place the code
      Throws:
      StandardException - Thrown on error
    • toString

      public String toString()
      Print a string ref of this node.
      Overrides:
      toString in class UnaryOperatorNode
      Returns:
      a string representation of this node
    • isConstant

      boolean isConstant()
    • constantExpression

      boolean constantExpression(PredicateList where)
      Description copied from class: ValueNode
      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.
      Overrides:
      constantExpression in class UnaryOperatorNode
      Returns:
      True means this expression tree represents a constant value.
      See Also:
    • getSQLName

      public 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: UnaryOperatorNode
      Accept the visitor for all visitable children of this node.
      Overrides:
      acceptChildren in class UnaryOperatorNode
      Parameters:
      v - the visitor
      Throws:
      StandardException - on error