Search in sources :

Example 16 with MetaStreamEvent

use of org.wso2.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.

the class StoreQueryParser method constructStoreQueryRuntime.

private static StoreQueryRuntime constructStoreQueryRuntime(Window window, StoreQuery storeQuery, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String queryName, int metaPosition, Expression onCondition, MetaStreamEvent metaStreamEvent, List<VariableExpressionExecutor> variableExpressionExecutors) {
    metaStreamEvent.setEventType(EventType.WINDOW);
    initMetaStreamEvent(metaStreamEvent, window.getWindowDefinition());
    MatchingMetaInfoHolder metaStreamInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, window.getWindowDefinition());
    CompiledCondition compiledCondition = window.compileCondition(onCondition, generateMatchingMetaInfoHolder(metaStreamEvent, window.getWindowDefinition()), siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
    FindStoreQueryRuntime findStoreQueryRuntime = new FindStoreQueryRuntime(window, compiledCondition, queryName, metaStreamEvent);
    populateFindStoreQueryRuntime(findStoreQueryRuntime, metaStreamInfoHolder, storeQuery.getSelector(), variableExpressionExecutors, siddhiAppContext, tableMap, queryName, metaPosition);
    return findStoreQueryRuntime;
}
Also used : CompiledCondition(org.wso2.siddhi.core.util.collection.operator.CompiledCondition) MatchingMetaInfoHolder(org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) FindStoreQueryRuntime(org.wso2.siddhi.core.query.FindStoreQueryRuntime)

Example 17 with MetaStreamEvent

use of org.wso2.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.

the class StoreQueryParser method constructStoreQueryRuntime.

private static StoreQueryRuntime constructStoreQueryRuntime(AggregationRuntime aggregation, StoreQuery storeQuery, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String queryName, Within within, Expression per, Expression onCondition, MetaStreamEvent metaStreamEvent, List<VariableExpressionExecutor> variableExpressionExecutors) {
    int metaPosition;
    metaStreamEvent.setEventType(EventType.AGGREGATE);
    initMetaStreamEvent(metaStreamEvent, aggregation.getAggregationDefinition());
    MatchingMetaInfoHolder metaStreamInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, aggregation.getAggregationDefinition());
    CompiledCondition compiledCondition = aggregation.compileExpression(onCondition, within, per, metaStreamInfoHolder, variableExpressionExecutors, tableMap, queryName, siddhiAppContext);
    metaStreamInfoHolder = ((IncrementalAggregateCompileCondition) compiledCondition).getAlteredMatchingMetaInfoHolder();
    FindStoreQueryRuntime findStoreQueryRuntime = new FindStoreQueryRuntime(aggregation, compiledCondition, queryName, metaStreamEvent);
    metaPosition = 1;
    populateFindStoreQueryRuntime(findStoreQueryRuntime, metaStreamInfoHolder, storeQuery.getSelector(), variableExpressionExecutors, siddhiAppContext, tableMap, queryName, metaPosition);
    ComplexEventPopulater complexEventPopulater = StreamEventPopulaterFactory.constructEventPopulator(metaStreamInfoHolder.getMetaStateEvent().getMetaStreamEvent(0), 0, ((IncrementalAggregateCompileCondition) compiledCondition).getAdditionalAttributes());
    ((IncrementalAggregateCompileCondition) compiledCondition).setComplexEventPopulater(complexEventPopulater);
    return findStoreQueryRuntime;
}
Also used : CompiledCondition(org.wso2.siddhi.core.util.collection.operator.CompiledCondition) MatchingMetaInfoHolder(org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) IncrementalAggregateCompileCondition(org.wso2.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition) FindStoreQueryRuntime(org.wso2.siddhi.core.query.FindStoreQueryRuntime) ComplexEventPopulater(org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater)

Example 18 with MetaStreamEvent

use of org.wso2.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.

the class QueryParserHelper method initStreamRuntime.

public static void initStreamRuntime(StreamRuntime runtime, MetaComplexEvent metaComplexEvent, LockWrapper lockWrapper, String queryName) {
    if (runtime instanceof SingleStreamRuntime) {
        initSingleStreamRuntime((SingleStreamRuntime) runtime, 0, metaComplexEvent, null, lockWrapper, queryName);
    } else {
        MetaStateEvent metaStateEvent = (MetaStateEvent) metaComplexEvent;
        StateEventPool stateEventPool = new StateEventPool(metaStateEvent, 5);
        MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
        for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
            initSingleStreamRuntime(runtime.getSingleStreamRuntimes().get(i), i, metaStateEvent, stateEventPool, lockWrapper, queryName);
        }
    }
}
Also used : StateEventPool(org.wso2.siddhi.core.event.state.StateEventPool) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent)

Example 19 with MetaStreamEvent

use of org.wso2.siddhi.core.event.stream.MetaStreamEvent 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;
}
Also used : Attribute(org.wso2.siddhi.query.api.definition.Attribute) Scheduler(org.wso2.siddhi.core.util.Scheduler) OutputStream(org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) SchedulingProcessor(org.wso2.siddhi.core.query.processor.SchedulingProcessor) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.wso2.siddhi.core.event.stream.StreamEventCloner) EntryValveProcessor(org.wso2.siddhi.core.query.input.stream.single.EntryValveProcessor) WindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 20 with MetaStreamEvent

use of org.wso2.siddhi.core.event.stream.MetaStreamEvent 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);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) HashMap(java.util.HashMap) ElementIdGenerator(org.wso2.siddhi.core.util.ElementIdGenerator) Source(org.wso2.siddhi.core.stream.input.source.Source) SiddhiContext(org.wso2.siddhi.core.config.SiddhiContext) Sink(org.wso2.siddhi.core.stream.output.sink.Sink) QueryRuntime(org.wso2.siddhi.core.query.QueryRuntime) LockSynchronizer(org.wso2.siddhi.core.util.lock.LockSynchronizer) List(java.util.List) AggregationRuntime(org.wso2.siddhi.core.aggregation.AggregationRuntime) Window(org.wso2.siddhi.core.window.Window) SnapshotService(org.wso2.siddhi.core.util.snapshot.SnapshotService) Table(org.wso2.siddhi.core.table.Table) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) AbstractDefinition(org.wso2.siddhi.query.api.definition.AbstractDefinition) SiddhiAppContext(org.wso2.siddhi.core.config.SiddhiAppContext) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Aggregations

MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)33 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)23 Attribute (org.wso2.siddhi.query.api.definition.Attribute)23 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)18 ArrayList (java.util.ArrayList)13 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)12 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)11 MatchingMetaInfoHolder (org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)11 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)11 Expression (org.wso2.siddhi.query.api.expression.Expression)11 Variable (org.wso2.siddhi.query.api.expression.Variable)10 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)9 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)8 Table (org.wso2.siddhi.core.table.Table)7 CompiledCondition (org.wso2.siddhi.core.util.collection.operator.CompiledCondition)7 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)6 Test (org.testng.annotations.Test)5 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)5 Window (org.wso2.siddhi.core.window.Window)5 HashMap (java.util.HashMap)4