Java Code Examples for io.siddhi.query.compiler.SiddhiCompiler#parseQuery()
The following examples show how to use
io.siddhi.query.compiler.SiddhiCompiler#parseQuery() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void test2() throws SiddhiParserException { Query query = SiddhiCompiler.parseQuery("from StockStream [price >= 20]#window.lengthBatch(50) " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having avgPrice>50 " + "insert into StockQuote; " ); AssertJUnit.assertNotNull(query); Query api = Query.query().from(InputStream.stream("StockStream"). filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))). window("lengthBatch", 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("avgPrice"), Compare.Operator.GREATER_THAN, Expression.value(50)))). insertInto("StockQuote"); AssertJUnit.assertEquals(api, query); }
Example 2
Source File: AbsentPatternTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void test4() throws SiddhiParserException { Query query = SiddhiCompiler.parseQuery("from e1=Stream1[price>20] -> not Stream2[price>e1.price] for 2 sec " + "select e1.symbol as symbol1 " + "insert into OutputStream ;"); AssertJUnit.assertNotNull(query); Query api = Query.query(); api.from( InputStream.patternStream(State.next( State.stream(InputStream.stream("e1", "Stream1") .filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(20)))), State.logicalNot(State.stream(InputStream.stream("Stream2") .filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("e1")))), new TimeConstant(2000))) )) .select(Selector.selector().select("symbol1", Expression.variable("symbol").ofStream("e1"))) .insertInto("OutputStream"); AssertJUnit.assertEquals(api, query); }
Example 3
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void test4() throws SiddhiParserException { Query query = SiddhiCompiler.parseQuery("from AllStockQuotes#window.lengthBatch(50) " + "select symbol, avg(price) as avgPrice " + "return ;" ); AssertJUnit.assertNotNull(query); Query api = Query.query().from(InputStream.stream("AllStockQuotes"). window("lengthBatch", Expression.value(50))). select(Selector.selector(). select("symbol", Expression.variable("symbol")). select("avgPrice", Expression.function("avg", Expression.variable("price")))). returns(); AssertJUnit.assertEquals(api, query); }
Example 4
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@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); }
Example 5
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = UnsupportedAttributeTypeException.class) public void test19() 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 " + "offset 3 " + "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)). offset(Expression.value(3.8))). insertInto("StockQuote", OutputStream.OutputEventType.ALL_EVENTS); }
Example 6
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void test15() { 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 " + " 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, Expression.compare( Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.variable("symbol").ofStream("StockQuote"))); AssertJUnit.assertEquals(query, queryString); }
Example 7
Source File: DefineAggregationTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void test3() throws SiddhiParserException { Query query = SiddhiCompiler .parseQuery("from barStream as b join cseEventAggregation as a " + "on a.symbol == b.symbol " + "within \"2014-02-15T00:00:00Z\", \"2014-03-16T00:00:00Z\" " + "per \"day\" " + "select a.symbol, a.total, a.avgPrice " + "insert into fooBar;"); Query queryApi = Query.query(). from(InputStream.joinStream( InputStream.stream("b", "barStream"), JoinInputStream.Type.JOIN, InputStream.stream("a", "cseEventAggregation"), Expression.compare( Expression.variable("symbol").ofStream("a"), Compare.Operator.EQUAL, Expression.variable("symbol").ofStream("b")), Within.within(Expression.value("2014-02-15T00:00:00Z"), Expression.value("2014-03-16T00:00:00Z")), Expression.value("day") ) ). select( Selector.selector(). select(Expression.variable("symbol").ofStream("a")). select(Expression.variable("total").ofStream("a")). select(Expression.variable("avgPrice").ofStream("a")) ). insertInto("fooBar"); AssertJUnit.assertEquals(queryApi, query); }
Example 8
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@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); }
Example 9
Source File: AbsentPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = SiddhiParserException.class) public void test1() throws SiddhiParserException { SiddhiCompiler.parseQuery("from e1=Stream1[price>20] -> not Stream2[price>e1.price] " + "select e1.symbol as symbol, e1.price as price " + "insert into OutputStream ;"); }
Example 10
Source File: AbsentPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = SiddhiParserException.class) public void test2() throws SiddhiParserException { SiddhiCompiler.parseQuery("from e1=Stream1[price>20] -> not e2=Stream2[price>e1.price] for 1 sec " + "select e1.symbol as symbol, e1.price as price " + "insert into OutputStream ;"); }
Example 11
Source File: AbsentPatternTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = SiddhiParserException.class) public void test3() throws SiddhiParserException { SiddhiCompiler.parseQuery("from not Stream1[price>20] for 1 sec -> not Stream2[price>e1.price] for 1 sec " + "select e1.symbol as symbol, e1.price as price " + "insert into OutputStream ;"); }
Example 12
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void test3() throws SiddhiParserException { Query query = SiddhiCompiler.parseQuery("from AllStockQuotes#window.time(10 min)\n" + "select symbol as symbol, price, avg(price) as averagePrice \n" + "group by symbol \n" + "having ( price > ( averagePrice*1.02) ) or ( averagePrice > price ) " + "insert into FastMovingStockQuotes \n;"); Query api = Query.query().from(InputStream.stream("AllStockQuotes"). window("time", Expression.Time.minute(10))). select(Selector.selector(). select("symbol", Expression.variable("symbol")). select(Expression.variable("price")). select("averagePrice", Expression.function("avg", Expression.variable("price"))). groupBy(Expression.variable("symbol")). having(Expression.or( Expression.compare( Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.multiply(Expression.variable("averagePrice"), Expression.value (1.02))), Expression.compare( Expression.variable("averagePrice"), Compare.Operator.GREATER_THAN, Expression.variable("price"))))). insertInto("FastMovingStockQuotes"); AssertJUnit.assertEquals(api, query); }
Example 13
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@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); }
Example 14
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void test9() { Query query = SiddhiCompiler.parseQuery("from StockStream[7-9.5 > price and 100 >= volume]#bar(price)#window" + ".length(50)#foo(67,89)#[10<=price] " + "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") ) ) ). function("bar", Expression.variable("price")). window("length", Expression.value(50)). function("foo", Expression.value(67), Expression.value(89)). filter( Expression.compare( Expression.value(10), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("price") ) ) ); 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); }
Example 15
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@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); }
Example 16
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void test7() { Query query = SiddhiCompiler.parseQuery("from StockStream[7+9.5 < price or 100 <= volume]#window.length(50) " + " " + "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.or( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.LESS_THAN, Expression.variable("price")), Expression.compare( Expression.value(100), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("volume") ) ) ).window("length", Expression.value(50)) ); 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.NOT_EQUAL, Expression.value(50) )) ); api.insertInto("OutStockStream"); AssertJUnit.assertEquals(api, query); }
Example 17
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void test14() { 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", 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); }
Example 18
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@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); }
Example 19
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void test16() { 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", 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); }
Example 20
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@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")); }