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:
Serializable, ExprEvaluator, ExprValidator, MetaDefItem
Direct Known Subclasses:
ExprAvedevNode, ExprAvgNode, ExprCountNode, ExprMedianNode, ExprMinMaxAggrNode, ExprPlugInAggFunctionNode, 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 AggregationMethod that reflects each group's (there may be group-by critera) current aggregation state.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class net.esper.eql.expression.ExprNode
ExprNode.MappedPropertyParseResult
 
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.
 Object evaluate(EventBean[] events, boolean isNewData)
          Evaluate event tuple and return result.
static void getAggregatesBottomUp(ExprNode topNode, List<ExprAggregateNode> aggregateNodes)
          Populates into the supplied list all aggregation functions within this expression, if any.
protected abstract  String getAggregationFunctionName()
          Returns the aggregation function name for representation in a generate expression string.
 AggregationMethod getPrototypeAggregator()
          Returns the aggregation state prototype for use in grouping aggregation states per group-by keys.
 Class getType()
          Returns the type that the node's evaluate method returns an instance of.
 boolean isConstantResult()
          Returns true if the expression node's evaluation value doesn't depend on any events data, as must be determined at validation time, which is bottom-up and therefore reliably allows each node to determine constant value.
 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.
 String toExpressionString()
          Renders the aggregation function expression.
 void validate(StreamTypeService streamTypeService, MethodResolutionService methodResolutionService, ViewResourceDelegate viewResourceDelegate, TimeProvider timeProvider)
          Validate node.
protected abstract  AggregationMethod validateAggregationChild(StreamTypeService streamTypeService, MethodResolutionService methodResolutionService)
          Gives the aggregation node a chance to validate the sub-expression types.
protected  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, parseMappedProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

getAggregationFunctionName

protected abstract 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

validateAggregationChild

protected abstract AggregationMethod validateAggregationChild(StreamTypeService streamTypeService,
                                                              MethodResolutionService methodResolutionService)
                                                       throws ExprValidationException
Gives the aggregation node a chance to validate the sub-expression types.

Parameters:
streamTypeService - is the types per stream
methodResolutionService - used for resolving method and function names
Returns:
aggregation function use
Throws:
ExprValidationException - when expression validation failed

isConstantResult

public boolean isConstantResult()
Description copied from class: ExprNode
Returns true if the expression node's evaluation value doesn't depend on any events data, as must be determined at validation time, which is bottom-up and therefore reliably allows each node to determine constant value.

Specified by:
isConstantResult in class ExprNode
Returns:
true for constant evaluation value, false for non-constant evaluation value

validate

public void validate(StreamTypeService streamTypeService,
                     MethodResolutionService methodResolutionService,
                     ViewResourceDelegate viewResourceDelegate,
                     TimeProvider timeProvider)
              throws ExprValidationException
Description copied from interface: ExprValidator
Validate node.

Parameters:
streamTypeService - serves stream event type info
methodResolutionService - - for resolving class names in library method invocations
viewResourceDelegate - - delegates for view resources to expression nodes
timeProvider - - provides engine current time
Throws:
ExprValidationException - thrown when validation failed

getType

public Class getType()
              throws ExprValidationException
Description copied from interface: ExprValidator
Returns the type that the node's evaluate method returns an instance of.

Returns:
type returned when evaluated
Throws:
ExprValidationException - thrown when validation failed

getPrototypeAggregator

public AggregationMethod 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

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 Object evaluate(EventBean[] events,
                             boolean isNewData)
Description copied from interface: ExprEvaluator
Evaluate event tuple and return result.

Parameters:
events - - event tuple
isNewData - - indicates whether we are dealing with new data (istream) or old data (rstream)
Returns:
evaluation result, a boolean value for OR/AND-type evalution nodes.

getAggregatesBottomUp

public static void getAggregatesBottomUp(ExprNode topNode,
                                         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 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 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