Java Code Examples for io.siddhi.query.api.execution.query.Query#insertInto()
The following examples show how to use
io.siddhi.query.api.execution.query.Query#insertInto() .
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: FilterTestCase2.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery98() throws InterruptedException { log.info("Filter test98"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE) .attribute("quantity", Attribute.Type.INT); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(60L)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price")).select("quantity", Expression.variable("quantity"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 500f, 50d, 6}); inputHandler.send(new Object[]{"WSO2", 70f, 60d, 2}); inputHandler.send(new Object[]{"WSO2", 50f, 300d, 4}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); AssertJUnit.assertEquals(2, count.get()); siddhiAppRuntime.shutdown(); }
Example 2
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery17() throws InterruptedException { log.info("Filter test17"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.GREATER_THAN, Expression.value(45)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price")).select("volume", Expression.variable("volume"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60L}); inputHandler.send(new Object[]{"WSO2", 70f, 40L}); inputHandler.send(new Object[]{"WSO2", 44f, 200L}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); siddhiAppRuntime.shutdown(); }
Example 3
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery54() throws InterruptedException { log.info("Filter test54"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL, Expression.value(50d)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); siddhiAppRuntime.shutdown(); }
Example 4
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery72() throws InterruptedException { log.info("Filter test72"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE) .attribute("quantity", Attribute.Type.INT); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(200L)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price")).select("quantity", Expression.variable("quantity"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 500f, 60d, 5}); inputHandler.send(new Object[]{"WSO2", 70f, 60d, 2}); inputHandler.send(new Object[]{"WSO2", 60f, 300d, 4}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); siddhiAppRuntime.shutdown(); }
Example 5
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery82() throws InterruptedException { log.info("Filter test82"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN, Expression.value(50)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50d, 60d}); inputHandler.send(new Object[]{"WSO2", 70d, 40d}); inputHandler.send(new Object[]{"WSO2", 44d, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); siddhiAppRuntime.shutdown(); }
Example 6
Source File: FilterTestCase2.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery87() throws InterruptedException { log.info("Filter test87"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN, Expression.value(50d)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); AssertJUnit.assertEquals(1, count.get()); siddhiAppRuntime.shutdown(); }
Example 7
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery51() throws InterruptedException { log.info("Filter test51"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.EQUAL, Expression.value(60f)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); siddhiAppRuntime.shutdown(); }
Example 8
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery66() throws InterruptedException { log.info("Filter test66"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.not(Expression.compare(Expression.variable ("volume"), Compare.Operator.EQUAL, Expression.value(40))))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60L}); inputHandler.send(new Object[]{"WSO2", 70f, 40L}); inputHandler.send(new Object[]{"WSO2", 44f, 200L}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); siddhiAppRuntime.shutdown(); }
Example 9
Source File: PatternQueryTestCase.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testPatternQuery4() { Query query = Query.query(); query.from( InputStream.patternStream( State.next( State.every( State.next( State.stream(InputStream.stream("e1", "Stream1").filter(Expression .compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(30)))), State.stream(InputStream.stream("e2", "Stream1").filter(Expression .compare(Expression.variable("price"), 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 10
Source File: FilterTestCase2.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery94() throws InterruptedException { log.info("Filter test94"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(50d)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); AssertJUnit.assertEquals(2, count.get()); siddhiAppRuntime.shutdown(); }
Example 11
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 12
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 13
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery58() throws InterruptedException { log.info("Filter test58"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE) .attribute("quantity", Attribute.Type.INT); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"), Compare.Operator.EQUAL, Expression.value(5d)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price")).select("quantity", Expression.variable("quantity"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d, 5}); inputHandler.send(new Object[]{"WSO2", 70f, 60d, 2}); inputHandler.send(new Object[]{"WSO2", 60f, 200d, 4}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); siddhiAppRuntime.shutdown(); }
Example 14
Source File: FilterTestCase2.java From siddhi with Apache License 2.0 | 5 votes |
@Test public void testFilterQuery95() throws InterruptedException { log.info("Filter test95"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE); Query query = new Query(); query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(70f)))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60d}); inputHandler.send(new Object[]{"WSO2", 70f, 40d}); inputHandler.send(new Object[]{"WSO2", 44f, 200d}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); AssertJUnit.assertEquals(1, count.get()); siddhiAppRuntime.shutdown(); }
Example 15
Source File: FilterTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testFilterQuery83() throws InterruptedException { log.info("Filter test83"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG); Query query = new Query(); Filter filter = new Filter(Expression.compare(Expression.variable("volume"), Compare.Operator.GREATER_THAN, Expression.value(45))); String funcString = filter.toString(); AssertJUnit.assertFalse(filter.equals(funcString)); query.from(InputStream.stream("cseEventStream").filter(new Filter(Expression.compare(Expression.variable("volume"), Compare.Operator.GREATER_THAN, Expression.value(45))))); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression .variable("price")).select("volume", Expression.variable("volume"))); query.insertInto("outputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 50f, 60L}); inputHandler.send(new Object[]{"WSO2", 70f, 40L}); inputHandler.send(new Object[]{"WSO2", 44f, 200L}); SiddhiTestHelper.waitForEvents(10, 2, count, 100); siddhiAppRuntime.shutdown(); }
Example 16
Source File: FilterTestCase2.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testFilterQuery113() throws InterruptedException { log.info("Filter test113"); SiddhiManager siddhiManager = new SiddhiManager(); StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE) .attribute("quantity", Attribute.Type.INT).attribute("awards", Attribute.Type.LONG); Query query = new Query(); query.from(InputStream.stream("cseEventStream")); query.annotation(Annotation.annotation("info").element("name", "query1")); query.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("modPrice", Expression.mod(Expression.variable("price"), Expression.value(2))). select("modVolume", Expression.mod(Expression.variable("volume"), Expression.value(2))). select("modQuantity", Expression.mod(Expression.variable("quantity"), Expression.value(2))). select("modAwards", Expression.mod(Expression.variable("awards"), Expression.value(2))) ); query.insertInto("OutputStream"); SiddhiApp siddhiApp = new SiddhiApp("ep1"); siddhiApp.defineStream(cseEventStream); siddhiApp.addQuery(query); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); siddhiAppRuntime.addCallback("query1", new QueryCallback() { @Override public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) { EventPrinter.print(timeStamp, inEvents, removeEvents); AssertJUnit.assertTrue("1.5".equals(inEvents[0].getData()[1].toString())); AssertJUnit.assertTrue("1.0".equals(inEvents[0].getData()[2].toString())); AssertJUnit.assertTrue("1".equals(inEvents[0].getData()[3].toString())); AssertJUnit.assertTrue("1".equals(inEvents[0].getData()[4].toString())); count.addAndGet(inEvents.length); } }); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream"); siddhiAppRuntime.start(); inputHandler.send(new Object[]{"WSO2", 55.5f, 101d, 5, 7L}); SiddhiTestHelper.waitForEvents(10, 1, count, 100); AssertJUnit.assertEquals(1, count.get()); siddhiAppRuntime.shutdown(); }
Example 17
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testQuery3() { 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("bar", Expression.value("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") ) ) ); 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 18
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery39() throws InterruptedException { log.info("Partition test"); SiddhiApp siddhiApp = SiddhiApp.siddhiApp("Test") .defineStream( StreamDefinition.id("streamA") .attribute("symbol", Attribute.Type.STRING) .attribute("price", Attribute.Type.INT) ); Query query = Query.query(); query.from( InputStream.stream("streamA") ); query.select( Selector.selector(). select("symbol", Expression.variable("symbol")). select("price", Expression.variable("price"))); query.insertInto("StockQuote"); Partition partition = Partition.partition() .annotation(Annotation.annotation("info").element("name", "partitionA")) .with("streamA", Expression.variable("symbol")).addQuery(query); siddhiApp.addPartition(partition); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); StreamCallback streamCallback = new StreamCallback() { @Override public void receive(Event[] events) { EventPrinter.print(events); AssertJUnit.assertTrue("IBM".equals(events[0].getData(0)) || "WSO2".equals(events[0].getData(0))); count.addAndGet(events.length); eventArrived = true; } }; siddhiAppRuntime.addCallback("StockQuote", streamCallback); InputHandler inputHandler = siddhiAppRuntime.getInputHandler("streamA"); siddhiAppRuntime.start(); inputHandler.send(new Event(System.currentTimeMillis(), new Object[]{"IBM", 700})); inputHandler.send(new Event(System.currentTimeMillis(), new Object[]{"WSO2", 60})); inputHandler.send(new Event(System.currentTimeMillis(), new Object[]{"WSO2", 60})); Thread.sleep(1000); AssertJUnit.assertEquals(3, count.get()); siddhiAppRuntime.shutdown(); }
Example 19
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 20
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); }