use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.
the class OutputRateTestCase method testCreatingQuery3.
@Test
public void testCreatingQuery3() {
Query query = Query.query();
query.from(InputStream.stream("cseEventStream").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("lengthBatch", Expression.value(50)));
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.output(OutputRate.perSnapshot(Expression.Time.minute(1)));
query.insertInto("StockQuote");
}
use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.
the class OutputRateTestCase method testCreatingQuery1.
@Test
public void testCreatingQuery1() {
Query query = Query.query();
query.from(InputStream.stream("cseEventStream").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("lengthBatch", Expression.value(50)));
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.output(OutputRate.perTimePeriod(Expression.value(1000L)).output(OutputRate.Type.LAST));
query.insertInto("StockQuote");
}
use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.
the class OutputRateTestCase method testCreatingQuery2.
@Test
public void testCreatingQuery2() {
Query query = Query.query();
query.from(InputStream.stream("cseEventStream").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("lengthBatch", Expression.value(50)));
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.output(OutputRate.perTimePeriod(Expression.Time.minute(1)).output(OutputRate.Type.LAST));
query.insertInto("StockQuote");
}
use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.
the class PartitionQueryTestCase method testCreatingFilterQuery.
// from StockStream[ 7+9.5>price AND 100>=volume]
// insert into OutStockStream symbol, avg(price) as avgPrice
// group by symbol
// having avgPrice>50
@Test
public void testCreatingFilterQuery() {
Partition partition = Partition.partition().with("StockStream", Expression.variable("symbol")).with("StockStream1", Expression.variable("symbol")).with("StockStream2", Partition.range("LessValue", Expression.compare(Expression.value(7), Compare.Operator.GREATER_THAN, Expression.variable("price"))), Partition.range("HighValue", Expression.compare(Expression.value(9.5), Compare.Operator.LESS_THAN, Expression.variable("price1"))));
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")))));
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.insertIntoInner("OutStockStream");
partition.addQuery(query);
}
use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.
the class PatternQueryTestCase method testPatternQuery3.
// from every (e1=Stream1[price >= 30]) -> e2=Stream1[ price >= 20] -> every (e3=Stream2[ price >= e1.price]) ->
// e4=Stream3[price>74] -> e5= Stream4[symbol=='IBM']
// select e1.symbol, avg(e2.price ) as avgPrice
// insert into OutputStream
@Test
public void testPatternQuery3() {
Query query = Query.query();
query.from(InputStream.patternStream(State.next(State.every(State.stream(InputStream.stream("e1", "Stream1").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(30))))), State.next(State.stream(InputStream.stream("e2", "Stream1").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)))), State.next(State.every(State.stream(InputStream.stream("e3", "Stream2").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("price").ofStream("e1"))))), State.next(State.stream(InputStream.stream("e4", "Stream3").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(74)))), State.stream(InputStream.stream("e5", "Stream4").filter(Expression.compare(Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.value("IBM"))))))))));
query.select(Selector.selector().select("symbol", Expression.variable("symbol").ofStream("e1")).select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2"))));
query.insertInto("OutputStream");
}
Aggregations