com.espertech.esper.epl.expression.baseagg
Class ExprAggregateNodeBase

java.lang.Object
  extended by com.espertech.esper.epl.expression.core.ExprNodeBase
      extended by com.espertech.esper.epl.expression.baseagg.ExprAggregateNodeBase
All Implemented Interfaces:
ExprAggregateNode, ExprEvaluator, ExprNode, ExprValidator, MetaDefItem, java.io.Serializable
Direct Known Subclasses:
ExprAggCountMinSketchNode, ExprAggMultiFunctionLinearAccessNode, ExprAggMultiFunctionSortedMinMaxByNode, ExprAvedevNode, ExprAvgNode, ExprCountEverNode, ExprCountNode, ExprFirstEverNode, ExprLastEverNode, ExprLeavingAggNode, ExprMedianNode, ExprMinMaxAggrNode, ExprNthAggNode, ExprPlugInAggFunctionFactoryNode, ExprPlugInAggMultiFunctionNode, ExprRateAggNode, ExprStddevNode, ExprSumNode

public abstract class ExprAggregateNodeBase
extends ExprNodeBase
implements ExprEvaluator, ExprAggregateNode

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

Field Summary
protected  AggregationResultFuture aggregationResultFuture
           
protected  int column
           
protected  boolean isDistinct
          Indicator for whether the aggregation is distinct - i.e.
protected  ExprAggregateLocalGroupByDesc optionalAggregateLocalGroupByDesc
           
protected  ExprNode[] positionalParams
           
 
Constructor Summary
protected ExprAggregateNodeBase(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 equalsNodeAggregateMethodOnly(ExprAggregateNode node)
          Return true if a expression aggregate node semantically equals the current node, or false if not.
 java.lang.Object evaluate(EventBean[] events, boolean isNewData, ExprEvaluatorContext exprEvaluatorContext)
          Evaluate event tuple and return result.
abstract  java.lang.String getAggregationFunctionName()
          Returns the aggregation function name for representation in a generate expression string.
 ExprEvaluator getExprEvaluator()
           
 AggregationMethodFactory getFactory()
          Returns the aggregation state factory for use in grouping aggregation states per group-by keys.
 ExprAggregateLocalGroupByDesc getOptionalLocalGroupBy()
           
 ExprNode[] getPositionalParams()
           
 ExprPrecedenceEnum getPrecedence()
          Returns precedence.
 java.lang.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.
protected  boolean isExprTextWildcardWhenNoParams()
           
protected  ExprValidationException makeExceptionExpectedParamNum(int lower, int upper)
           
 void setAggregationResultFuture(AggregationResultFuture aggregationResultFuture, int column)
          Assigns to the node the future which can be queried for the current aggregation state at evaluation time.
 void toPrecedenceFreeEPL(java.io.StringWriter writer)
           
 ExprNode validate(ExprValidationContext validationContext)
           
protected abstract  AggregationMethodFactory validateAggregationChild(ExprValidationContext validationContext)
          Gives the aggregation node a chance to validate the sub-expression types.
 void validateFilter(ExprEvaluator filterEvaluator)
           
protected  java.lang.Class validateNumericChildAllowFilter(boolean hasFilter)
          For use by implementing classes, validates the aggregation node expecting a single numeric-type child node.
 void validatePositionals()
           
 
Methods inherited from class com.espertech.esper.epl.expression.core.ExprNodeBase
accept, accept, acceptChildnodes, addChildNode, addChildNodes, addChildNodeToFront, getChildNodes, replaceUnlistedChildNode, setChildNode, setChildNodes, toEPL
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.espertech.esper.epl.expression.core.ExprNode
accept, accept, acceptChildnodes, addChildNode, addChildNodes, getChildNodes, replaceUnlistedChildNode, setChildNode, setChildNodes, toEPL
 

Field Detail

aggregationResultFuture

protected transient AggregationResultFuture aggregationResultFuture

column

protected int column

optionalAggregateLocalGroupByDesc

protected ExprAggregateLocalGroupByDesc optionalAggregateLocalGroupByDesc

positionalParams

protected ExprNode[] positionalParams

isDistinct

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

Constructor Detail

ExprAggregateNodeBase

protected ExprAggregateNodeBase(boolean distinct)
Ctor.

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

getAggregationFunctionName

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

Returns:
aggregation function name

equalsNodeAggregateMethodOnly

protected abstract boolean equalsNodeAggregateMethodOnly(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 AggregationMethodFactory validateAggregationChild(ExprValidationContext validationContext)
                                                              throws ExprValidationException
Gives the aggregation node a chance to validate the sub-expression types.

Parameters:
validationContext - validation information
Returns:
aggregation function factory to use
Throws:
ExprValidationException - when expression validation failed

getPositionalParams

public ExprNode[] getPositionalParams()
Specified by:
getPositionalParams in interface ExprAggregateNode

getExprEvaluator

public ExprEvaluator getExprEvaluator()
Specified by:
getExprEvaluator in interface ExprNode

isConstantResult

public boolean isConstantResult()
Description copied from interface: 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 interface ExprNode
Returns:
true for constant evaluation value, false for non-constant evaluation value

validate

public ExprNode validate(ExprValidationContext validationContext)
                  throws ExprValidationException
Specified by:
validate in interface ExprValidator
Throws:
ExprValidationException

validatePositionals

public void validatePositionals()
                         throws ExprValidationException
Specified by:
validatePositionals in interface ExprAggregateNode
Throws:
ExprValidationException

getType

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

Specified by:
getType in interface ExprEvaluator
Returns:
type returned when evaluated

getFactory

public AggregationMethodFactory getFactory()
Returns the aggregation state factory for use in grouping aggregation states per group-by keys.

Specified by:
getFactory in interface ExprAggregateNode
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.

Specified by:
setAggregationResultFuture in interface ExprAggregateNode
Parameters:
aggregationResultFuture - - future containing state
column - - column to hand to future for easy access

evaluate

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

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

isDistinct

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

Specified by:
isDistinct in interface ExprAggregateNode
Returns:
true if 'distinct' keyword was given, false if not

equalsNode

public final boolean equalsNode(ExprNode node)
Description copied from interface: 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 interface ExprNode
Parameters:
node - to compare to
Returns:
true if semantically equal, or false if not equals

validateNumericChildAllowFilter

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

Returns:
numeric type of single child
Throws:
ExprValidationException - if the validation failed

makeExceptionExpectedParamNum

protected ExprValidationException makeExceptionExpectedParamNum(int lower,
                                                                int upper)

toPrecedenceFreeEPL

public void toPrecedenceFreeEPL(java.io.StringWriter writer)
Specified by:
toPrecedenceFreeEPL in class ExprNodeBase

getPrecedence

public ExprPrecedenceEnum getPrecedence()
Description copied from interface: ExprNode
Returns precedence.

Specified by:
getPrecedence in interface ExprNode
Returns:
precedence

validateFilter

public void validateFilter(ExprEvaluator filterEvaluator)
                    throws ExprValidationException
Throws:
ExprValidationException

getOptionalLocalGroupBy

public ExprAggregateLocalGroupByDesc getOptionalLocalGroupBy()
Specified by:
getOptionalLocalGroupBy in interface ExprAggregateNode

isExprTextWildcardWhenNoParams

protected boolean isExprTextWildcardWhenNoParams()

© 2006-2015 EsperTech Inc.
All rights reserved.
Visit us at espertech.com