Search in sources :

Example 86 with Query

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");
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 87 with Query

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");
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 88 with Query

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");
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 89 with Query

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);
}
Also used : Partition(org.ballerinalang.siddhi.query.api.execution.partition.Partition) Query(org.ballerinalang.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 90 with 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");
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Aggregations

Query (org.ballerinalang.siddhi.query.api.execution.query.Query)145 Test (org.testng.annotations.Test)137 SiddhiApp (org.ballerinalang.siddhi.query.api.SiddhiApp)83 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)82 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)82 StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)82 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)79 Event (org.ballerinalang.siddhi.core.event.Event)78 QueryCallback (org.ballerinalang.siddhi.core.query.output.callback.QueryCallback)73 Partition (org.ballerinalang.siddhi.query.api.execution.partition.Partition)9 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)6 StoreQuery (org.ballerinalang.siddhi.query.api.execution.query.StoreQuery)4 ArrayList (java.util.ArrayList)3 QueryRuntime (org.ballerinalang.siddhi.core.query.QueryRuntime)3 List (java.util.List)2 SiddhiAppContext (org.ballerinalang.siddhi.core.config.SiddhiAppContext)2 PartitionRuntime (org.ballerinalang.siddhi.core.partition.PartitionRuntime)2 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)2 ElementIdGenerator (org.ballerinalang.siddhi.core.util.ElementIdGenerator)2 SnapshotService (org.ballerinalang.siddhi.core.util.snapshot.SnapshotService)2