Java Code Examples for io.siddhi.query.api.execution.query.Query#query()
The following examples show how to use
io.siddhi.query.api.execution.query.Query#query() .
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: SequenceQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testSequenceQuery() { Query query = Query.query(); query.from( InputStream.sequenceStream( State.next(State.stream(InputStream.stream("e1", "Stream1")), State.stream(InputStream.stream("e2", "Stream1")) ))); query.insertInto("OutputStream"); query.select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("e1")). select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2", 0))). groupBy(Expression.variable("symbol").ofStream("e1")). having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.GREATER_THAN, Expression.value(50))) ); }
Example 2
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@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"))) ); }
Example 3
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testCreatingNestedFilterQuery() { Query query = Query.query(); query.from(InputStream.stream( Query.query(). from(InputStream.stream("StockStream"). filter( Expression.compare( Expression.variable("price").ofStream("StockStream"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)) ).filter(Expression.isNull(Expression.variable("price").ofStream("StockStream")))). select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("avgPrice", Expression.function("avg", Expression.variable("price"))) ). returns()) ); query.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("avgPrice", Expression.variable("avgPrice")) ); query.insertInto("IBMOutStockStream"); }
Example 4
Source File: TableQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void testCreatingDeleteQuery() { 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.deleteBy("StockQuote", Expression.compare( Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.variable("symbol").ofStream("StockQuote"))); }
Example 5
Source File: OutputRateTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test(expectedExceptions = UnsupportedAttributeTypeException.class) public void testCreatingQuery6() { 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.perEvents(Expression.value(21.3)).output(OutputRate.Type.ALL)); query.insertInto("StockQuote"); }
Example 6
Source File: PatternQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPatternQuery16() { 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.oneOrMany( State.stream(InputStream.stream("e2", "Stream1").filter(Expression .compare(Expression.variable("price").ofStream("e2", Variable .LAST), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)))) ), State.next( State.stream(InputStream.stream("e3", "Stream2").filter(Expression .compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("price").ofStream("e1")))), State.stream(InputStream.stream("e4", "Stream3").filter(Expression .compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(74))))) ) ) ) ); query.select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("e1")). select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2"))) ); query.insertInto("OutputStream"); }
Example 7
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void test3() { List<OrderByAttribute> list = new ArrayList<>(); list.add(new OrderByAttribute(Expression.variable("avgPrice"), OrderByAttribute.Order.ASC)); 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"))). addOrderByList(list). limit(Expression.value(5)) ); }
Example 8
Source File: PatternQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPatternQuery10() { 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.next( State.stream(InputStream.stream("e2", "Stream1").filter(Expression .compare(Expression.variable("price").ofStream("e2", Variable .LAST), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)))), State.stream(InputStream.stream("e3", "Stream2").filter(Expression .compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("price").ofStream("e1"))))), State.stream(InputStream.stream("e4", "Stream3").filter(Expression.compare (Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(74)))) ) ), Expression.Time.minute(4) ) ); query.select( Selector.selector(). select("symbol", Expression.variable("symbol").ofStream("e1")). select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2"))) ); query.insertInto("OutputStream"); }
Example 9
Source File: OutputRateTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testCreatingQuery5() { 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.perEvents(Expression.value(1000L)).output(OutputRate.Type.ALL)); query.insertInto("StockQuote"); }
Example 10
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testCreatingFilterQueryWithExpression() { Query query = Query.query(); Variable variable = new Variable("price"); Variable variable1 = new Variable("symbol"); variable.setFunctionId("func1"); variable.setAttributeName("price"); variable.setFunctionIndex(1); variable.setStreamId(true, true, "func"); variable1.setStreamId(false, true, "func2"); query.from( InputStream.stream("StockStream"). filter(Expression.and(Expression.compare(Expression.function("ext", "FooBarCond", Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable(variable.getAttributeName())), Expression.function("ext", "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("price"))) ); AssertJUnit.assertTrue(variable.isInnerStream()); AssertJUnit.assertEquals(variable.getFunctionId(), "func1"); AssertJUnit.assertEquals(Integer.toString(variable.getFunctionIndex()), "1"); }
Example 11
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testCreatingFilterQueryWithFaultStream2() { Query query = Query.query(); query.from( InputStream.faultStream("e1", "StockStream"). filter( Expression.and( Expression.compare( Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price").ofStream("e1")), Expression.compare( Expression.value(100), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("volume").ofStream("e1") ) ) ) ); 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.insertIntoFault("OutStockStream"); SiddhiApp.siddhiApp("test").addQuery(query); }
Example 12
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testCreatingFilterQuery() { 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.insertInto("OutStockStream"); SiddhiApp.siddhiApp("test").addQuery(query); }
Example 13
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testQuery2() { 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)). filter( Expression.compare( Expression.variable("symbol"), Compare.Operator.EQUAL, Expression.value("WSO2") ) ) ); query.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) )) ); query.insertInto("OutStockStream"); }
Example 14
Source File: OutputRateTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testCreatingQuery4() { 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.value(1000L))); query.insertInto("StockQuote"); }
Example 15
Source File: OutputRateTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@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"); }
Example 16
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testQuery5() { StreamFunction streamFunction = new StreamFunction("funcNameSpace", "function1"); 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") ) ) ). function(streamFunction). 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") ) ) ); query.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) )) ); query.insertInto("OutStockStream"); }
Example 17
Source File: PatternQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPatternQuery13() { 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.count( State.stream(InputStream.stream("e2", "Stream1").filter(Expression .compare(Expression.variable("price"). ofFunction("f1").ofInnerStream("e2", Variable .LAST), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)))), 3, 5), State.next( State.stream(InputStream.stream("e3", "Stream2").filter(Expression .compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("price").ofInnerStream("e1")))), State.stream(InputStream.stream("e4", "Stream3").filter(Expression .compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(74))))) ) ) ) ); query.select( Selector.selector(). select("symbol", Expression.variable("symbol").ofInnerStream("e1")). select("avgPrice", Expression.function("avg", Expression.variable("price").ofInnerStream("e2"))) ); String streamStateEleString = State.stream(InputStream.stream("e3", "Stream2").filter(Expression .compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("price").ofStream("e1")))).toString(); query.insertInto("OutputStream"); }
Example 18
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery17() throws InterruptedException { log.info("Partition test17"); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiApp siddhiApp = new SiddhiApp("plan17"); StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT); siddhiApp.defineStream(streamDefinition); Partition partition = Partition.partition(). with("cseEventStream", Partition.range("LessValue", Expression.compare( Expression.value(200), Compare.Operator.GREATER_THAN, Expression.variable("volume")) ), Partition.range("HighValue", Expression.compare( Expression.value(200), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("volume")) )); Query query = Query.query(); query.from(InputStream.stream("cseEventStream")); query.select( Selector.selector(). select("sumvolume", Expression.function("sum", Expression.variable("volume"))) ); query.insertInto("StockStream"); partition.addQuery(query); siddhiApp.addPartition(partition); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("StockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); for (Event event : events) { count.incrementAndGet(); if (count.get() == 1) { AssertJUnit.assertEquals(100L, event.getData()[0]); } else if (count.get() == 2) { AssertJUnit.assertEquals(600L, event.getData()[0]); } else if (count.get() == 3) { AssertJUnit.assertEquals(200L, event.getData()[0]); } else if (count.get() == 4) { AssertJUnit.assertEquals(250L, event.getData()[0]); } eventArrived = true; } } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"WSO2", 75.6f, 600}); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); Thread.sleep(100); inputHandler.send(new Object[]{"ORACLE", 75.6f, 50}); SiddhiTestHelper.waitForEvents(100, 4, count, 60000); AssertJUnit.assertEquals(4, count.get()); siddhiAppRuntime.shutdown(); }
Example 19
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testCreatingNestedFilterQuery() { Query query1 = SiddhiCompiler.parseQuery("from from StockStream[StockStream.price >= 20][ StockStream.price " + "is null] " + "select symbol, avg(price) as avgPrice " + "return " + "select symbol, avgPrice " + "insert into OutStockStream ;" ); AssertJUnit.assertNotNull(query1); Query query2 = SiddhiCompiler.parseQuery("from ( from StockStream[StockStream.price >= 20][ StockStream" + ".price is null] " + "select symbol, avg(price) as avgPrice " + "return ) " + "select symbol, avgPrice " + "insert into OutStockStream ;" ); AssertJUnit.assertNotNull(query2); Query api = Query.query(); api.from(InputStream.stream( Query.query(). from(InputStream.stream("StockStream"). filter( Expression.compare( Expression.variable("price").ofStream("StockStream"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)) ).filter(Expression.isNull(Expression.variable("price").ofStream("StockStream")))). select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("avgPrice", Expression.function("avg", Expression.variable("price"))) ). returns()) ); api.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("avgPrice", Expression.variable("avgPrice")) ); api.insertInto("OutStockStream"); AssertJUnit.assertEquals(api, query1); AssertJUnit.assertEquals(api, query2); }
Example 20
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery3() throws InterruptedException { log.info("Partition test3"); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiApp siddhiApp = new SiddhiApp("plan3"); StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT); siddhiApp.defineStream(streamDefinition); Partition partition = Partition.partition(). with("cseEventStream", Expression.variable("symbol")); Query query = Query.query(); query.from(InputStream.stream("cseEventStream")); query.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("price", Expression.variable("price")). select("volume", Expression.variable("volume")) ); query.insertIntoInner("StockStream"); Query query1 = Query.query(); query1.from(InputStream.innerStream("StockStream")); query1.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("price", Expression.variable("price")). select("volume", Expression.variable("volume")) ); query1.insertInto("OutStockStream"); partition.addQuery(query); partition.addQuery(query1); siddhiApp.addPartition(partition); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("OutStockStream", new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); count.addAndGet(events.length); eventArrived = true; } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"WSO2", 75.6f, 100}); inputHandler.send(new Object[]{"IBM", 75.6f, 100}); inputHandler.send(new Object[]{"ORACLE", 75.6f, 100}); SiddhiTestHelper.waitForEvents(100, 4, count, 60000); siddhiAppRuntime.shutdown(); AssertJUnit.assertEquals(4, count.get()); }