use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class StoreQueryTableTestCase method test2.
@Test
public void test2() throws InterruptedException {
log.info("Test2 table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (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 ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
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 });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 75 " + "select symbol, volume ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(2, events[0].getData().length);
events = siddhiAppRuntime.query("" + "from StockTable " + "select symbol, volume ");
EventPrinter.print(events);
AssertJUnit.assertEquals(3, events.length);
AssertJUnit.assertEquals(2, events[0].getData().length);
events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, volume " + "having symbol == 'WSO2' ");
EventPrinter.print(events);
AssertJUnit.assertEquals(2, events.length);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class StoreQueryTableTestCase method test13.
@Test
public void test13() throws InterruptedException {
log.info("Test13 - Test output attributes and its types for aggregation table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "define aggregation StockTableAg " + "from StockStream " + "select symbol, price " + "group by symbol " + "aggregate every minutes ...year;";
String storeQuery = "" + "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, price ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
siddhiAppRuntime.start();
Attribute[] actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute symbolAttribute = new Attribute("symbol", Attribute.Type.STRING);
Attribute priceAttribute = new Attribute("price", Attribute.Type.FLOAT);
Attribute[] expectedAttributeArray = new Attribute[] { symbolAttribute, priceAttribute };
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
storeQuery = "" + "from StockTableAg within '2018-**-** **:**:**' per 'minutes' select symbol, sum(price) as total";
actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute totalVolumeAttribute = new Attribute("total", Attribute.Type.DOUBLE);
expectedAttributeArray = new Attribute[] { symbolAttribute, totalVolumeAttribute };
siddhiAppRuntime.shutdown();
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class StoreQueryTableTestCase method test3.
@Test
public void test3() throws InterruptedException {
log.info("Test3 table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (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 ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
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 });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol " + "having totalVolume >150 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData(1));
events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol ");
EventPrinter.print(events);
AssertJUnit.assertEquals(2, events.length);
events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 5 " + "select symbol, sum(volume) as totalVolume " + "group by symbol,price ");
EventPrinter.print(events);
AssertJUnit.assertEquals(3, events.length);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class StoreQueryTableTestCase method test6.
@Test(expectedExceptions = SiddhiParserException.class)
public void test6() throws InterruptedException {
log.info("Test5 table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long); " + "define table StockTable (symbol string, price float, volume long); ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams);
try {
siddhiAppRuntime.start();
Event[] events = siddhiAppRuntime.query("" + "from StockTable1 " + "on price > 5 " + "select symbol1, sum(volume) totalVolume " + "group by symbol " + "having totalVolume >150 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData(1));
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class StoreQueryTableTestCase method test1.
@Test
public void test1() throws InterruptedException {
log.info("Test1 table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (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 ;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
InputHandler stockStream = siddhiAppRuntime.getInputHandler("StockStream");
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 });
Thread.sleep(500);
Event[] events = siddhiAppRuntime.query("" + "from StockTable ");
EventPrinter.print(events);
AssertJUnit.assertEquals(3, events.length);
events = siddhiAppRuntime.query("" + "from StockTable " + "on price > 75 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
events = siddhiAppRuntime.query("" + "from StockTable " + "on price > volume*3/4 ");
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
siddhiAppRuntime.shutdown();
}
Aggregations