use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class SimpleQueryTestCase method test17.
@Test
public void test17() {
Query queryString = SiddhiCompiler.parseQuery("" + "from StockStream[7+9.5 > price and 100 >= volume]#window.length(50) " + " " + "select symbol as symbol, price as price, volume as volume " + "update or insert into StockQuote \n " + " set StockQuote.price = price, \n " + " StockQuote.volume = volume " + " on symbol==StockQuote.symbol ;");
AssertJUnit.assertNotNull(queryString);
Query query = Query.query();
query.from(InputStream.stream("StockStream").filter(Expression.and(Expression.compare(Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume")))).window("length", Expression.value(50)));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
query.updateOrInsertBy("StockQuote", UpdateStream.updateSet().set(Expression.variable("price").ofStream("StockQuote"), Expression.variable("price")).set(Expression.variable("volume").ofStream("StockQuote"), Expression.variable("volume")), Expression.compare(Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.variable("symbol").ofStream("StockQuote")));
AssertJUnit.assertEquals(query.toString(), queryString.toString());
AssertJUnit.assertTrue(query.equals(query));
AssertJUnit.assertFalse(query.equals("query"));
}
use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class SimpleQueryTestCase method test5.
@Test
public void test5() throws SiddhiParserException {
Query query = SiddhiCompiler.parseQuery("from AllStockQuotes[price==Foo.price and Foo.try<5] " + "select symbol, avg(price) as avgPrice " + "return ;");
AssertJUnit.assertNotNull(query);
Query api = Query.query().from(InputStream.stream("AllStockQuotes").filter(Expression.and(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("Foo")), Expression.compare(Expression.variable("try").ofStream("Foo"), Compare.Operator.LESS_THAN, Expression.value(5))))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))));
AssertJUnit.assertEquals(api, query);
}
use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class SimpleQueryTestCase method test1.
@Test
public void test1() throws SiddhiParserException {
Query query = SiddhiCompiler.parseQuery("from StockStream[price>3]#window.length(50) " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having (price >= 20) " + "insert all events into StockQuote; ");
AssertJUnit.assertNotNull(query);
Query api = Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(3))).window("length", Expression.value(50))).select(Selector.selector().select(Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)))).insertInto("StockQuote", OutputStream.OutputEventType.ALL_EVENTS);
AssertJUnit.assertEquals(api, query);
}
use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class SimpleQueryTestCase method test11.
@Test
public void test11() throws SiddhiParserException {
Query query = SiddhiCompiler.parseQuery("from StockStream[price>3]#window.length(50) " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having (price >= 20)" + "order by avgPrice " + "limit 5 " + "insert all events into StockQuote; ");
AssertJUnit.assertNotNull(query);
Query api = Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(3))).window("length", Expression.value(50))).select(Selector.selector().select(Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))).orderBy(Expression.variable("avgPrice")).limit(Expression.value(5))).insertInto("StockQuote", OutputStream.OutputEventType.ALL_EVENTS);
AssertJUnit.assertEquals(api, query);
}
use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class SimpleQueryTestCase method test8.
@Test
public void test8() {
Query query = SiddhiCompiler.parseQuery("from StockStream[7-9.5 > price and 100 >= volume]#window.length(50)" + "#[symbol=='WSO2'] " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having avgPrice >= 50 " + "insert into OutStockStream ;");
AssertJUnit.assertNotNull(query);
Query api = Query.query();
api.from(InputStream.stream("StockStream").filter(Expression.and(Expression.compare(Expression.subtract(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume")))).window("length", Expression.value(50)).filter(Expression.compare(Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.value("WSO2"))));
api.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(50))));
api.insertInto("OutStockStream");
AssertJUnit.assertEquals(api, query);
}
Aggregations