Search in sources :

Example 21 with Query

use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.

the class SimpleQueryTestCase method testCreatingReturnFilterQueryWithFunction.

@Test
public void testCreatingReturnFilterQueryWithFunction() {
    Query query = Query.query();
    query.from(InputStream.stream("StockStream").filter(Expression.and(Expression.compare(Expression.function("FooBarCond", Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")), Expression.function("BarCond", Expression.value(100), Expression.variable("volume")))).function("ext", "Foo", Expression.value(67), Expression.value(89)).window("ext", "lengthFirst10", Expression.value(50)));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("ext", "avg", Expression.variable("symbol"))));
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 22 with Query

use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.

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

Example 23 with Query

use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.

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

Example 24 with Query

use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.

the class SimpleQueryTestCase method test10.

@Test
public void test10() {
    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 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.updateBy("StockQuote", OutputStream.OutputEventType.CURRENT_EVENTS, 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, queryString);
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 25 with Query

use of org.ballerinalang.siddhi.query.api.execution.query.Query in project ballerina by ballerina-lang.

the class SimpleQueryTestCase method test6.

// 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 test6() {
    Query query = SiddhiCompiler.parseQuery("from  StockStream[7+9.5 > price and 100 >= volume]  " + "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.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")))));
    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);
}
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