use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
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.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class PartitionStreamReceiver method addStreamJunction.
/**
* create local streamJunctions through which events received by partitionStreamReceiver, are sent to
* queryStreamReceivers
*
* @param key partitioning key
* @param queryRuntimeList queryRuntime list of the partition
*/
public void addStreamJunction(String key, List<QueryRuntime> queryRuntimeList) {
StreamJunction streamJunction = cachedStreamJunctionMap.get(streamId + key);
if (streamJunction == null) {
streamJunction = partitionRuntime.getLocalStreamJunctionMap().get(streamId + key);
if (streamJunction == null) {
streamJunction = createStreamJunction();
partitionRuntime.addStreamJunction(streamId + key, streamJunction);
}
cachedStreamJunctionMap.put(streamId + key, streamJunction);
}
for (QueryRuntime queryRuntime : queryRuntimeList) {
StreamRuntime streamRuntime = queryRuntime.getStreamRuntime();
for (int i = 0; i < queryRuntime.getInputStreamId().size(); i++) {
if ((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver().getStreamId().equals(streamId + key)) {
streamJunction.subscribe((streamRuntime.getSingleStreamRuntimes().get(i)).getProcessStreamReceiver());
}
}
}
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class StreamPartitioner method createJoinInputStreamExecutors.
private void createJoinInputStreamExecutors(JoinInputStream inputStream, Partition partition, MetaStateEvent metaEvent, List<VariableExpressionExecutor> executors, SiddhiAppContext siddhiAppContext, String queryName) {
createExecutors(inputStream.getLeftInputStream(), partition, metaEvent.getMetaStreamEvent(0), executors, siddhiAppContext, queryName);
int size = executors.size();
for (VariableExpressionExecutor variableExpressionExecutor : executors) {
variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 0;
}
createExecutors(inputStream.getRightInputStream(), partition, metaEvent.getMetaStreamEvent(1), executors, siddhiAppContext, queryName);
for (int i = size; i < executors.size(); i++) {
executors.get(i).getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 1;
}
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class JoinPartitionTestCase method testJoinPartition1.
@Test
public void testJoinPartition1() throws InterruptedException {
log.info("Join partition test1");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int); define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream, user of twitterStream) begin @info(name = 'query1') " + "from cseEventStream#window.time(1 sec) join twitterStream#window.time(1 sec) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.volume " + "insert all events into outputStream ;" + "" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User1", "Hellno World", "WSO2" });
SiddhiTestHelper.waitForEvents(100, 4, count, 6000);
AssertJUnit.assertEquals(4, count.get());
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.execution.partition.Partition in project siddhi by wso2.
the class JoinPartitionTestCase method testJoinPartition9.
@Test
public void testJoinPartition9() throws InterruptedException {
log.info("Join partition test9");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "define stream cseEventStream (symbol string, user string,volume int); define stream " + "twitterStream (user string, tweet string, company string);" + "partition with (user of cseEventStream, user of twitterStream) begin @info(name = 'query1') " + "from cseEventStream#window.length(1) unidirectional join twitterStream#window.length(1) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.user, cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream" + ".volume " + "insert all events into outputStream ;" + "" + "end ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {
@Override
public void receive(Event[] events) {
EventPrinter.print(events);
count.addAndGet(events.length);
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "WSO2", "User1", 100 });
cseEventStreamHandler.send(new Object[] { "WSO2", "User2", 100 });
twitterStreamHandler.send(new Object[] { "User2", "Hello World", "WSO2" });
twitterStreamHandler.send(new Object[] { "User3", "Hello World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "WSO2", "User3", 100 });
SiddhiTestHelper.waitForEvents(100, 2, count, 60000);
AssertJUnit.assertEquals(2, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations