use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class UpdateOrInsertTableTestCase method updateOrInsertTableTest9.
@Test
public void updateOrInsertTableTest9() throws InterruptedException {
log.info("updateOrInsertTableTest9");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long, price float); " + "define stream UpdateStockStream (comp string, vol long); " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream left outer join StockTable " + " on UpdateStockStream.comp == StockTable.symbol " + "select symbol, ifThenElse(price is null,0f,price) as price, vol as volume " + "update or insert into StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume and price==StockTable" + ".price) in StockTable] " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query3", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L, 155.6f }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 200L, 155.6f }, event.getData());
break;
default:
AssertJUnit.assertSame(2, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 155.6f, 100L });
checkStockStream.send(new Object[] { "IBM", 100L, 155.6f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
updateStockStream.send(new Object[] { "IBM", 200L });
checkStockStream.send(new Object[] { "IBM", 200L, 155.6f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
Thread.sleep(500);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class UpdateOrInsertTableTestCase method updateOrInsertTableTest7.
@Test
public void updateOrInsertTableTest7() throws InterruptedException {
log.info("updateOrInsertTableTest7");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long, price float); " + "define stream UpdateStockStream (comp string, vol long); " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "select comp as symbol, 0f as price, vol as volume " + "update or insert into StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume and price==StockTable" + ".price) in StockTable] " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query3", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L, 155.6f }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 200L, 0f }, event.getData());
break;
default:
AssertJUnit.assertSame(2, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 155.6f, 100L });
checkStockStream.send(new Object[] { "IBM", 100L, 155.6f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
updateStockStream.send(new Object[] { "IBM", 200L });
checkStockStream.send(new Object[] { "IBM", 200L, 0f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
Thread.sleep(500);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class UpdateOrInsertTableTestCase method updateOrInsertTableTest4.
@Test
public void updateOrInsertTableTest4() throws InterruptedException {
log.info("updateOrInsertTableTest4");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query2') " + "from StockStream " + "update or insert into StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume) in StockTable] " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query3", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
break;
case 3:
AssertJUnit.assertArrayEquals(new Object[] { "WSO2", 100L }, event.getData());
break;
default:
AssertJUnit.assertSame(3, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 55.6f, 100L });
checkStockStream.send(new Object[] { "IBM", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
stockStream.send(new Object[] { "IBM", 77.6f, 200L });
checkStockStream.send(new Object[] { "IBM", 100L });
checkStockStream.send(new Object[] { "WSO2", 100L });
Thread.sleep(500);
AssertJUnit.assertEquals("Number of success events", 3, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class UpdateOrInsertTableTestCase method updateOrInsertTableTest8.
@Test
public void updateOrInsertTableTest8() throws InterruptedException {
log.info("updateOrInsertTableTest8");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream CheckStockStream (symbol string, volume long, price float); " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query2') " + "from StockStream " + "select symbol, price, volume " + "update or insert into StockTable " + " on StockTable.symbol==symbol;" + "" + "@info(name = 'query3') " + "from CheckStockStream[(symbol==StockTable.symbol and volume==StockTable.volume and price==StockTable" + ".price) in StockTable] " + "insert into OutStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
siddhiAppRuntime.addCallback("query3", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
EventPrinter.print(timestamp, inEvents, removeEvents);
if (inEvents != null) {
for (Event event : inEvents) {
inEventCount++;
switch(inEventCount) {
case 1:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 100L, 155.6f }, event.getData());
break;
case 2:
AssertJUnit.assertArrayEquals(new Object[] { "IBM", 200L, 155.6f }, event.getData());
break;
default:
AssertJUnit.assertSame(2, inEventCount);
}
}
eventArrived = true;
}
if (removeEvents != null) {
removeEventCount = removeEventCount + removeEvents.length;
}
eventArrived = true;
}
});
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler checkStockStream = siddhiAppRuntime.getInputHandler("CheckStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 155.6f, 100L });
checkStockStream.send(new Object[] { "IBM", 100L, 155.6f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
stockStream.send(new Object[] { "IBM", 155.6f, 200L });
checkStockStream.send(new Object[] { "IBM", 200L, 155.6f });
checkStockStream.send(new Object[] { "WSO2", 100L, 155.6f });
Thread.sleep(500);
AssertJUnit.assertEquals("Number of success events", 2, inEventCount);
AssertJUnit.assertEquals("Number of remove events", 0, removeEventCount);
AssertJUnit.assertEquals("Event arrived", true, eventArrived);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.query.api.expression.condition.In in project siddhi by wso2.
the class SetUpdateInMemoryTableTestCase method updateFromTableTest4.
@Test
public void updateFromTableTest4() throws InterruptedException, SQLException {
log.info("SET-RDBMS-update test case 4: using one of the output attribute values in the " + "select clause as the assignment expression.");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define stream UpdateStockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
String query = "" + "@info(name = 'query1') " + "from StockStream " + "insert into StockTable ;" + "" + "@info(name = 'query2') " + "from UpdateStockStream " + "select price + 100 as newPrice , symbol " + "update StockTable " + "set StockTable.price = newPrice " + " on StockTable.symbol == symbol ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
InputHandler updateStockStream = siddhiAppRuntime.getInputHandler("UpdateStockStream");
siddhiAppRuntime.start();
stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
stockStream.send(new Object[] { "IBM", 75.6f, 100L });
stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
updateStockStream.send(new Object[] { "IBM", 100f, 100L });
Thread.sleep(1000);
siddhiAppRuntime.shutdown();
}
Aggregations