net.esper.eql.expression
Class ExprAggregateNode

java.lang.Object
  extended by net.esper.eql.expression.ExprNode
      extended by net.esper.eql.expression.ExprAggregateNode
All Implemented Interfaces:
ExprEvaluator, ExprValidator
Direct Known Subclasses:
ExprAvedevNode, ExprAvgNode, ExprCountNode, ExprMedianNode, ExprMinMaxAggrNode, ExprStddevNode, ExprSumNode

public abstract class ExprAggregateNode
extends ExprNode

Base expression node that represents an aggregation function such as 'sum' or 'count'.

In terms of validation each concrete aggregation node must implement it's own validation.

In terms of evaluation this base class will ask the assigned AggregationResultFuture for the current state, using a column number assigned to the node.

Concrete subclasses must supply an aggregation state prototype node Aggregator that reflects each group's (there may be group-by critera) current aggregation state.


Field Summary
protected  boolean isDistinct
          Indicator for whether the aggregation is distinct - i.e.
 
Constructor Summary
protected ExprAggregateNode(boolean distinct)
          Ctor.
 
Method Summary
 boolean equalsNode(ExprNode node)
          Return true if a expression node semantically equals the current node, or false if not.
protected abstract  boolean equalsNodeAggregate(ExprAggregateNode node)
          Return true if a expression aggregate node semantically equals the current node, or false if not.
 java.lang.Object evaluate(EventBean[] events)
          Evaluate event tuple and return result.
static void getAggregatesBottomUp(ExprNode topNode, java.util.List<ExprAggregateNode> aggregateNodes)
          Populates into the supplied list all aggregation functions within this expression, if any.
protected abstract  Aggregator getAggregationFunction()
          Returns the aggregation state prototype for use in grouping aggregation states per group-by keys.
protected abstract  java.lang.String getAggregationFunctionName()
          Returns the aggregation function name for representation in a generate expression string.
 Aggregator getPrototypeAggregator()
          Returns the aggregation state prototype for use in grouping aggregation states per group-by keys.
 boolean isDistinct()
          Returns true if the aggregation node is only aggregatig distinct values, or false if aggregating all values.
 void setAggregationResultFuture(AggregationResultFuture aggregationResultFuture, int column)
          Assigns to the node the future which can be queried for the current aggregation state at evaluation time.
 java.lang.String toExpressionString()
          Renders the aggregation function expression.
protected  java.lang.Class validateSingleNumericChild(StreamTypeService streamTypeService)
          For use by implementing classes, validates the aggregation node expecting a single numeric-type child node.
 
Methods inherited from class net.esper.eql.expression.ExprNode
accept, addChildNode, deepEquals, dumpDebug, getChildNodes, getValidatedSubtree
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface net.esper.eql.expression.ExprValidator
getType, validate
 

Field Detail

isDistinct

protected boolean isDistinct
Indicator for whether the aggregation is distinct - i.e. only unique values are considered.

Constructor Detail

ExprAggregateNode

protected ExprAggregateNode(boolean distinct)
Ctor.

Parameters:
distinct - - sets the flag indicatating whether only unique values should be aggregated
Method Detail

getPrototypeAggregator

public Aggregator getPrototypeAggregator()
Returns the aggregation state prototype for use in grouping aggregation states per group-by keys.

Returns:
prototype aggregation state as a factory for aggregation states per group-by key value

getAggregationFunction

protected abstract Aggregator getAggregationFunction()
Returns the aggregation state prototype for use in grouping aggregation states per group-by keys.

Returns:
prototype aggregation state as a factory for aggregation states per group-by key value

getAggregationFunctionName

protected abstract java.lang.String getAggregationFunctionName()
Returns the aggregation function name for representation in a generate expression string.

Returns:
aggregation function name

equalsNodeAggregate

protected abstract boolean equalsNodeAggregate(ExprAggregateNode node)
Return true if a expression aggregate node semantically equals the current node, or false if not.

For use by the equalsNode implementation which compares the distinct flag.

Parameters:
node - to compare to
Returns:
true if semantically equal, or false if not equals

setAggregationResultFuture

public void setAggregationResultFuture(AggregationResultFuture aggregationResultFuture,
                                       int column)
Assigns to the node the future which can be queried for the current aggregation state at evaluation time.

Parameters:
aggregationResultFuture - - future containing state
column - - column to hand to future for easy access

evaluate

public final java.lang.Object evaluate(EventBean[] events)
Description copied from interface: ExprEvaluator
Evaluate event tuple and return result.

Parameters:
events - - event tuple
Returns:
evaluation result, a boolean value for OR/AND-type evalution nodes.

getAggregatesBottomUp

public static void getAggregatesBottomUp(ExprNode topNode,
                                         java.util.List<ExprAggregateNode> aggregateNodes)
Populates into the supplied list all aggregation functions within this expression, if any.

Populates by going bottom-up such that nested aggregates appear first.

I.e. sum(volume * sum(price)) would put first A then B into the list with A=sum(price) and B=sum(volume * A)

Parameters:
topNode - is the expression node to deep inspect
aggregateNodes - is a list of node to populate into

isDistinct

public boolean isDistinct()
Returns true if the aggregation node is only aggregatig distinct values, or false if aggregating all values.

Returns:
true if 'distinct' keyword was given, false if not

equalsNode

public final boolean equalsNode(ExprNode node)
Description copied from class: ExprNode
Return true if a expression node semantically equals the current node, or false if not.

Concrete implementations should compare the type and any additional information that impact the evaluation of a node.

Specified by:
equalsNode in class ExprNode
Parameters:
node - to compare to
Returns:
true if semantically equal, or false if not equals

validateSingleNumericChild

protected final java.lang.Class validateSingleNumericChild(StreamTypeService streamTypeService)
                                                    throws ExprValidationException
For use by implementing classes, validates the aggregation node expecting a single numeric-type child node.

Parameters:
streamTypeService - - types represented in streams
Returns:
numeric type of single child
Throws:
ExprValidationException - if the validation failed

toExpressionString

public final java.lang.String toExpressionString()
Renders the aggregation function expression.

Specified by:
toExpressionString in class ExprNode
Returns:
expression string is the textual rendering of the aggregation function and it's sub-expression