use of org.wso2.siddhi.core.query.QueryRuntime in project siddhi by wso2.
the class SiddhiAppRuntime method debug.
public synchronized SiddhiDebugger debug() {
siddhiDebugger = new SiddhiDebugger(siddhiAppContext);
List<StreamRuntime> streamRuntime = new ArrayList<>();
List<OutputCallback> streamCallbacks = new ArrayList<>();
for (QueryRuntime queryRuntime : queryProcessorMap.values()) {
streamRuntime.add(queryRuntime.getStreamRuntime());
streamCallbacks.add(queryRuntime.getOutputCallback());
}
for (StreamRuntime streamRuntime1 : streamRuntime) {
for (SingleStreamRuntime singleStreamRuntime : streamRuntime1.getSingleStreamRuntimes()) {
singleStreamRuntime.getProcessStreamReceiver().setSiddhiDebugger(siddhiDebugger);
}
}
for (OutputCallback callback : streamCallbacks) {
callback.setSiddhiDebugger(siddhiDebugger);
}
start();
running = true;
return siddhiDebugger;
}
use of org.wso2.siddhi.core.query.QueryRuntime in project siddhi by wso2.
the class SiddhiAppRuntime method addCallback.
public void addCallback(String queryName, QueryCallback callback) {
callback.setContext(siddhiAppContext);
QueryRuntime queryRuntime = queryProcessorMap.get(queryName);
if (queryRuntime == null) {
throw new QueryNotExistException("No query found with name: " + queryName);
}
callback.setQuery(queryRuntime.getQuery());
queryRuntime.addCallback(callback);
}
use of org.wso2.siddhi.core.query.QueryRuntime in project siddhi by wso2.
the class PartitionRuntime method addQuery.
public QueryRuntime addQuery(QueryRuntime metaQueryRuntime) {
Query query = metaQueryRuntime.getQuery();
if (query.getOutputStream() instanceof InsertIntoStream && metaQueryRuntime.getOutputCallback() instanceof InsertIntoStreamCallback) {
InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) metaQueryRuntime.getOutputCallback();
StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
String id = streamDefinition.getId();
if (((InsertIntoStream) query.getOutputStream()).isInnerStream()) {
metaQueryRuntime.setToLocalStream(true);
localStreamDefinitionMap.putIfAbsent(id, streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, localStreamDefinitionMap.get(id));
StreamJunction outputStreamJunction = localStreamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
localStreamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoStreamCallback.init(localStreamJunctionMap.get(id));
} else {
streamDefinitionMap.putIfAbsent(id, streamDefinition);
DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(id));
StreamJunction outputStreamJunction = streamJunctionMap.get(id);
if (outputStreamJunction == null) {
outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), siddhiAppContext);
streamJunctionMap.putIfAbsent(id, outputStreamJunction);
}
insertIntoStreamCallback.init(streamJunctionMap.get(id));
}
}
metaQueryRuntimeMap.put(metaQueryRuntime.getQueryId(), metaQueryRuntime);
return metaQueryRuntime;
}
use of org.wso2.siddhi.core.query.QueryRuntime in project siddhi by wso2.
the class PartitionParser method createMetaEventForPartitioner.
/**
* Create metaEvent to be used by StreamPartitioner with output attributes
*
* @param stateEvent metaStateEvent of the queryRuntime
* @return metaStateEvent
*/
private static MetaStateEvent createMetaEventForPartitioner(MetaComplexEvent stateEvent) {
MetaStateEvent metaStateEvent;
if (stateEvent instanceof MetaStateEvent) {
metaStateEvent = new MetaStateEvent(((MetaStateEvent) stateEvent).getStreamEventCount());
for (MetaStreamEvent metaStreamEvent : ((MetaStateEvent) stateEvent).getMetaStreamEvents()) {
AbstractDefinition definition = metaStreamEvent.getLastInputDefinition();
MetaStreamEvent newMetaStreamEvent = new MetaStreamEvent();
for (Attribute attribute : definition.getAttributeList()) {
newMetaStreamEvent.addOutputData(attribute);
}
newMetaStreamEvent.addInputDefinition(definition);
newMetaStreamEvent.setEventType(metaStreamEvent.getEventType());
metaStateEvent.addEvent(newMetaStreamEvent);
}
} else {
metaStateEvent = new MetaStateEvent(1);
AbstractDefinition definition = ((MetaStreamEvent) stateEvent).getLastInputDefinition();
MetaStreamEvent newMetaStreamEvent = new MetaStreamEvent();
for (Attribute attribute : definition.getAttributeList()) {
newMetaStreamEvent.addOutputData(attribute);
}
newMetaStreamEvent.addInputDefinition(definition);
newMetaStreamEvent.setEventType(((MetaStreamEvent) stateEvent).getEventType());
metaStateEvent.addEvent(newMetaStreamEvent);
}
return metaStateEvent;
}
use of org.wso2.siddhi.core.query.QueryRuntime in project siddhi by wso2.
the class EventTestCase method testQueryParser.
@Test
public void testQueryParser() {
StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
StreamDefinition outStreamDefinition = StreamDefinition.id("outputStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT);
Query query = new Query();
query.annotation(Annotation.annotation("info").element("name", "query1"));
query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.NOT_EQUAL, Expression.value(50))));
query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
query.insertInto("outputStream");
Map<String, AbstractDefinition> tableDefinitionMap = new HashMap<>();
Map<String, AbstractDefinition> windowDefinitionMap = new HashMap<>();
Map<String, AbstractDefinition> aggregationDefinitionMap = new HashMap<>();
Map<String, Table> tableMap = new HashMap<String, Table>();
Map<String, Window> eventWindowMap = new HashMap<String, Window>();
Map<String, AggregationRuntime> aggregationMap = new HashMap<String, AggregationRuntime>();
Map<String, List<Source>> eventSourceMap = new HashMap<String, List<Source>>();
Map<String, List<Sink>> eventSinkMap = new HashMap<String, List<Sink>>();
Map<String, AbstractDefinition> streamDefinitionMap = new HashMap<String, AbstractDefinition>();
LockSynchronizer lockSynchronizer = new LockSynchronizer();
streamDefinitionMap.put("cseEventStream", streamDefinition);
streamDefinitionMap.put("outputStream", outStreamDefinition);
SiddhiContext siddhicontext = new SiddhiContext();
SiddhiAppContext context = new SiddhiAppContext();
context.setSiddhiContext(siddhicontext);
context.setElementIdGenerator(new ElementIdGenerator(context.getName()));
context.setSnapshotService(new SnapshotService(context));
QueryRuntime runtime = QueryParser.parse(query, context, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, aggregationMap, eventWindowMap, lockSynchronizer, "1");
AssertJUnit.assertNotNull(runtime);
AssertJUnit.assertTrue(runtime.getStreamRuntime() instanceof SingleStreamRuntime);
AssertJUnit.assertNotNull(runtime.getSelector());
AssertJUnit.assertTrue(runtime.getMetaComplexEvent() instanceof MetaStreamEvent);
}
Aggregations