Search in sources :

Example 16 with SiddhiAppCreationException

use of org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException in project ballerina by ballerina-lang.

the class AttributeAggregator method initAggregator.

public void initAggregator(ExpressionExecutor[] attributeExpressionExecutors, SiddhiAppContext siddhiAppContext, ConfigReader configReader) {
    this.configReader = configReader;
    try {
        this.siddhiAppContext = siddhiAppContext;
        this.attributeExpressionExecutors = attributeExpressionExecutors;
        this.attributeSize = attributeExpressionExecutors.length;
        if (elementId == null) {
            elementId = "AttributeAggregator-" + siddhiAppContext.getElementIdGenerator().createNewId();
        }
        // Not added to Snapshotable as the AggregationAttributeExecutors are added
        // siddhiAppContext.getSnapshotService().addSnapshotable(this);
        init(attributeExpressionExecutors, configReader, siddhiAppContext);
    } catch (Throwable t) {
        throw new SiddhiAppCreationException(t);
    }
}
Also used : SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)

Example 17 with SiddhiAppCreationException

use of org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException in project ballerina by ballerina-lang.

the class MaxIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    if (attributeName == null) {
        throw new SiddhiAppCreationException("Max incremental attribute aggregation cannot be executed " + "when no parameters are given");
    }
    if (attributeType.equals(Attribute.Type.INT) || attributeType.equals(Attribute.Type.LONG) || attributeType.equals(Attribute.Type.DOUBLE) || attributeType.equals(Attribute.Type.FLOAT)) {
        this.baseAttributes = new Attribute[] { new Attribute("AGG_MAX_".concat(attributeName), attributeType) };
        this.baseAttributesInitialValues = new Expression[] { Expression.variable(attributeName) };
        this.returnType = attributeType;
        assert baseAttributes.length == baseAttributesInitialValues.length;
    } else {
        throw new SiddhiAppRuntimeException("Max aggregation cannot be executed on attribute type " + attributeType.toString());
    }
}
Also used : Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) ReturnAttribute(org.ballerinalang.siddhi.annotation.ReturnAttribute) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException)

Example 18 with SiddhiAppCreationException

use of org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException in project ballerina by ballerina-lang.

the class AvgIncrementalAttributeAggregator method init.

@Override
public void init(String attributeName, Attribute.Type attributeType) {
    // Send the relevant attribute to this
    Attribute sum;
    Attribute count;
    Expression sumInitialValue;
    Expression countInitialValue;
    if (attributeName == null) {
        throw new SiddhiAppCreationException("Average incremental attribute aggregation cannot be executed " + "when no parameters are given");
    }
    SumIncrementalAttributeAggregator sumIncrementalAttributeAggregator = new SumIncrementalAttributeAggregator();
    sumIncrementalAttributeAggregator.init(attributeName, attributeType);
    CountIncrementalAttributeAggregator countIncrementalAttributeAggregator = new CountIncrementalAttributeAggregator();
    countIncrementalAttributeAggregator.init(attributeName, attributeType);
    // Only one attribute exists for sum and count
    sum = sumIncrementalAttributeAggregator.getBaseAttributes()[0];
    count = countIncrementalAttributeAggregator.getBaseAttributes()[0];
    // Only one init value exists for sum and count
    sumInitialValue = sumIncrementalAttributeAggregator.getBaseAttributeInitialValues()[0];
    countInitialValue = countIncrementalAttributeAggregator.getBaseAttributeInitialValues()[0];
    this.baseAttributes = new Attribute[] { sum, count };
    this.baseAttributesInitialValues = new Expression[] { sumInitialValue, countInitialValue };
    assert baseAttributes.length == baseAttributesInitialValues.length;
}
Also used : Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) ReturnAttribute(org.ballerinalang.siddhi.annotation.ReturnAttribute) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)

Example 19 with SiddhiAppCreationException

use of org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException in project ballerina by ballerina-lang.

the class FunctionExecutor method initExecutor.

public void initExecutor(ExpressionExecutor[] attributeExpressionExecutors, SiddhiAppContext siddhiAppContext, String queryName, ConfigReader configReader) {
    this.configReader = configReader;
    try {
        this.siddhiAppContext = siddhiAppContext;
        this.attributeExpressionExecutors = attributeExpressionExecutors;
        attributeSize = attributeExpressionExecutors.length;
        this.queryName = queryName;
        if (elementId == null) {
            elementId = "FunctionExecutor-" + siddhiAppContext.getElementIdGenerator().createNewId();
        }
        siddhiAppContext.getSnapshotService().addSnapshotable(queryName, this);
        init(attributeExpressionExecutors, configReader, siddhiAppContext);
    } catch (Throwable t) {
        throw new SiddhiAppCreationException(t);
    }
}
Also used : SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)

Example 20 with SiddhiAppCreationException

use of org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException in project ballerina by ballerina-lang.

the class AbstractStreamProcessor method initProcessor.

public AbstractDefinition initProcessor(AbstractDefinition inputDefinition, ExpressionExecutor[] attributeExpressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext, boolean outputExpectsExpiredEvents, String queryName, SiddhiElement siddhiElement) {
    this.configReader = configReader;
    this.outputExpectsExpiredEvents = outputExpectsExpiredEvents;
    try {
        this.inputDefinition = inputDefinition;
        this.attributeExpressionExecutors = attributeExpressionExecutors;
        this.siddhiAppContext = siddhiAppContext;
        this.attributeExpressionLength = attributeExpressionExecutors.length;
        this.queryName = queryName;
        if (elementId == null) {
            elementId = "AbstractStreamProcessor-" + siddhiAppContext.getElementIdGenerator().createNewId();
        }
        siddhiAppContext.getSnapshotService().addSnapshotable(queryName, this);
        this.additionalAttributes = init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
        siddhiAppContext.addEternalReferencedHolder(this);
        StreamDefinition outputDefinition = StreamDefinition.id(inputDefinition.getId());
        outputDefinition.setQueryContextStartIndex(siddhiElement.getQueryContextStartIndex());
        outputDefinition.setQueryContextEndIndex(siddhiElement.getQueryContextEndIndex());
        for (Attribute attribute : inputDefinition.getAttributeList()) {
            outputDefinition.attribute(attribute.getName(), attribute.getType());
        }
        for (Attribute attribute : additionalAttributes) {
            outputDefinition.attribute(attribute.getName(), attribute.getType());
        }
        return outputDefinition;
    } catch (Throwable t) {
        throw new SiddhiAppCreationException(t);
    }
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)

Aggregations

SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)30 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)14 Expression (org.ballerinalang.siddhi.query.api.expression.Expression)10 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)9 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)8 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)8 Element (org.ballerinalang.siddhi.query.api.annotation.Element)7 ArrayList (java.util.ArrayList)6 AbstractDefinition (org.ballerinalang.siddhi.query.api.definition.AbstractDefinition)6 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)6 HashMap (java.util.HashMap)5 Annotation (org.ballerinalang.siddhi.query.api.annotation.Annotation)5 ReturnAttribute (org.ballerinalang.siddhi.annotation.ReturnAttribute)4 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)4 Table (org.ballerinalang.siddhi.core.table.Table)4 CompiledCondition (org.ballerinalang.siddhi.core.util.collection.operator.CompiledCondition)4 MatchingMetaInfoHolder (org.ballerinalang.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)4 ConfigReader (org.ballerinalang.siddhi.core.util.config.ConfigReader)4 SiddhiAppValidationException (org.ballerinalang.siddhi.query.api.exception.SiddhiAppValidationException)4 AttributeFunction (org.ballerinalang.siddhi.query.api.expression.AttributeFunction)4