use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class JoinTestCase method joinTest20.
@Test
public void joinTest20() throws InterruptedException {
log.info("Join test20");
SiddhiManager siddhiManager = new SiddhiManager();
String streams = "" + "define stream dataIn (id int, data string); " + "define stream countIn (id int); " + "define stream deleteIn (id int); " + "define table dataTable (id int, data string); ";
String query = "" + "from dataIn\n" + "insert into dataTable;\n" + "" + "from deleteIn \n" + "delete dataTable\n" + " on dataTable.id == id;\n" + "" + "@info(name = 'query1') " + "from countIn as c left outer join dataTable as d\n" + "on d.data == 'abc'\n" + "select count() as count\n" + "insert into countOut; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
try {
InputHandler dataIn = siddhiAppRuntime.getInputHandler("dataIn");
InputHandler countIn = siddhiAppRuntime.getInputHandler("countIn");
InputHandler deleteIn = siddhiAppRuntime.getInputHandler("deleteIn");
siddhiAppRuntime.addCallback("query1", new QueryCallback() {
@Override
public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
inEventCount.incrementAndGet();
if (inEventCount.get() == 1) {
EventPrinter.print(timestamp, inEvents, removeEvents);
AssertJUnit.assertTrue((Long) inEvents[0].getData(0) == 3L);
} else {
EventPrinter.print(timestamp, inEvents, removeEvents);
AssertJUnit.assertTrue((Long) inEvents[0].getData(0) == 2L);
}
}
});
siddhiAppRuntime.start();
Thread.sleep(100);
dataIn.send(new Object[] { 1, "abc" });
dataIn.send(new Object[] { 2, "abc" });
dataIn.send(new Object[] { 3, "abc" });
countIn.send(new Object[] { 1 });
deleteIn.send(new Object[] { 1 });
countIn.send(new Object[] { 1 });
} finally {
siddhiAppRuntime.shutdown();
}
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class JoinTestCase method joinTest16.
@Test
public void joinTest16() throws InterruptedException {
log.info("Join test16");
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 order.custid\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();
}
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class SimpleQueryValidatorTestCase method testQueryWithEveryTable.
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testQueryWithEveryTable() throws InterruptedException {
SiddhiManager siddhiManager = new SiddhiManager();
String tables = "define table TestTable(symbol string, volume float);\n" + "" + "from every TestTable " + "select * " + "insert into OutputStream; ";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(tables);
siddhiAppRuntime.shutdown();
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class Window method init.
/**
* Initialize the WindowEvent table by creating {@link WindowProcessor} to handle the events.
*
* @param tableMap map of {@link Table}s
* @param eventWindowMap map of EventWindows
* @param queryName name of the query window belongs to.
*/
public void init(Map<String, Table> tableMap, Map<String, Window> eventWindowMap, String queryName) {
if (this.windowProcessor != null) {
return;
}
// Create and initialize MetaStreamEvent
MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
metaStreamEvent.addInputDefinition(windowDefinition);
metaStreamEvent.setEventType(MetaStreamEvent.EventType.WINDOW);
metaStreamEvent.initializeAfterWindowData();
for (Attribute attribute : windowDefinition.getAttributeList()) {
metaStreamEvent.addOutputData(attribute);
}
this.streamEventPool = new StreamEventPool(metaStreamEvent, 5);
StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, this.streamEventPool);
OutputStream.OutputEventType outputEventType = windowDefinition.getOutputEventType();
boolean outputExpectsExpiredEvents = outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS;
WindowProcessor internalWindowProcessor = (WindowProcessor) SingleInputStreamParser.generateProcessor(windowDefinition.getWindow(), metaStreamEvent, new ArrayList<VariableExpressionExecutor>(), this.siddhiAppContext, tableMap, false, outputExpectsExpiredEvents, queryName);
internalWindowProcessor.setStreamEventCloner(streamEventCloner);
internalWindowProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
EntryValveProcessor entryValveProcessor = null;
if (internalWindowProcessor instanceof SchedulingProcessor) {
entryValveProcessor = new EntryValveProcessor(this.siddhiAppContext);
Scheduler scheduler = SchedulerParser.parse(this.siddhiAppContext.getScheduledExecutorService(), entryValveProcessor, this.siddhiAppContext);
scheduler.init(this.lockWrapper, queryName);
scheduler.setStreamEventPool(streamEventPool);
((SchedulingProcessor) internalWindowProcessor).setScheduler(scheduler);
}
if (entryValveProcessor != null) {
entryValveProcessor.setToLast(internalWindowProcessor);
this.windowProcessor = entryValveProcessor;
} else {
this.windowProcessor = internalWindowProcessor;
}
// StreamPublishProcessor must be the last in chain so that it can publish the events to StreamJunction
this.windowProcessor.setToLast(new StreamPublishProcessor(outputEventType));
this.internalWindowProcessor = internalWindowProcessor;
}
use of org.wso2.siddhi.core.table.Table in project siddhi by wso2.
the class DefineTableTestCase method testQuery10.
@Test(expectedExceptions = DuplicateDefinitionException.class)
public void testQuery10() throws InterruptedException {
log.info("testTableDefinition10 - OUT 0");
SiddhiManager siddhiManager = new SiddhiManager();
String siddhiApp = "" + "define stream StockStream(symbol string, price int, volume float); " + "define table OutputStream (symbol string, price float, volume long);" + "" + "from StockStream " + "select symbol, price " + "insert into OutputStream;";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
siddhiAppRuntime.shutdown();
}
Aggregations