/**************************************************************************************
* Copyright (C) 2008 EsperTech, Inc. All rights reserved. *
* http://esper.codehaus.org *
* http://www.espertech.com *
* ---------------------------------------------------------------------------------- *
* The software in this package is published under the terms of the GPL license *
* a copy of which has been included with this distribution in the license.txt file. *
**************************************************************************************/
package com.espertech.esper.epl.core;
import com.espertech.esper.client.EventType;
import com.espertech.esper.core.context.util.AgentInstanceContext;
import com.espertech.esper.epl.agg.service.AggregationService;
import com.espertech.esper.epl.expression.ExprEvaluator;
import com.espertech.esper.epl.spec.OutputLimitLimitType;
import com.espertech.esper.epl.spec.OutputLimitSpec;
/**
* Result set processor prototype for the fully-grouped case:
* there is a group-by and all non-aggregation event properties in the select clause are listed in the group by,
* and there are aggregation functions.
*/
public class ResultSetProcessorRowPerGroupFactory implements ResultSetProcessorFactory
{
private final SelectExprProcessor selectExprProcessor;
private final ExprEvaluator groupKeyNode;
private final ExprEvaluator[] groupKeyNodes;
private final ExprEvaluator optionalHavingNode;
private final boolean isSorting;
private final boolean isSelectRStream;
private final boolean isUnidirectional;
private final OutputLimitSpec outputLimitSpec;
private final boolean noDataWindowSingleSnapshot;
/**
* Ctor.
* @param selectExprProcessor - for processing the select expression and generting the final output rows
* @param groupKeyNodes - list of group-by expression nodes needed for building the group-by keys
* @param optionalHavingNode - expression node representing validated HAVING clause, or null if none given.
* Aggregation functions in the having node must have been pointed to the AggregationService for evaluation.
* @param isSelectRStream - true if remove stream events should be generated
* @param isUnidirectional - true if unidirectional join
*/
public ResultSetProcessorRowPerGroupFactory(SelectExprProcessor selectExprProcessor,
ExprEvaluator[] groupKeyNodes,
ExprEvaluator optionalHavingNode,
boolean isSelectRStream,
boolean isUnidirectional,
OutputLimitSpec outputLimitSpec,
boolean isSorting,
boolean noDataWindowSingleStream)
{
this.selectExprProcessor = selectExprProcessor;
this.groupKeyNodes = groupKeyNodes;
if (groupKeyNodes.length == 1) {
this.groupKeyNode = groupKeyNodes[0];
}
else {
this.groupKeyNode = null;
}
this.optionalHavingNode = optionalHavingNode;
this.isSorting = isSorting;
this.isSelectRStream = isSelectRStream;
this.isUnidirectional = isUnidirectional;
this.outputLimitSpec = outputLimitSpec;
this.noDataWindowSingleSnapshot = (outputLimitSpec != null && outputLimitSpec.getDisplayLimit() == OutputLimitLimitType.SNAPSHOT && noDataWindowSingleStream);
}
public ResultSetProcessor instantiate(OrderByProcessor orderByProcessor, AggregationService aggregationService, AgentInstanceContext agentInstanceContext) {
if (noDataWindowSingleSnapshot) {
return new ResultSetProcessorRowPerGroupSpecial(this, selectExprProcessor, orderByProcessor, aggregationService, agentInstanceContext);
}
return new ResultSetProcessorRowPerGroup(this, selectExprProcessor, orderByProcessor, aggregationService, agentInstanceContext);
}
public EventType getResultEventType()
{
return selectExprProcessor.getResultEventType();
}
public boolean hasAggregation() {
return true;
}
public ExprEvaluator[] getGroupKeyNodes() {
return groupKeyNodes;
}
public ExprEvaluator getGroupKeyNode() {
return groupKeyNode;
}
public ExprEvaluator getOptionalHavingNode() {
return optionalHavingNode;
}
public boolean isSorting() {
return isSorting;
}
public boolean isSelectRStream() {
return isSelectRStream;
}
public boolean isUnidirectional() {
return isUnidirectional;
}
public OutputLimitSpec getOutputLimitSpec() {
return outputLimitSpec;
}
}