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());
}
}
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);
}
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();
}
}
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();
}
}
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();
}
}
Aggregations