use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class SimpleQueryTestCase method testQuery7.
@Test
public void testQuery7() {
Query query = Query.query();
query.from(InputStream.faultStream("StockStream").filter(Expression.isNullFaultStream("StockStream", 1)));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(50))));
query.insertIntoFault("OutStockStream");
SiddhiApp.siddhiApp("test").addQuery(query);
}
use of io.siddhi.query.api.execution.query.Query 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 query = Query.query();
query.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()));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.variable("avgPrice")));
query.insertInto("IBMOutStockStream");
}
use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class SimpleQueryTestCase method testCreatingReturnFilterQueryLimitAndSortError2.
@Test(expectedExceptions = UnsupportedAttributeTypeException.class)
public void testCreatingReturnFilterQueryLimitAndSortError2() {
Query query = Query.query();
query.from(InputStream.stream("StockStream"));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).orderBy(Expression.variable("avgPrice")).limit(Expression.value(5.0F)));
}
use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class SimpleQueryTestCase method testQuery9.
@Test
public void testQuery9() {
Query query = Query.query();
query.from(InputStream.faultStream("StockStream").filter(Expression.isNullInnerStream("StockStream")));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(50))));
query.insertIntoFault("OutStockStream");
SiddhiApp.siddhiApp("test").addQuery(query);
}
use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.
the class JoinQueryTestCase method testCreatingJoinQuery.
@Test
public void testCreatingJoinQuery() {
Query query = Query.query().annotation(Annotation.annotation("foo").element("name", "Query1").element("summery", "Test Query").element("Custom")).from(InputStream.joinStream(InputStream.stream("s1", "cseEventStream").window("lengthBatch", Expression.value(50)), JoinInputStream.Type.JOIN, InputStream.stream("s2", "cseEventStream").filter(Expression.and(Expression.compare(Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("cseEventStream")), Expression.compare(Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("cseEventStream")))).window("lengthBatch", Expression.value(50)), Expression.compare(Expression.variable("price").ofStream("s1"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("s2")))).select(Selector.selector().select("symbol", Expression.variable("symbol").ofStream("cseEventStream")).select(null, Expression.variable("symbol").ofStream("cseEventStream")).groupBy(Expression.variable("symbol").ofStream("cseEventStream")).having(Expression.compare(Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")))).insertInto("StockQuote", OutputStream.OutputEventType.EXPIRED_EVENTS);
List<String> streamIds = new ArrayList<>();
streamIds.add("cseEventStream");
Assert.assertEquals(query.getInputStream().getAllStreamIds(), streamIds);
Assert.assertEquals(query.getInputStream().getUniqueStreamIds(), streamIds);
}
Aggregations