use of org.wso2.siddhi.query.api.execution.query.StoreQuery in project siddhi by wso2.
the class QueryStoreTestCase method test3.
@Test
public void test3() {
StoreQuery query = SiddhiCompiler.parseStoreQuery("" + "from StockTable " + "on price > 40 " + "select symbol, price " + "group by symbol " + "having (7 > price) ;");
AssertJUnit.assertNotNull(query);
StoreQuery api = StoreQuery.query().from(InputStore.store("StockTable").on(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(40)))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select(Expression.variable("price")).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.value(7), Compare.Operator.GREATER_THAN, Expression.variable("price"))));
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.siddhi.query.api.execution.query.StoreQuery in project siddhi by wso2.
the class SiddhiCompiler method parseStoreQuery.
public static StoreQuery parseStoreQuery(String storeQuery) throws SiddhiParserException {
ANTLRInputStream input = new ANTLRInputStream(storeQuery);
SiddhiQLLexer lexer = new SiddhiQLLexer(input);
lexer.removeErrorListeners();
lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
CommonTokenStream tokens = new CommonTokenStream(lexer);
SiddhiQLParser parser = new SiddhiQLParser(tokens);
parser.removeErrorListeners();
parser.addErrorListener(SiddhiErrorListener.INSTANCE);
ParseTree tree = parser.store_query_final();
SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
return (StoreQuery) eval.visit(tree);
}
use of org.wso2.siddhi.query.api.execution.query.StoreQuery in project siddhi by wso2.
the class StoreQueryTableTestCase method test10.
@Test
public void test10() throws InterruptedException {
log.info("Test10 table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "@PrimaryKey('symbol') " + "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);
String storeQuery = "" + "from StockTable " + "on volume > 10 " + "select symbol, price, sum(volume) as totalVolume ";
Event[] events = siddhiAppRuntime.query(storeQuery);
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData()[2]);
events = siddhiAppRuntime.query(storeQuery);
EventPrinter.print(events);
AssertJUnit.assertEquals(1, events.length);
AssertJUnit.assertEquals(200L, events[0].getData()[2]);
}
use of org.wso2.siddhi.query.api.execution.query.StoreQuery in project siddhi by wso2.
the class StoreQueryTableTestCase method test12.
@Test
public void test12() throws InterruptedException {
log.info("Test12 - Test output attributes and its types for table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "@PrimaryKey('symbol') " + "define table StockTable (symbol string, price float, volume long); ";
String storeQuery = "" + "from StockTable " + "select * ;";
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 volumeAttribute = new Attribute("volume", Attribute.Type.LONG);
Attribute[] expectedAttributeArray = new Attribute[] { symbolAttribute, priceAttribute, volumeAttribute };
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
storeQuery = "" + "from StockTable " + "select symbol, sum(volume) as totalVolume ;";
actualAttributeArray = siddhiAppRuntime.getStoreQueryOutputAttributes(SiddhiCompiler.parseStoreQuery(storeQuery));
Attribute totalVolumeAttribute = new Attribute("totalVolume", Attribute.Type.LONG);
expectedAttributeArray = new Attribute[] { symbolAttribute, totalVolumeAttribute };
siddhiAppRuntime.shutdown();
AssertJUnit.assertArrayEquals(expectedAttributeArray, actualAttributeArray);
}
use of org.wso2.siddhi.query.api.execution.query.StoreQuery in project siddhi by wso2.
the class StoreQueryTableTestCase method test11.
@Test
public void test11() throws InterruptedException {
log.info("Test10 table");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream StockStream (symbol string, price float, volume long);" + "@PrimaryKey('symbol') " + "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);
String storeQuery = "" + "from StockTable " + "on volume > 10 " + "select symbol, price, sum(volume) as totalVolume " + "group by symbol ";
Event[] events = siddhiAppRuntime.query(storeQuery);
EventPrinter.print(events);
AssertJUnit.assertEquals(2, events.length);
AssertJUnit.assertEquals(100L, events[0].getData()[2]);
AssertJUnit.assertEquals(100L, events[1].getData()[2]);
events = siddhiAppRuntime.query(storeQuery);
EventPrinter.print(events);
AssertJUnit.assertEquals(2, events.length);
AssertJUnit.assertEquals(100L, events[0].getData()[2]);
AssertJUnit.assertEquals(100L, events[1].getData()[2]);
}
Aggregations