Java Code Examples for io.siddhi.query.api.SiddhiApp#addPartition()
The following examples show how to use
io.siddhi.query.api.SiddhiApp#addPartition() .
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: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 5 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public SiddhiApp visitSiddhi_app(@NotNull SiddhiQLParser.Siddhi_appContext ctx) { SiddhiApp siddhiApp = SiddhiApp.siddhiApp(); for (SiddhiQLParser.App_annotationContext annotationContext : ctx.app_annotation()) { siddhiApp.annotation((Annotation) visit(annotationContext)); } for (SiddhiQLParser.Definition_streamContext streamContext : ctx.definition_stream()) { siddhiApp.defineStream((StreamDefinition) visit(streamContext)); } for (SiddhiQLParser.Definition_tableContext tableContext : ctx.definition_table()) { siddhiApp.defineTable((TableDefinition) visit(tableContext)); } for (SiddhiQLParser.Definition_functionContext functionContext : ctx.definition_function()) { siddhiApp.defineFunction((FunctionDefinition) visit(functionContext)); } for (SiddhiQLParser.Definition_windowContext windowContext : ctx.definition_window()) { siddhiApp.defineWindow((WindowDefinition) visit(windowContext)); } for (SiddhiQLParser.Definition_aggregationContext aggregationContext : ctx.definition_aggregation()) { siddhiApp.defineAggregation((AggregationDefinition) visit(aggregationContext)); } for (SiddhiQLParser.Execution_elementContext executionElementContext : ctx.execution_element()) { ExecutionElement executionElement = (ExecutionElement) visit(executionElementContext); if (executionElement instanceof Partition) { siddhiApp.addPartition((Partition) executionElement); } else if (executionElement instanceof Query) { siddhiApp.addQuery((Query) executionElement); } else { throw newSiddhiParserException(ctx); } } for (SiddhiQLParser.Definition_triggerContext triggerContext : ctx.definition_trigger()) { siddhiApp.defineTrigger((TriggerDefinition) visit(triggerContext)); } populateQueryContext(siddhiApp, ctx); return siddhiApp; }
Example 2
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()); }
Example 3
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 4
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 5
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test(expectedExceptions = SiddhiAppCreationException.class) public void testPartitionQuery42() 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.annotation(Annotation.annotation("info").element("name", "query1")); 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(); partition.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(0, count.get()); siddhiAppRuntime.shutdown(); }
Example 6
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
public void testPartitionQuery43() throws InterruptedException { log.info("Partition test43"); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiApp siddhiApp = new SiddhiApp("plan43"); 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", OutputStream.OutputEventType.CURRENT_EVENTS); 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", OutputStream.OutputEventType.CURRENT_EVENTS); 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()); }
Example 7
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 4 votes |
@Test public void testPartitionQuery44() throws InterruptedException { log.info("Partition test44"); SiddhiManager siddhiManager = new SiddhiManager(); SiddhiApp siddhiApp = new SiddhiApp("plan44"); 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("e1", "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("e2", "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()); }
Example 8
Source File: PartitionTestCase1.java From siddhi with Apache License 2.0 | 3 votes |
@Test(expectedExceptions = SiddhiAppValidationException.class) public void testPartitionQuery45() throws InterruptedException { log.info("Partition test45"); SiddhiApp siddhiApp = new SiddhiApp("plan45"); 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 = null; siddhiApp.addPartition(partition); }