Search in sources :

Example 26 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class SimpleQueryTestCase method test17.

@Test
public void test17() {
    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 or insert into 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.updateOrInsertBy("StockQuote", 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.toString(), queryString.toString());
    AssertJUnit.assertTrue(query.equals(query));
    AssertJUnit.assertFalse(query.equals("query"));
}
Also used : Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 27 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

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(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 28 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class SimpleQueryTestCase method test1.

@Test
public void test1() 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) " + "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)))).insertInto("StockQuote", OutputStream.OutputEventType.ALL_EVENTS);
    AssertJUnit.assertEquals(api, query);
}
Also used : Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 29 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class SimpleQueryTestCase method test11.

@Test
public void test11() 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 " + "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")).limit(Expression.value(5))).insertInto("StockQuote", OutputStream.OutputEventType.ALL_EVENTS);
    AssertJUnit.assertEquals(api, query);
}
Also used : Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 30 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class SimpleQueryTestCase method test8.

@Test
public void test8() {
    Query query = SiddhiCompiler.parseQuery("from  StockStream[7-9.5 > price and 100 >= volume]#window.length(50)" + "#[symbol=='WSO2']  " + "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.subtract(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)).filter(Expression.compare(Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.value("WSO2"))));
    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(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Aggregations

Query (io.siddhi.query.api.execution.query.Query)192 Test (org.testng.annotations.Test)181 SiddhiApp (io.siddhi.query.api.SiddhiApp)86 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)85 SiddhiManager (io.siddhi.core.SiddhiManager)85 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)85 InputHandler (io.siddhi.core.stream.input.InputHandler)82 Event (io.siddhi.core.event.Event)81 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)74 Partition (io.siddhi.query.api.execution.partition.Partition)14 StreamCallback (io.siddhi.core.stream.output.StreamCallback)8 ArrayList (java.util.ArrayList)7 QueryRuntimeImpl (io.siddhi.core.query.QueryRuntimeImpl)4 OnDemandQuery (io.siddhi.query.api.execution.query.OnDemandQuery)4 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)3 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 Window (io.siddhi.core.window.Window)3 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)3 ExecutionElement (io.siddhi.query.api.execution.ExecutionElement)3 JoinInputStream (io.siddhi.query.api.execution.query.input.stream.JoinInputStream)3