use of org.wso2.charon3.core.objects.Group 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.charon3.core.objects.Group in project siddhi by wso2.
the class SimpleQueryTestCase method test12.
@Test
public void test12() 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 desc " + "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"), OrderByAttribute.Order.DESC).limit(Expression.value(5))).insertInto("StockQuote", OutputStream.OutputEventType.ALL_EVENTS);
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.
the class SimpleQueryTestCase method test7.
@Test
public void test7() {
Query query = SiddhiCompiler.parseQuery("from StockStream[7+9.5 < price or 100 <= volume]#window.length(50) " + " " + "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.or(Expression.compare(Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.LESS_THAN, Expression.variable("price")), Expression.compare(Expression.value(100), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("volume")))).window("length", Expression.value(50)));
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.NOT_EQUAL, Expression.value(50))));
api.insertInto("OutStockStream");
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.
the class SimpleQueryTestCase method test2.
@Test
public void test2() throws SiddhiParserException {
Query query = SiddhiCompiler.parseQuery("from StockStream [price >= 20]#window.lengthBatch(50) " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having avgPrice>50 " + "insert into StockQuote; ");
AssertJUnit.assertNotNull(query);
Query api = Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))).window("lengthBatch", 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("avgPrice"), Compare.Operator.GREATER_THAN, Expression.value(50)))).insertInto("StockQuote");
AssertJUnit.assertEquals(api, query);
}
use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.
the class SimpleQueryTestCase method testCreatingNestedFilterQuery.
// from (from StockStream[win.length(50)][ price >= 20]
// return symbol, avg(price) as avgPrice
// group by symbol) [symbol=="IBM"]
// insert into IBMOutStockStream symbol, avgPrice
@Test
public void testCreatingNestedFilterQuery() {
Query query1 = SiddhiCompiler.parseQuery("from from StockStream[StockStream.price >= 20][ StockStream.price " + "is null] " + "select symbol, avg(price) as avgPrice " + "return " + "select symbol, avgPrice " + "insert into OutStockStream ;");
AssertJUnit.assertNotNull(query1);
Query query2 = SiddhiCompiler.parseQuery("from ( from StockStream[StockStream.price >= 20][ StockStream" + ".price is null] " + "select symbol, avg(price) as avgPrice " + "return ) " + "select symbol, avgPrice " + "insert into OutStockStream ;");
AssertJUnit.assertNotNull(query2);
Query api = Query.query();
api.from(InputStream.stream(Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price").ofStream("StockStream"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))).filter(Expression.isNull(Expression.variable("price").ofStream("StockStream")))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price")))).returns()));
api.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.variable("avgPrice")));
api.insertInto("OutStockStream");
AssertJUnit.assertEquals(api, query1);
AssertJUnit.assertEquals(api, query2);
}
Aggregations