Search in sources :

Example 21 with MetaStateEvent

use of org.wso2.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

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.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent)

Example 22 with MetaStateEvent

use of org.wso2.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

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.wso2.siddhi.core.executor.VariableExpressionExecutor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent)

Example 23 with MetaStateEvent

use of org.wso2.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

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.wso2.siddhi.core.query.input.ProcessStreamReceiver) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) Processor(org.wso2.siddhi.core.query.processor.Processor) JoinProcessor(org.wso2.siddhi.core.query.input.stream.join.JoinProcessor) AbstractStreamProcessor(org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor) SchedulingProcessor(org.wso2.siddhi.core.query.processor.SchedulingProcessor) AbstractStreamProcessor(org.wso2.siddhi.core.query.processor.stream.AbstractStreamProcessor) IncrementalAggregateCompileCondition(org.wso2.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition) ComplexEventPopulater(org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater) StreamPreStateProcessor(org.wso2.siddhi.core.query.input.stream.state.StreamPreStateProcessor) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) SchedulingProcessor(org.wso2.siddhi.core.query.processor.SchedulingProcessor) StreamEventPool(org.wso2.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.wso2.siddhi.core.event.stream.StreamEventCloner) JoinProcessor(org.wso2.siddhi.core.query.input.stream.join.JoinProcessor) StateEventCloner(org.wso2.siddhi.core.event.state.StateEventCloner) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 24 with MetaStateEvent

use of org.wso2.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

the class PartitionRuntime method addPartitionReceiver.

public void addPartitionReceiver(QueryRuntime queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
    Query query = queryRuntime.getQuery();
    List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, siddhiAppContext, null).getPartitionExecutorLists();
    if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
        SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
        addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
    } else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
        SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream();
        addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
        SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream();
        addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
    } else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
        StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
        addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
    }
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinStreamRuntime(org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) StateElement(org.wso2.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) LogicalStateElement(org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) ArrayList(java.util.ArrayList) List(java.util.List) StateInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream) StateStreamRuntime(org.wso2.siddhi.core.query.input.stream.state.StateStreamRuntime)

Example 25 with MetaStateEvent

use of org.wso2.siddhi.core.event.state.MetaStateEvent in project siddhi by wso2.

the class StreamPartitioner method createJoinInputStreamExecutors.

private void createJoinInputStreamExecutors(JoinInputStream inputStream, Partition partition, MetaStateEvent metaEvent, List<VariableExpressionExecutor> executors, SiddhiAppContext siddhiAppContext, String queryName) {
    createExecutors(inputStream.getLeftInputStream(), partition, metaEvent.getMetaStreamEvent(0), executors, siddhiAppContext, queryName);
    int size = executors.size();
    for (VariableExpressionExecutor variableExpressionExecutor : executors) {
        variableExpressionExecutor.getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 0;
    }
    createExecutors(inputStream.getRightInputStream(), partition, metaEvent.getMetaStreamEvent(1), executors, siddhiAppContext, queryName);
    for (int i = size; i < executors.size(); i++) {
        executors.get(i).getPosition()[SiddhiConstants.STREAM_EVENT_CHAIN_INDEX] = 1;
    }
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor)

Aggregations

MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)22 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)19 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)11 Attribute (org.wso2.siddhi.query.api.definition.Attribute)9 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)8 ArrayList (java.util.ArrayList)7 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)7 ProcessStreamReceiver (org.wso2.siddhi.core.query.input.ProcessStreamReceiver)5 MatchingMetaInfoHolder (org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)5 Variable (org.wso2.siddhi.query.api.expression.Variable)5 OperationNotSupportedException (org.wso2.siddhi.core.exception.OperationNotSupportedException)4 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)4 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)3 JoinStreamRuntime (org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime)3 WindowProcessor (org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor)3 JoinInputStream (org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream)3 SingleInputStream (org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream)3 Expression (org.wso2.siddhi.query.api.expression.Expression)3 StateEventCloner (org.wso2.siddhi.core.event.state.StateEventCloner)2 StreamEventCloner (org.wso2.siddhi.core.event.stream.StreamEventCloner)2