Search in sources :

Example 21 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class DefinitionParserHelper method validateDefinition.

public static void validateDefinition(AbstractDefinition definition, ConcurrentMap<String, AbstractDefinition> streamDefinitionMap, ConcurrentMap<String, AbstractDefinition> tableDefinitionMap, ConcurrentMap<String, AbstractDefinition> windowDefinitionMap, ConcurrentMap<String, AbstractDefinition> aggregationDefinitionMap) {
    AbstractDefinition existingTableDefinition = tableDefinitionMap.get(definition.getId());
    if (existingTableDefinition != null && (!existingTableDefinition.equals(definition) || definition instanceof StreamDefinition)) {
        throw new DuplicateDefinitionException("Table Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingTableDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingStreamDefinition = streamDefinitionMap.get(definition.getId());
    if (existingStreamDefinition != null && (!existingStreamDefinition.equals(definition) || definition instanceof TableDefinition)) {
        throw new DuplicateDefinitionException("Stream Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingStreamDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId());
    if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) {
        throw new DuplicateDefinitionException("Window Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId());
    if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) {
        throw new DuplicateDefinitionException("Aggregation Definition with same Aggregation Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(org.wso2.siddhi.query.api.exception.DuplicateDefinitionException) AggregationDefinition(org.wso2.siddhi.query.api.definition.AggregationDefinition) AbstractDefinition(org.wso2.siddhi.query.api.definition.AbstractDefinition) TableDefinition(org.wso2.siddhi.query.api.definition.TableDefinition) WindowDefinition(org.wso2.siddhi.query.api.definition.WindowDefinition)

Example 22 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class TablePartitionTestCase method testPartitionQuery2.

@Test
public void testPartitionQuery2() throws InterruptedException {
    log.info("Table Partition test 2");
    SiddhiManager siddhiManager = new SiddhiManager();
    String siddhiApp = "" + "@app:name('PartitionTest') " + "define stream streamA (symbol string, price int);" + "define stream streamB (symbol string);" + "define table tableA (symbol string, price int);" + "partition with (symbol of streamA, symbol of streamB) " + "begin " + "   @info(name = 'query1') " + "   from streamA " + "   select symbol, price " + "   insert into tableA;  " + "" + "end ;" + "" + "@info(name = 'query2') " + "from streamB[(symbol==tableA.symbol) in tableA] " + "select symbol " + "insert into outputStream;  " + "";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(Event[] events) {
            EventPrinter.print(events);
            for (Event event : events) {
                count.incrementAndGet();
            }
            eventArrived = true;
        }
    });
    InputHandler streamAInputHandler = siddhiAppRuntime.getInputHandler("streamA");
    InputHandler streamBInputHandler = siddhiAppRuntime.getInputHandler("streamB");
    siddhiAppRuntime.start();
    streamAInputHandler.send(new Object[] { "IBM", 700 });
    streamAInputHandler.send(new Object[] { "WSO2", 60 });
    streamAInputHandler.send(new Object[] { "WSO2", 60 });
    streamBInputHandler.send(new Object[] { "WSO2" });
    streamBInputHandler.send(new Object[] { "FB" });
    streamBInputHandler.send(new Object[] { "IBM" });
    SiddhiTestHelper.waitForEvents(100, 2, count, 60000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertEquals(2, count.get());
    AssertJUnit.assertEquals(true, eventArrived);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Example 23 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class JoinTestCase method joinTest14.

@Test
public void joinTest14() throws InterruptedException {
    log.info("Join test14");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
    String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "on order.custid == dow_items.custid \n" + "select  dow_items.item\n" + "having order.items == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
        InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                eventArrived = true;
            }
        });
        siddhiAppRuntime.start();
        Thread.sleep(100);
        itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
        orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
        Thread.sleep(100);
        AssertJUnit.assertEquals("Event Arrived", true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 24 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class JoinTestCase method joinTest17.

@Test
public void joinTest17() throws InterruptedException {
    log.info("Join test17");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
    String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "select  dow_items.custid\n" + "having order.items == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
        InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                eventArrived = true;
            }
        });
        siddhiAppRuntime.start();
        Thread.sleep(100);
        itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
        orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
        Thread.sleep(100);
        AssertJUnit.assertEquals("Event Arrived", true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 25 with Table

use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.

the class JoinTestCase method joinTest15.

@Test
public void joinTest15() throws InterruptedException {
    log.info("Join test15");
    SiddhiManager siddhiManager = new SiddhiManager();
    String streams = "" + "define stream order (billnum string, custid string, items string, dow string, timestamp long); " + "define table dow_items (custid string, dow string, item string) ; " + "define stream dow_items_stream (custid string, dow string, item string); ";
    String query = "" + "@info(name = 'query1') " + "from order join dow_items \n" + "on order.custid == dow_items.custid \n" + "select  dow_items.item\n" + "having dow_items.item == \"item1\" \n" + "insert into recommendationStream ;" + "@info(name = 'query2') " + "from dow_items_stream " + "insert into dow_items ;" + "" + "";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    try {
        InputHandler orderStream = siddhiAppRuntime.getInputHandler("order");
        InputHandler itemsStream = siddhiAppRuntime.getInputHandler("dow_items_stream");
        siddhiAppRuntime.addCallback("query1", new QueryCallback() {

            @Override
            public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
                EventPrinter.print(timestamp, inEvents, removeEvents);
                eventArrived = true;
            }
        });
        siddhiAppRuntime.start();
        Thread.sleep(100);
        itemsStream.send(new Object[] { "cust1", "bill1", "item1" });
        orderStream.send(new Object[] { "bill1", "cust1", "item1", "dow1", 12323232L });
        Thread.sleep(100);
        AssertJUnit.assertEquals("Event Arrived", true, eventArrived);
    } finally {
        siddhiAppRuntime.shutdown();
    }
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)183 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)176 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)176 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)140 Event (org.wso2.siddhi.core.event.Event)119 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)102 ArrayList (java.util.ArrayList)47 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)23 HashMap (java.util.HashMap)22 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)20 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)19 Attribute (org.wso2.siddhi.query.api.definition.Attribute)19 Table (org.wso2.siddhi.core.table.Table)11 Expression (org.wso2.siddhi.query.api.expression.Expression)11 Variable (org.wso2.siddhi.query.api.expression.Variable)11 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)10 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)10 TableDefinition (org.wso2.siddhi.query.api.definition.TableDefinition)9 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)8 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)8