use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class JoinTestCase method joinTest15.
@Test
public void joinTest15() throws InterruptedException {
log.info("Join test15");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "on order.custid == dow_items.custid \n" + "select dow_items.item\n" + "having dow_items.item == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
}
});
siddhiAppRuntime.start();
Thread.sleep(100);
itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
Thread.sleep(100);
AssertJUnit.assertEquals("Event Arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class JoinTestCase method joinTest20.
@Test
public void joinTest20() throws InterruptedException {
log.info("Join test20");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream dataIn (id int, data string); " + "define stream countIn (id int); " + "define stream deleteIn (id int); " + "define table dataTable (id int, data string); ";
String query = "" + "from dataIn\n" + "insert into dataTable;\n" + "" + "from deleteIn \n" + "delete dataTable\n" + " on dataTable.id == id;\n" + "" + "@info(name = 'query1') " + "from countIn as c left outer join dataTable as d\n" + "on d.data == 'abc'\n" + "select count() as count\n" + "insert into countOut; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
InputHandler dataIn = siddhiAppRuntime.getInputHandler("dataIn");
InputHandler countIn = siddhiAppRuntime.getInputHandler("countIn");
InputHandler deleteIn = siddhiAppRuntime.getInputHandler("deleteIn");
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
inEventCount.incrementAndGet();
if (inEventCount.get() == 1) {
EventPrinter.print(timestamp, inEvents, removeEvents);
AssertJUnit.assertTrue((Long) inEvents[0].getData(0) == 3L);
} else {
EventPrinter.print(timestamp, inEvents, removeEvents);
AssertJUnit.assertTrue((Long) inEvents[0].getData(0) == 2L);
}
}
});
siddhiAppRuntime.start();
Thread.sleep(100);
dataIn.send(new Object[] { 1, "abc" });
dataIn.send(new Object[] { 2, "abc" });
dataIn.send(new Object[] { 3, "abc" });
countIn.send(new Object[] { 1 });
deleteIn.send(new Object[] { 1 });
countIn.send(new Object[] { 1 });
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class JoinTestCase method joinTest16.
@Test
public void joinTest16() throws InterruptedException {
log.info("Join test16");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "on order.custid == dow_items.custid \n" + "select order.custid\n" + "having dow_items.item == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
eventArrived = true;
}
});
siddhiAppRuntime.start();
Thread.sleep(100);
itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
Thread.sleep(100);
AssertJUnit.assertEquals("Event Arrived", true, eventArrived);
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class OuterJoinTestCase method joinTest1.
@Test
public void joinTest1() throws InterruptedException {
log.info("Outer Join test1");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "define stream cseEventStream (symbol string, price float, volume int); " + "define stream twitterStream (user string, tweet string, company string); ";
String query = "@info(name = 'query1') " + "from cseEventStream#window.length(3) full outer join twitterStream#window.length(1) " + "on cseEventStream.symbol== twitterStream.company " + "select cseEventStream.symbol as symbol, twitterStream.tweet, cseEventStream.price " + "insert all events into outputStream ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
for (Event inEvent : inEvents) {
inEventCount++;
if (inEventCount == 1) {
AssertJUnit.assertEquals("WSO2", inEvent.getData(0));
AssertJUnit.assertEquals(null, inEvent.getData(1));
AssertJUnit.assertEquals(55.6f, inEvent.getData(2));
}
if (inEventCount == 2) {
AssertJUnit.assertEquals("WSO2", inEvent.getData(0));
AssertJUnit.assertEquals("Hello World", inEvent.getData(1));
AssertJUnit.assertEquals(55.6f, inEvent.getData(2));
}
if (inEventCount == 3) {
AssertJUnit.assertEquals("IBM", inEvent.getData(0));
AssertJUnit.assertEquals(null, inEvent.getData(1));
AssertJUnit.assertEquals(75.6f, inEvent.getData(2));
}
if (inEventCount == 4) {
AssertJUnit.assertEquals("WSO2", inEvent.getData(0));
AssertJUnit.assertEquals("Hello World", inEvent.getData(1));
AssertJUnit.assertEquals(57.6f, inEvent.getData(2));
}
}
eventArrived = true;
}
});
InputHandler cseEventStreamHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
InputHandler twitterStreamHandler = siddhiAppRuntime.getInputHandler("twitterStream");
siddhiAppRuntime.start();
cseEventStreamHandler.send(new Object[] { "WSO2", 55.6f, 100 });
twitterStreamHandler.send(new Object[] { "User1", "Hello World", "WSO2" });
cseEventStreamHandler.send(new Object[] { "IBM", 75.6f, 100 });
cseEventStreamHandler.send(new Object[] { "WSO2", 57.6f, 100 });
Thread.sleep(500);
AssertJUnit.assertEquals(4, inEventCount);
AssertJUnit.assertTrue(eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.query.output.callback.QueryCallback in project siddhi by wso2.
the class FilterTestCase2 method testFilterQuery112.
// ****************************************************************************************************************
// Expression Multiply
@Test
public void testFilterQuery112() throws InterruptedException {
log.info("Filter test112");
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("multipliedQuantity", Expression.multiply(Expression.variable("quantity"), Expression.value(4))).select("multipliedPrice", Expression.multiply(Expression.variable("price"), Expression.value(2))).select("multipliedVolume", Expression.multiply(Expression.variable("volume"), Expression.value(3))).select("multipliedAwards", Expression.multiply(Expression.variable("awards"), Expression.value(5))));
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("20".equals(inEvents[0].getData()[1].toString()));
AssertJUnit.assertTrue("111.0".equals(inEvents[0].getData()[2].toString()));
AssertJUnit.assertTrue("300.0".equals(inEvents[0].getData()[3].toString()));
AssertJUnit.assertTrue("15".equals(inEvents[0].getData()[4].toString()));
count = count + inEvents.length;
}
});
InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
siddhiAppRuntime.start();
inputHandler.send(new Object[] { "WSO2", 55.5f, 100d, 5, 3L });
Thread.sleep(100);
AssertJUnit.assertEquals(1, count);
siddhiAppRuntime.shutdown();
}
Aggregations