use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.
the class EventTestCase method testQueryParser.
@Test
public void testQueryParser() {
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
StreamDefinition outStreamDefinition = StreamDefinition.id("outputStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT);
Query query = new Query();
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.NOT_EQUAL, Expression.value(50))));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
Map<String, AbstractDefinition> tableDefinitionMap = new HashMap<>();
Map<String, AbstractDefinition> windowDefinitionMap = new HashMap<>();
Map<String, AbstractDefinition> aggregationDefinitionMap = new HashMap<>();
Map<String, Table> tableMap = new HashMap<String, Table>();
Map<String, Window> eventWindowMap = new HashMap<String, Window>();
Map<String, AggregationRuntime> aggregationMap = new HashMap<String, AggregationRuntime>();
Map<String, List<Source>> eventSourceMap = new HashMap<String, List<Source>>();
Map<String, List<Sink>> eventSinkMap = new HashMap<String, List<Sink>>();
Map<String, AbstractDefinition> streamDefinitionMap = new HashMap<String, AbstractDefinition>();
LockSynchronizer lockSynchronizer = new LockSynchronizer();
streamDefinitionMap.put("cseEventStream", streamDefinition);
streamDefinitionMap.put("outputStream", outStreamDefinition);
SiddhiContext siddhicontext = new SiddhiContext();
SiddhiAppContext context = new SiddhiAppContext();
context.setSiddhiContext(siddhicontext);
context.setElementIdGenerator(new ElementIdGenerator(context.getName()));
context.setSnapshotService(new SnapshotService(context));
QueryRuntime runtime = QueryParser.parse(query, context, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, aggregationMap, eventWindowMap, lockSynchronizer, "1");
AssertJUnit.assertNotNull(runtime);
AssertJUnit.assertTrue(runtime.getStreamRuntime() instanceof SingleStreamRuntime);
AssertJUnit.assertNotNull(runtime.getSelector());
AssertJUnit.assertTrue(runtime.getMetaComplexEvent() instanceof MetaStreamEvent);
}
use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.
the class PartitionRuntime method addPartitionReceiver.
public void addPartitionReceiver(QueryRuntime queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
Query query = queryRuntime.getQuery();
List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, siddhiAppContext, null).getPartitionExecutorLists();
if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
} else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream();
addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream();
addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
} else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
}
}
use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.
the class JoinStreamRuntime method clone.
@Override
public StreamRuntime clone(String key) {
JoinStreamRuntime joinStreamRuntime = new JoinStreamRuntime(siddhiAppContext, metaStateEvent);
for (SingleStreamRuntime singleStreamRuntime : singleStreamRuntimeList) {
joinStreamRuntime.addRuntime((SingleStreamRuntime) singleStreamRuntime.clone(key));
}
SingleStreamRuntime leftSingleStreamRuntime = joinStreamRuntime.getSingleStreamRuntimes().get(0);
SingleStreamRuntime rightSingleStreamRuntime = joinStreamRuntime.getSingleStreamRuntimes().get(1);
Processor lastLeftProcessor = leftSingleStreamRuntime.getProcessorChain();
while (!(lastLeftProcessor instanceof JoinProcessor)) {
lastLeftProcessor = lastLeftProcessor.getNextProcessor();
}
JoinProcessor leftPreJoinProcessor = (JoinProcessor) lastLeftProcessor;
WindowProcessor leftWindowProcessor = (WindowProcessor) leftPreJoinProcessor.getNextProcessor();
JoinProcessor leftPostJoinProcessor = (JoinProcessor) leftWindowProcessor.getNextProcessor();
Processor lastRightProcessor = rightSingleStreamRuntime.getProcessorChain();
while (!(lastRightProcessor instanceof JoinProcessor)) {
lastRightProcessor = lastRightProcessor.getNextProcessor();
}
JoinProcessor rightPreJoinProcessor = (JoinProcessor) lastRightProcessor;
WindowProcessor rightWindowProcessor = (WindowProcessor) rightPreJoinProcessor.getNextProcessor();
JoinProcessor rightPostJoinProcessor = (JoinProcessor) rightWindowProcessor.getNextProcessor();
rightPostJoinProcessor.setFindableProcessor((FindableProcessor) leftWindowProcessor);
rightPreJoinProcessor.setFindableProcessor((FindableProcessor) leftWindowProcessor);
leftPreJoinProcessor.setFindableProcessor((FindableProcessor) rightWindowProcessor);
leftPostJoinProcessor.setFindableProcessor((FindableProcessor) rightWindowProcessor);
return joinStreamRuntime;
}
use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.
the class StreamInnerStateRuntime method clone.
@Override
public InnerStateRuntime clone(String key) {
StreamInnerStateRuntime streamInnerStateRuntime = new StreamInnerStateRuntime(stateType);
for (SingleStreamRuntime singleStreamRuntime : singleStreamRuntimeList) {
streamInnerStateRuntime.singleStreamRuntimeList.add((SingleStreamRuntime) singleStreamRuntime.clone(key));
}
Processor processor = streamInnerStateRuntime.singleStreamRuntimeList.get(0).getProcessorChain();
streamInnerStateRuntime.firstProcessor = (StreamPreStateProcessor) processor;
while (processor != null) {
if (processor instanceof StreamPostStateProcessor) {
streamInnerStateRuntime.lastProcessor = (StreamPostStateProcessor) processor;
break;
} else {
processor = processor.getNextProcessor();
}
}
((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor).setThisStatePreProcessor((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor);
((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor).setThisStatePostProcessor((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor);
((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor).setThisLastProcessor((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor);
return streamInnerStateRuntime;
}
use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.
the class LogicalInnerStateRuntime method clone.
@Override
public InnerStateRuntime clone(String key) {
InnerStateRuntime clonedInnerStateRuntime1 = innerStateRuntime1.clone(key);
InnerStateRuntime clonedInnerStateRuntime2 = innerStateRuntime2.clone(key);
LogicalPreStateProcessor logicalPreStateProcessor1 = (LogicalPreStateProcessor) clonedInnerStateRuntime1.getFirstProcessor();
LogicalPostStateProcessor logicalPostStateProcessor1 = (LogicalPostStateProcessor) clonedInnerStateRuntime1.getLastProcessor();
LogicalPreStateProcessor logicalPreStateProcessor2 = (LogicalPreStateProcessor) clonedInnerStateRuntime2.getFirstProcessor();
LogicalPostStateProcessor logicalPostStateProcessor2 = (LogicalPostStateProcessor) clonedInnerStateRuntime2.getLastProcessor();
logicalPostStateProcessor1.setPartnerPreStateProcessor(logicalPreStateProcessor2);
logicalPostStateProcessor2.setPartnerPreStateProcessor(logicalPreStateProcessor1);
logicalPostStateProcessor1.setPartnerPostStateProcessor(logicalPostStateProcessor2);
logicalPostStateProcessor2.setPartnerPostStateProcessor(logicalPostStateProcessor1);
logicalPreStateProcessor1.setPartnerStatePreProcessor(logicalPreStateProcessor2);
logicalPreStateProcessor2.setPartnerStatePreProcessor(logicalPreStateProcessor1);
LogicalInnerStateRuntime logicalInnerStateRuntime = new LogicalInnerStateRuntime(clonedInnerStateRuntime1, clonedInnerStateRuntime2, stateType);
logicalInnerStateRuntime.firstProcessor = clonedInnerStateRuntime1.getFirstProcessor();
logicalInnerStateRuntime.lastProcessor = clonedInnerStateRuntime2.getLastProcessor();
logicalInnerStateRuntime.getSingleStreamRuntimeList().addAll(clonedInnerStateRuntime2.getSingleStreamRuntimeList());
logicalInnerStateRuntime.getSingleStreamRuntimeList().addAll(clonedInnerStateRuntime1.getSingleStreamRuntimeList());
List<SingleStreamRuntime> runtimeList = logicalInnerStateRuntime.getSingleStreamRuntimeList();
for (int i = 0; i < runtimeList.size(); i++) {
String streamId = runtimeList.get(i).getProcessStreamReceiver().getStreamId();
for (int j = i; j < runtimeList.size(); j++) {
if (streamId.equals(runtimeList.get(j).getProcessStreamReceiver().getStreamId())) {
runtimeList.get(j).setProcessStreamReceiver(runtimeList.get(i).getProcessStreamReceiver());
}
}
}
return logicalInnerStateRuntime;
}
Aggregations