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);
}
}
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());
}
}
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;
}
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);
}
}
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);
}
}
Aggregations