Search in sources :

Example 6 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class StoreQueryParser method buildExpectedOutputAttributes.

private static List<Attribute> buildExpectedOutputAttributes(StoreQuery storeQuery, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String queryName, int metaPosition, MatchingMetaInfoHolder metaStreamInfoHolder) {
    MetaStateEvent selectMetaStateEvent = new MetaStateEvent(metaStreamInfoHolder.getMetaStateEvent().getMetaStreamEvents());
    SelectorParser.parse(storeQuery.getSelector(), new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS), siddhiAppContext, selectMetaStateEvent, tableMap, new ArrayList<>(), queryName, metaPosition);
    return selectMetaStateEvent.getOutputStreamDefinition().getAttributeList();
}
Also used : ReturnStream(org.ballerinalang.siddhi.query.api.execution.query.output.stream.ReturnStream) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Example 7 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class StoreQueryParser method generateMatchingMetaInfoHolder.

private static MatchingMetaInfoHolder generateMatchingMetaInfoHolder(MetaStreamEvent metaStreamEvent, AbstractDefinition definition) {
    MetaStateEvent metaStateEvent = new MetaStateEvent(1);
    metaStateEvent.addEvent(metaStreamEvent);
    return new MatchingMetaInfoHolder(metaStateEvent, -1, 0, definition, definition, 0);
}
Also used : MatchingMetaInfoHolder(org.ballerinalang.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Example 8 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class QueryParserHelper method initSingleStreamRuntime.

private static void initSingleStreamRuntime(SingleStreamRuntime singleStreamRuntime, int streamEventChainIndex, MetaComplexEvent metaComplexEvent, StateEventPool stateEventPool, LockWrapper lockWrapper, String queryName) {
    MetaStreamEvent metaStreamEvent;
    if (metaComplexEvent instanceof MetaStateEvent) {
        metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
    } else {
        metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
    }
    StreamEventPool streamEventPool = new StreamEventPool(metaStreamEvent, 5);
    ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
    processStreamReceiver.setMetaStreamEvent(metaStreamEvent);
    processStreamReceiver.setStreamEventPool(streamEventPool);
    processStreamReceiver.setLockWrapper(lockWrapper);
    processStreamReceiver.init();
    Processor processor = singleStreamRuntime.getProcessorChain();
    while (processor != null) {
        if (processor instanceof SchedulingProcessor) {
            ((SchedulingProcessor) processor).getScheduler().setStreamEventPool(streamEventPool);
            ((SchedulingProcessor) processor).getScheduler().init(lockWrapper, queryName);
        }
        if (processor instanceof AbstractStreamProcessor) {
            ((AbstractStreamProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventPool));
            ((AbstractStreamProcessor) processor).constructStreamEventPopulater(metaStreamEvent, streamEventChainIndex);
        }
        if (stateEventPool != null && processor instanceof JoinProcessor) {
            if (((JoinProcessor) processor).getCompiledCondition() instanceof IncrementalAggregateCompileCondition) {
                IncrementalAggregateCompileCondition compiledCondition = (IncrementalAggregateCompileCondition) ((JoinProcessor) processor).getCompiledCondition();
                ComplexEventPopulater complexEventPopulater = StreamEventPopulaterFactory.constructEventPopulator(metaStreamEvent, 0, compiledCondition.getAdditionalAttributes());
                compiledCondition.setComplexEventPopulater(complexEventPopulater);
            }
            ((JoinProcessor) processor).setStateEventPool(stateEventPool);
            ((JoinProcessor) processor).setJoinLock(lockWrapper);
        }
        if (stateEventPool != null && processor instanceof StreamPreStateProcessor) {
            ((StreamPreStateProcessor) processor).setStateEventPool(stateEventPool);
            ((StreamPreStateProcessor) processor).setStreamEventPool(streamEventPool);
            ((StreamPreStateProcessor) processor).setStreamEventCloner(new StreamEventCloner(metaStreamEvent, streamEventPool));
            if (metaComplexEvent instanceof MetaStateEvent) {
                ((StreamPreStateProcessor) processor).setStateEventCloner(new StateEventCloner(((MetaStateEvent) metaComplexEvent), stateEventPool));
            }
        }
        processor = processor.getNextProcessor();
    }
}
Also used : ProcessStreamReceiver(org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver) Processor(org.ballerinalang.siddhi.core.query.processor.Processor) StreamPreStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor) JoinProcessor(org.ballerinalang.siddhi.core.query.input.stream.join.JoinProcessor) AbstractStreamProcessor(org.ballerinalang.siddhi.core.query.processor.stream.AbstractStreamProcessor) SchedulingProcessor(org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor) AbstractStreamProcessor(org.ballerinalang.siddhi.core.query.processor.stream.AbstractStreamProcessor) IncrementalAggregateCompileCondition(org.ballerinalang.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition) ComplexEventPopulater(org.ballerinalang.siddhi.core.event.stream.populater.ComplexEventPopulater) StreamPreStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) SchedulingProcessor(org.ballerinalang.siddhi.core.query.processor.SchedulingProcessor) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.ballerinalang.siddhi.core.event.stream.StreamEventCloner) JoinProcessor(org.ballerinalang.siddhi.core.query.input.stream.join.JoinProcessor) StateEventCloner(org.ballerinalang.siddhi.core.event.state.StateEventCloner) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)

