com.espertech.esper.epl.agg.factory.AggregationMethodFactoryNth Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of esper Show documentation
Show all versions of esper Show documentation
Complex event processing and event series analysis component
/*
***************************************************************************************
* Copyright (C) 2006 EsperTech, Inc. All rights reserved. *
* http://www.espertech.com/esper *
* 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.agg.factory;
import com.espertech.esper.client.EventType;
import com.espertech.esper.codegen.base.CodegenClassScope;
import com.espertech.esper.codegen.base.CodegenMethodNode;
import com.espertech.esper.codegen.core.CodegenCtor;
import com.espertech.esper.epl.agg.access.AggregationAccessorForge;
import com.espertech.esper.epl.agg.access.AggregationAgentForge;
import com.espertech.esper.epl.agg.access.AggregationStateKey;
import com.espertech.esper.epl.agg.aggregator.AggregationMethod;
import com.espertech.esper.epl.agg.aggregator.AggregatorNth;
import com.espertech.esper.epl.agg.aggregator.AggregatorNthFilter;
import com.espertech.esper.codegen.base.CodegenMembersColumnized;
import com.espertech.esper.epl.agg.service.common.AggregationMethodFactory;
import com.espertech.esper.epl.agg.service.common.AggregationStateFactoryForge;
import com.espertech.esper.epl.agg.service.common.AggregationValidationUtil;
import com.espertech.esper.epl.core.engineimport.EngineImportService;
import com.espertech.esper.epl.expression.baseagg.ExprAggregateNodeBase;
import com.espertech.esper.epl.expression.codegen.ExprForgeCodegenSymbol;
import com.espertech.esper.epl.expression.core.ExprForge;
import com.espertech.esper.epl.expression.core.ExprValidationException;
import com.espertech.esper.epl.expression.methodagg.ExprMethodAggUtil;
import com.espertech.esper.epl.expression.methodagg.ExprNthAggNode;
public class AggregationMethodFactoryNth implements AggregationMethodFactory {
protected final ExprNthAggNode parent;
protected final Class childType;
protected final int size;
public AggregationMethodFactoryNth(ExprNthAggNode parent, Class childType, int size) {
this.parent = parent;
this.childType = childType;
this.size = size;
}
public boolean isAccessAggregation() {
return false;
}
public Class getResultType() {
return childType;
}
public AggregationStateKey getAggregationStateKey(boolean isMatchRecognize) {
throw new IllegalStateException("Not an access aggregation function");
}
public AggregationStateFactoryForge getAggregationStateFactory(boolean isMatchRecognize) {
throw new IllegalStateException("Not an access aggregation function");
}
public AggregationAccessorForge getAccessorForge() {
throw new IllegalStateException("Not an access aggregation function");
}
public AggregationMethod make() {
AggregationMethod method;
if (parent.getOptionalFilter() != null) {
method = new AggregatorNthFilter(size + 1);
} else {
method = new AggregatorNth(size + 1);
}
if (!parent.isDistinct()) {
return method;
}
return AggregationMethodFactoryUtil.makeDistinctAggregator(method, false);
}
public ExprNthAggNode getParent() {
return parent;
}
public ExprAggregateNodeBase getAggregationExpression() {
return parent;
}
public void validateIntoTableCompatible(AggregationMethodFactory intoTableAgg) throws ExprValidationException {
AggregationValidationUtil.validateAggregationType(this, intoTableAgg);
AggregationMethodFactoryNth that = (AggregationMethodFactoryNth) intoTableAgg;
AggregationValidationUtil.validateAggregationInputType(childType, that.childType);
if (size != that.size) {
throw new ExprValidationException("The size is " +
size +
" and provided is " +
that.size);
}
}
public AggregationAgentForge getAggregationStateAgent(EngineImportService engineImportService, String statementName) {
return null;
}
public ExprForge[] getMethodAggregationForge(boolean join, EventType[] typesPerStream) throws ExprValidationException {
return ExprMethodAggUtil.getDefaultForges(parent.getPositionalParams(), join, typesPerStream);
}
public void rowMemberCodegen(int column, CodegenCtor ctor, CodegenMembersColumnized membersColumnized, ExprForge[] forges, CodegenClassScope classScope) {
AggregatorNth.rowMemberCodegen(this, column, ctor, membersColumnized);
}
public void applyEnterCodegen(int column, CodegenMethodNode method, ExprForgeCodegenSymbol symbols, ExprForge[] forges, CodegenClassScope classScope) {
AggregatorNth.applyEnterCodegen(this, column, method, symbols, forges, classScope);
}
public void applyLeaveCodegen(int column, CodegenMethodNode method, ExprForgeCodegenSymbol symbols, ExprForge[] forges, CodegenClassScope classScope) {
AggregatorNth.applyLeaveCodegen(this, column, method, symbols, forges, classScope);
}
public void clearCodegen(int column, CodegenMethodNode method, CodegenClassScope classScope) {
AggregatorNth.clearCodegen(this, column, method);
}
public void getValueCodegen(int column, CodegenMethodNode method, CodegenClassScope classScope) {
AggregatorNth.getValueCodegen(this, column, method);
}
public int getSizeOfBuf() {
return size + 1;
}
}