use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class PartitionTestCase1 method testPartitionQuery46.
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPartitionQuery46() {
log.info("Partition test46");
SiddhiApp siddhiApp = new SiddhiApp("plan46");
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
siddhiApp.defineStream(streamDefinition);
FunctionDefinition functionDefinition = null;
siddhiApp.defineFunction(functionDefinition);
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class PartitionRuntimeImpl method addPartitionReceiver.
private void addPartitionReceiver(String streamId, boolean isInnerStream, MetaStreamEvent metaStreamEvent, List<PartitionExecutor> partitionExecutors) {
if (!partitionStreamReceivers.containsKey(streamId) && !isInnerStream && metaStreamEvent.getEventType() == MetaStreamEvent.EventType.DEFAULT) {
StreamDefinition streamDefinition = (StreamDefinition) streamDefinitionMap.get(streamId);
if (streamDefinition == null) {
streamDefinition = (StreamDefinition) windowDefinitionMap.get(streamId);
}
PartitionStreamReceiver partitionStreamReceiver = new PartitionStreamReceiver(siddhiAppContext, metaStreamEvent, streamDefinition, partitionExecutors, this);
partitionStreamReceivers.put(partitionStreamReceiver.getStreamId(), partitionStreamReceiver);
streamJunctionMap.get(partitionStreamReceiver.getStreamId()).subscribe(partitionStreamReceiver);
}
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class PartitionRuntimeImpl method addQuery.
public void addQuery(QueryRuntimeImpl metaQueryRuntime) {
Query query = metaQueryRuntime.getQuery();
if (query.getOutputStream() instanceof InsertIntoStream && metaQueryRuntime.getOutputCallback() instanceof InsertIntoStreamCallback) {
InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) metaQueryRuntime.getOutputCallback();
StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
String id = streamDefinition.getId();
if (((InsertIntoStream) query.getOutputStream()).isInnerStream()) {
metaQueryRuntime.setToLocalStream(true);
localStreamDefinitionMap.putIfAbsent(id, streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, localStreamDefinitionMap.get(id));
StreamJunction outputStreamJunction = localStreamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
localStreamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoStreamCallback.init(localStreamJunctionMap.get(id));
} else {
streamDefinitionMap.putIfAbsent(id, streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(id));
StreamJunction outputStreamJunction = streamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
streamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoStreamCallback.init(streamJunctionMap.get(id));
}
} else if (query.getOutputStream() instanceof InsertIntoStream && metaQueryRuntime.getOutputCallback() instanceof InsertIntoWindowCallback) {
InsertIntoWindowCallback insertIntoWindowCallback = (InsertIntoWindowCallback) metaQueryRuntime.getOutputCallback();
StreamDefinition streamDefinition = insertIntoWindowCallback.getOutputStreamDefinition();
String id = streamDefinition.getId();
DefinitionParserHelper.validateOutputStream(streamDefinition, windowDefinitionMap.get(id));
StreamJunction outputStreamJunction = streamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
streamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoWindowCallback.getWindow().setPublisher(streamJunctionMap.get(insertIntoWindowCallback.getOutputStreamDefinition().getId()).constructPublisher());
}
if (metaQueryRuntime.isFromLocalStream()) {
for (int i = 0; i < metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().size(); i++) {
String streamId = metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver().getStreamId();
if (streamId.startsWith("#")) {
StreamDefinition streamDefinition = (StreamDefinition) localStreamDefinitionMap.get(streamId);
StreamJunction streamJunction = localStreamJunctionMap.get(streamId);
if (streamJunction == null) {
streamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
localStreamJunctionMap.put(streamId, streamJunction);
}
streamJunction.subscribe(metaQueryRuntime.getStreamRuntime().getSingleStreamRuntimes().get(i).getProcessStreamReceiver());
}
}
}
queryRuntimeList.add(metaQueryRuntime);
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class FilterTestCase2 method testFilterQuery100.
@Test
public void testFilterQuery100() throws InterruptedException {
log.info("Filter test100");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute("quantity", Attribute.Type.INT);
Query query = new Query();
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(40L))));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("quantity", Expression.variable("quantity")));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 500f, 50L, 6 });
inputHandler.send(new Object[] { "WSO2", 70f, 20L, 2 });
inputHandler.send(new Object[] { "WSO2", 50f, 300L, 4 });
SiddhiTestHelper.waitForEvents(10, 2, count, 100);
AssertJUnit.assertEquals(2, count.get());
siddhiAppRuntime.shutdown();
}
use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.
the class FilterTestCase2 method testFilterQuery109.
// *****************************************************************************************************************
// Expression-Add
@Test
public void testFilterQuery109() throws InterruptedException {
log.info("Filter test109");
SiddhiManager siddhiManager = new SiddhiManager();
StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE).attribute("quantity", Attribute.Type.INT).attribute("awards", Attribute.Type.LONG);
Query query = new Query();
query.from(InputStream.stream("cseEventStream"));
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("increasedPrice", Expression.add(Expression.value(100), Expression.variable("price"))).select("increasedVolume", Expression.add(Expression.value(50), Expression.variable("volume"))).select("increasedQuantity", Expression.add(Expression.value(4), Expression.variable("quantity"))).select("increasedAwards", Expression.add(Expression.value(10), Expression.variable("awards"))));
query.insertInto("outputStream");
SiddhiApp siddhiApp = new SiddhiApp("ep1");
siddhiApp.defineStream(cseEventStream);
siddhiApp.addQuery(query);
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timeStamp, inEvents, removeEvents);
AssertJUnit.assertTrue("155.5".equals(inEvents[0].getData()[1].toString()));
AssertJUnit.assertTrue("150.0".equals(inEvents[0].getData()[2].toString()));
AssertJUnit.assertTrue("9".equals(inEvents[0].getData()[3].toString()));
AssertJUnit.assertTrue("20".equals(inEvents[0].getData()[4].toString()));
count.addAndGet(inEvents.length);
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.5f, 100d, 5, 10L });
SiddhiTestHelper.waitForEvents(10, 1, count, 100);
AssertJUnit.assertEquals(1, count.get());
siddhiAppRuntime.shutdown();
}
Aggregations