use of org.ballerinalang.siddhi.core.event.state.StateEventPool in project ballerina by ballerina-lang.
the class OutputParser method constructOutputCallback.
public static OutputCallback constructOutputCallback(final OutputStream outStream, StreamDefinition outputStreamDefinition, Map<String, Table> tableMap, Map<String, Window> eventWindowMap, SiddhiAppContext siddhiAppContext, boolean convertToStreamEvent, String queryName) {
String id = outStream.getId();
Table table = null;
Window window = null;
if (id != null) {
table = tableMap.get(id);
window = eventWindowMap.get(id);
}
StreamEventPool streamEventPool = null;
StreamEventConverter streamEventConverter = null;
MetaStreamEvent tableMetaStreamEvent = null;
if (table != null) {
tableMetaStreamEvent = new MetaStreamEvent();
tableMetaStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
TableDefinition matchingTableDefinition = TableDefinition.id("");
for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
tableMetaStreamEvent.addOutputData(attribute);
matchingTableDefinition.attribute(attribute.getName(), attribute.getType());
}
matchingTableDefinition.setQueryContextStartIndex(outStream.getQueryContextStartIndex());
matchingTableDefinition.setQueryContextEndIndex(outStream.getQueryContextEndIndex());
tableMetaStreamEvent.addInputDefinition(matchingTableDefinition);
streamEventPool = new StreamEventPool(tableMetaStreamEvent, 10);
streamEventConverter = new ZeroStreamEventConverter();
}
// Construct CallBack
if (outStream instanceof InsertIntoStream) {
if (window != null) {
return new InsertIntoWindowCallback(window, outputStreamDefinition, queryName);
} else if (table != null) {
DefinitionParserHelper.validateOutputStream(outputStreamDefinition, table.getTableDefinition());
return new InsertIntoTableCallback(table, outputStreamDefinition, convertToStreamEvent, streamEventPool, streamEventConverter, queryName);
} else {
return new InsertIntoStreamCallback(outputStreamDefinition, queryName);
}
} else if (outStream instanceof DeleteStream || outStream instanceof UpdateStream || outStream instanceof UpdateOrInsertStream) {
if (table != null) {
if (outStream instanceof UpdateStream) {
if (((UpdateStream) outStream).getUpdateSet() == null) {
TableDefinition tableDefinition = table.getTableDefinition();
for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
if (!tableDefinition.getAttributeList().contains(attribute)) {
throw new SiddhiAppCreationException("Attribute " + attribute + " does not exist on " + "Event Table " + tableDefinition, outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
}
}
}
}
if (outStream instanceof UpdateOrInsertStream) {
TableDefinition tableDefinition = table.getTableDefinition();
for (Attribute attribute : outputStreamDefinition.getAttributeList()) {
if (!tableDefinition.getAttributeList().contains(attribute)) {
throw new SiddhiAppCreationException("Attribute " + attribute + " does not exist on " + "Event Table " + tableDefinition, outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
}
}
}
if (outStream instanceof DeleteStream) {
try {
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
CompiledCondition compiledCondition = table.compileCondition((((DeleteStream) outStream).getOnDeleteExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
return new DeleteTableCallback(table, compiledCondition, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
} catch (SiddhiAppValidationException e) {
throw new SiddhiAppCreationException("Cannot create delete for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
}
} else if (outStream instanceof UpdateStream) {
try {
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
CompiledCondition compiledCondition = table.compileCondition((((UpdateStream) outStream).getOnUpdateExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
UpdateSet updateSet = ((UpdateStream) outStream).getUpdateSet();
if (updateSet == null) {
updateSet = new UpdateSet();
for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
}
}
CompiledUpdateSet compiledUpdateSet = table.compileUpdateSet(updateSet, matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
return new UpdateTableCallback(table, compiledCondition, compiledUpdateSet, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
} catch (SiddhiAppValidationException e) {
throw new SiddhiAppCreationException("Cannot create update for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext);
}
} else {
DefinitionParserHelper.validateOutputStream(outputStreamDefinition, table.getTableDefinition());
try {
MatchingMetaInfoHolder matchingMetaInfoHolder = MatcherParser.constructMatchingMetaStateHolder(tableMetaStreamEvent, 0, table.getTableDefinition(), 0);
CompiledCondition compiledCondition = table.compileCondition((((UpdateOrInsertStream) outStream).getOnUpdateExpression()), matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
UpdateSet updateSet = ((UpdateOrInsertStream) outStream).getUpdateSet();
if (updateSet == null) {
updateSet = new UpdateSet();
for (Attribute attribute : matchingMetaInfoHolder.getMatchingStreamDefinition().getAttributeList()) {
updateSet.set(new Variable(attribute.getName()), new Variable(attribute.getName()));
}
}
CompiledUpdateSet compiledUpdateSet = table.compileUpdateSet(updateSet, matchingMetaInfoHolder, siddhiAppContext, null, tableMap, queryName);
StateEventPool stateEventPool = new StateEventPool(matchingMetaInfoHolder.getMetaStateEvent(), 10);
return new UpdateOrInsertTableCallback(table, compiledCondition, compiledUpdateSet, matchingMetaInfoHolder.getMatchingStreamEventIndex(), convertToStreamEvent, stateEventPool, streamEventPool, streamEventConverter, queryName);
} catch (SiddhiAppValidationException e) {
throw new SiddhiAppCreationException("Cannot create update or insert into for table '" + outStream.getId() + "', " + e.getMessageWithOutContext(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext);
}
}
} else {
throw new SiddhiAppCreationException("Event table with id :" + id + " does not exist", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
}
} else {
throw new SiddhiAppCreationException(outStream.getClass().getName() + " not supported", outStream.getQueryContextStartIndex(), outStream.getQueryContextEndIndex());
}
}
use of org.ballerinalang.siddhi.core.event.state.StateEventPool in project ballerina by ballerina-lang.
the class StoreQueryParser method populateFindStoreQueryRuntime.
private static void populateFindStoreQueryRuntime(FindStoreQueryRuntime findStoreQueryRuntime, MatchingMetaInfoHolder metaStreamInfoHolder, Selector selector, List<VariableExpressionExecutor> variableExpressionExecutors, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String queryName, int metaPosition) {
QuerySelector querySelector = SelectorParser.parse(selector, new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS), siddhiAppContext, metaStreamInfoHolder.getMetaStateEvent(), tableMap, variableExpressionExecutors, queryName, metaPosition);
QueryParserHelper.reduceMetaComplexEvent(metaStreamInfoHolder.getMetaStateEvent());
QueryParserHelper.updateVariablePosition(metaStreamInfoHolder.getMetaStateEvent(), variableExpressionExecutors);
querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(metaStreamInfoHolder.getMetaStateEvent()));
findStoreQueryRuntime.setStateEventPool(new StateEventPool(metaStreamInfoHolder.getMetaStateEvent(), 5));
findStoreQueryRuntime.setSelector(querySelector);
findStoreQueryRuntime.setOutputAttributes(metaStreamInfoHolder.getMetaStateEvent().getOutputStreamDefinition().getAttributeList());
}
use of org.ballerinalang.siddhi.core.event.state.StateEventPool in project ballerina by ballerina-lang.
the class QueryParserHelper method initStreamRuntime.
public static void initStreamRuntime(StreamRuntime runtime, MetaComplexEvent metaComplexEvent, LockWrapper lockWrapper, String queryName) {
if (runtime instanceof SingleStreamRuntime) {
initSingleStreamRuntime((SingleStreamRuntime) runtime, 0, metaComplexEvent, null, lockWrapper, queryName);
} else {
MetaStateEvent metaStateEvent = (MetaStateEvent) metaComplexEvent;
StateEventPool stateEventPool = new StateEventPool(metaStateEvent, 5);
MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
initSingleStreamRuntime(runtime.getSingleStreamRuntimes().get(i), i, metaStateEvent, stateEventPool, lockWrapper, queryName);
}
}
}
use of org.ballerinalang.siddhi.core.event.state.StateEventPool in project ballerina by ballerina-lang.
the class WrappedSnapshotOutputRateLimiter method init.
public void init(int outPutAttributeSize, List<AttributeProcessor> attributeProcessorList, MetaComplexEvent metaComplexEvent) {
for (AttributeProcessor attributeProcessor : attributeProcessorList) {
if (attributeProcessor.getExpressionExecutor() instanceof AbstractAggregationAttributeExecutor) {
aggregateAttributePositionList.add(attributeProcessor.getOutputPosition());
}
}
if (windowed) {
if (groupBy) {
if (outPutAttributeSize == aggregateAttributePositionList.size()) {
// All Aggregation
outputRateLimiter = new AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
} else if (aggregateAttributePositionList.size() > 0) {
// Some Aggregation
outputRateLimiter = new AggregationGroupByWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, aggregateAttributePositionList, this, siddhiAppContext, queryName);
} else {
// No aggregation
// GroupBy is same as Non GroupBy
outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
}
} else {
if (outPutAttributeSize == aggregateAttributePositionList.size()) {
// All Aggregation
outputRateLimiter = new AllAggregationPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
} else if (aggregateAttributePositionList.size() > 0) {
// Some Aggregation
outputRateLimiter = new AggregationWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, aggregateAttributePositionList, this, siddhiAppContext, queryName);
} else {
// No aggregation
outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
}
}
} else {
if (groupBy) {
outputRateLimiter = new GroupByPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
} else {
outputRateLimiter = new PerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
}
}
if (metaComplexEvent instanceof MetaStateEvent) {
StateEventPool stateEventPool = new StateEventPool((MetaStateEvent) metaComplexEvent, 5);
outputRateLimiter.setStateEventCloner(new StateEventCloner((MetaStateEvent) metaComplexEvent, stateEventPool));
} else {
StreamEventPool streamEventPool = new StreamEventPool((MetaStreamEvent) metaComplexEvent, 5);
outputRateLimiter.setStreamEventCloner(new StreamEventCloner((MetaStreamEvent) metaComplexEvent, streamEventPool));
}
}
Aggregations