Example 9 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class QueryParserHelper method updateVariablePosition.

public static void updateVariablePosition(MetaComplexEvent metaComplexEvent, List<VariableExpressionExecutor> variableExpressionExecutorList) {
    for (VariableExpressionExecutor variableExpressionExecutor : variableExpressionExecutorList) {
        int streamEventChainIndex = variableExpressionExecutor.getPosition()[STREAM_EVENT_CHAIN_INDEX];
        if (streamEventChainIndex == HAVING_STATE) {
            if (metaComplexEvent instanceof MetaStreamEvent) {
                variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = OUTPUT_DATA_INDEX;
            } else {
                variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = STATE_OUTPUT_DATA_INDEX;
            }
            variableExpressionExecutor.getPosition()[STREAM_EVENT_CHAIN_INDEX] = UNKNOWN_STATE;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaComplexEvent.getOutputStreamDefinition().getAttributeList().indexOf(variableExpressionExecutor.getAttribute());
            continue;
        } else if (metaComplexEvent instanceof MetaStreamEvent && streamEventChainIndex >= 1) {
            // VariableExpressionExecutor on Event table
            continue;
        } else if (metaComplexEvent instanceof MetaStateEvent && streamEventChainIndex >= ((MetaStateEvent) metaComplexEvent).getMetaStreamEvents().length) {
            // for VariableExpressionExecutor on Event table
            continue;
        }
        MetaStreamEvent metaStreamEvent;
        if (metaComplexEvent instanceof MetaStreamEvent) {
            metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
        } else {
            metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
        }
        if (metaStreamEvent.getOutputData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = OUTPUT_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getOutputData().indexOf(variableExpressionExecutor.getAttribute());
        } else if (metaStreamEvent.getOnAfterWindowData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = ON_AFTER_WINDOW_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getOnAfterWindowData().indexOf(variableExpressionExecutor.getAttribute());
        } else if (metaStreamEvent.getBeforeWindowData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = BEFORE_WINDOW_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getBeforeWindowData().indexOf(variableExpressionExecutor.getAttribute());
        }
    }
}
Also used : VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Example 10 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.core.event.state.StateEventPool) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Aggregations

MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)22 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)19 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)10 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)8 AbstractDefinition (org.ballerinalang.siddhi.query.api.definition.AbstractDefinition)7 MatchingMetaInfoHolder (org.ballerinalang.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)6 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)5 ArrayList (java.util.ArrayList)4 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)4 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)4 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)4 Expression (org.ballerinalang.siddhi.query.api.expression.Expression)4 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)3 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)3 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)3 ProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver)3 StateEventCloner (org.ballerinalang.siddhi.core.event.state.StateEventCloner)2 StateEventPool (org.ballerinalang.siddhi.core.event.state.StateEventPool)2 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)2 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)2