Search in sources :

Example 1 with StateEventFactory

use of io.siddhi.core.event.state.StateEventFactory in project siddhi by wso2.

the class WrappedSnapshotOutputRateLimiter method init.

public void init(int outPutAttributeSize, List<AttributeProcessor> attributeProcessorList, MetaComplexEvent metaComplexEvent) {
    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
        if (attributeProcessor.getExpressionExecutor() instanceof AttributeAggregatorExecutor<?>) {
            aggregateAttributePositionList.add(attributeProcessor.getOutputPosition());
        }
    }
    if (windowed) {
        if (groupBy) {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationGroupByWindowedPerSnapshotOutputRateLimiter(value, aggregateAttributePositionList, this, groupBy, siddhiQueryContext);
            } else {
                // No aggregation
                // GroupBy is same as Non GroupBy
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            }
        } else {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationWindowedPerSnapshotOutputRateLimiter(value, aggregateAttributePositionList, this, groupBy, siddhiQueryContext);
            } else {
                // No aggregation
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
            }
        }
    } else {
        if (groupBy) {
            outputRateLimiter = new GroupByPerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
        } else {
            outputRateLimiter = new PerSnapshotOutputRateLimiter(value, this, groupBy, siddhiQueryContext);
        }
    }
    if (metaComplexEvent instanceof MetaStateEvent) {
        StateEventFactory stateEventFactory = new StateEventFactory((MetaStateEvent) metaComplexEvent);
        outputRateLimiter.setStateEventCloner(new StateEventCloner((MetaStateEvent) metaComplexEvent, stateEventFactory));
    } else {
        StreamEventFactory streamEventFactory = new StreamEventFactory((MetaStreamEvent) metaComplexEvent);
        outputRateLimiter.setStreamEventCloner(new StreamEventCloner((MetaStreamEvent) metaComplexEvent, streamEventFactory));
    }
}
Also used : StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) AttributeProcessor(io.siddhi.core.query.selector.attribute.processor.AttributeProcessor) StateEventCloner(io.siddhi.core.event.state.StateEventCloner) AttributeAggregatorExecutor(io.siddhi.core.query.selector.attribute.aggregator.AttributeAggregatorExecutor) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 2 with StateEventFactory

use of io.siddhi.core.event.state.StateEventFactory in project siddhi by wso2.

the class OnDemandQueryParser method populateFindOnDemandQueryRuntime.

private static void populateFindOnDemandQueryRuntime(FindOnDemandQueryRuntime findOnDemandQueryRuntime, MatchingMetaInfoHolder metaStreamInfoHolder, Selector selector, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, Map<String, Window> windowMap, int metaPosition, boolean groupBy, LockWrapper lockWrapper, SiddhiQueryContext siddhiQueryContext) {
    ReturnStream returnStream = new ReturnStream(OutputStream.OutputEventType.CURRENT_EVENTS);
    QuerySelector querySelector = SelectorParser.parse(selector, returnStream, metaStreamInfoHolder.getMetaStateEvent(), tableMap, variableExpressionExecutors, metaPosition, ProcessingMode.BATCH, false, siddhiQueryContext);
    PassThroughOutputRateLimiter rateLimiter = new PassThroughOutputRateLimiter(siddhiQueryContext.getName());
    rateLimiter.init(lockWrapper, groupBy, siddhiQueryContext);
    OutputCallback outputCallback = OutputParser.constructOutputCallback(returnStream, metaStreamInfoHolder.getMetaStateEvent().getOutputStreamDefinition(), tableMap, windowMap, true, siddhiQueryContext);
    rateLimiter.setOutputCallback(outputCallback);
    querySelector.setNextProcessor(rateLimiter);
    QueryParserHelper.reduceMetaComplexEvent(metaStreamInfoHolder.getMetaStateEvent());
    QueryParserHelper.updateVariablePosition(metaStreamInfoHolder.getMetaStateEvent(), variableExpressionExecutors);
    querySelector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(metaStreamInfoHolder.getMetaStateEvent()));
    findOnDemandQueryRuntime.setStateEventFactory(new StateEventFactory(metaStreamInfoHolder.getMetaStateEvent()));
    findOnDemandQueryRuntime.setSelector(querySelector);
    findOnDemandQueryRuntime.setOutputAttributes(metaStreamInfoHolder.getMetaStateEvent().getOutputStreamDefinition().getAttributeList());
}
Also used : StateEventFactory(io.siddhi.core.event.state.StateEventFactory) QuerySelector(io.siddhi.core.query.selector.QuerySelector) ReturnStream(io.siddhi.query.api.execution.query.output.stream.ReturnStream) PassThroughOutputRateLimiter(io.siddhi.core.query.output.ratelimit.PassThroughOutputRateLimiter) OutputCallback(io.siddhi.core.query.output.callback.OutputCallback)

Example 3 with StateEventFactory

use of io.siddhi.core.event.state.StateEventFactory in project siddhi by wso2.

the class OnDemandQueryParser method constructRegularOnDemandQueryRuntime.

private static OnDemandQueryRuntime constructRegularOnDemandQueryRuntime(Table table, OnDemandQuery onDemandQuery, Map<String, Table> tableMap, Map<String, Window> windowMap, int metaPosition, Expression onCondition, MetaStreamEvent metaStreamEvent, List<VariableExpressionExecutor> variableExpressionExecutors, LockWrapper lockWrapper, SiddhiQueryContext siddhiQueryContext) {
    MatchingMetaInfoHolder matchingMetaInfoHolder;
    AbstractDefinition inputDefinition;
    QuerySelector querySelector;
    switch(onDemandQuery.getType()) {
        case FIND:
            initMetaStreamEvent(metaStreamEvent, table.getTableDefinition());
            matchingMetaInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, table.getTableDefinition());
            CompiledCondition compiledCondition = table.compileCondition(onCondition, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiQueryContext);
            FindOnDemandQueryRuntime findOnDemandQueryRuntime = new FindOnDemandQueryRuntime(table, compiledCondition, siddhiQueryContext.getName(), metaStreamEvent);
            populateFindOnDemandQueryRuntime(findOnDemandQueryRuntime, matchingMetaInfoHolder, onDemandQuery.getSelector(), variableExpressionExecutors, tableMap, windowMap, metaPosition, !onDemandQuery.getSelector().getGroupByList().isEmpty(), lockWrapper, siddhiQueryContext);
            return findOnDemandQueryRuntime;
        case INSERT:
            initMetaStreamEvent(metaStreamEvent, getInputDefinition(onDemandQuery, table));
            matchingMetaInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, table.getTableDefinition());
            querySelector = getQuerySelector(matchingMetaInfoHolder, variableExpressionExecutors, tableMap, windowMap, metaPosition, onDemandQuery, lockWrapper, siddhiQueryContext);
            InsertOnDemandQueryRuntime insertOnDemandQueryRuntime = new InsertOnDemandQueryRuntime(siddhiQueryContext.getName(), metaStreamEvent);
            insertOnDemandQueryRuntime.setStateEventFactory(new StateEventFactory(matchingMetaInfoHolder.getMetaStateEvent()));
            insertOnDemandQueryRuntime.setSelector(querySelector);
            insertOnDemandQueryRuntime.setOutputAttributes(matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition().getAttributeList());
            return insertOnDemandQueryRuntime;
        case DELETE:
            inputDefinition = getInputDefinition(onDemandQuery, table);
            initMetaStreamEvent(metaStreamEvent, inputDefinition);
            matchingMetaInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, inputDefinition, table.getTableDefinition());
            querySelector = getQuerySelector(matchingMetaInfoHolder, variableExpressionExecutors, tableMap, windowMap, metaPosition, onDemandQuery, lockWrapper, siddhiQueryContext);
            DeleteOnDemandQueryRuntime deleteOnDemandQueryRuntime = new DeleteOnDemandQueryRuntime(siddhiQueryContext.getName(), metaStreamEvent);
            deleteOnDemandQueryRuntime.setStateEventFactory(new StateEventFactory(matchingMetaInfoHolder.getMetaStateEvent()));
            deleteOnDemandQueryRuntime.setSelector(querySelector);
            deleteOnDemandQueryRuntime.setOutputAttributes(matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition().getAttributeList());
            return deleteOnDemandQueryRuntime;
        case UPDATE:
            inputDefinition = getInputDefinition(onDemandQuery, table);
            initMetaStreamEvent(metaStreamEvent, inputDefinition);
            matchingMetaInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, inputDefinition, table.getTableDefinition());
            querySelector = getQuerySelector(matchingMetaInfoHolder, variableExpressionExecutors, tableMap, windowMap, metaPosition, onDemandQuery, lockWrapper, siddhiQueryContext);
            UpdateOnDemandQueryRuntime updateOnDemandQueryRuntime = new UpdateOnDemandQueryRuntime(siddhiQueryContext.getName(), metaStreamEvent);
            updateOnDemandQueryRuntime.setStateEventFactory(new StateEventFactory(matchingMetaInfoHolder.getMetaStateEvent()));
            updateOnDemandQueryRuntime.setSelector(querySelector);
            updateOnDemandQueryRuntime.setOutputAttributes(matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition().getAttributeList());
            return updateOnDemandQueryRuntime;
        case UPDATE_OR_INSERT:
            inputDefinition = getInputDefinition(onDemandQuery, table);
            initMetaStreamEvent(metaStreamEvent, inputDefinition);
            matchingMetaInfoHolder = generateMatchingMetaInfoHolder(metaStreamEvent, inputDefinition, table.getTableDefinition());
            querySelector = getQuerySelector(matchingMetaInfoHolder, variableExpressionExecutors, tableMap, windowMap, metaPosition, onDemandQuery, lockWrapper, siddhiQueryContext);
            UpdateOrInsertOnDemandQueryRuntime updateOrInsertIntoOnDemandQueryRuntime = new UpdateOrInsertOnDemandQueryRuntime(siddhiQueryContext.getName(), metaStreamEvent);
            updateOrInsertIntoOnDemandQueryRuntime.setStateEventFactory(new StateEventFactory(matchingMetaInfoHolder.getMetaStateEvent()));
            updateOrInsertIntoOnDemandQueryRuntime.setSelector(querySelector);
            updateOrInsertIntoOnDemandQueryRuntime.setOutputAttributes(matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition().getAttributeList());
            return updateOrInsertIntoOnDemandQueryRuntime;
        default:
            return null;
    }
}
Also used : CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition) FindOnDemandQueryRuntime(io.siddhi.core.query.FindOnDemandQueryRuntime) UpdateOrInsertOnDemandQueryRuntime(io.siddhi.core.query.UpdateOrInsertOnDemandQueryRuntime) InsertOnDemandQueryRuntime(io.siddhi.core.query.InsertOnDemandQueryRuntime) DeleteOnDemandQueryRuntime(io.siddhi.core.query.DeleteOnDemandQueryRuntime) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) QuerySelector(io.siddhi.core.query.selector.QuerySelector) UpdateOnDemandQueryRuntime(io.siddhi.core.query.UpdateOnDemandQueryRuntime) UpdateOrInsertOnDemandQueryRuntime(io.siddhi.core.query.UpdateOrInsertOnDemandQueryRuntime)

Example 4 with StateEventFactory

use of io.siddhi.core.event.state.StateEventFactory in project siddhi by wso2.

the class TestStoreContainingInMemoryTable method query.

@Override
protected RecordIterator<Object[]> query(Map<String, Object> parameterMap, CompiledCondition compiledCondition, CompiledSelection compiledSelection, Attribute[] outputAttributes) {
    StreamEvent outEvent = inMemoryTable.find(compiledCondition, findMatchingEvent);
    List<Object[]> objects = new LinkedList<>();
    CompiledSelectionWithCache compiledSelectionWithCache = null;
    if (outEvent != null) {
        compiledSelectionWithCache = (CompiledSelectionWithCache) compiledSelection;
        StateEventFactory stateEventFactory = new StateEventFactory(compiledSelectionWithCache.getMetaStateEvent());
        Event[] cacheResultsAfterSelection = executeSelector(stateEventFactory, null, outEvent, compiledSelectionWithCache.getStoreEventIndex(), compiledSelectionWithCache.getQuerySelector());
        if (compiledSelectionWithCache.getQuerySelector() != null & compiledSelectionWithCache.getQuerySelector().getAttributeProcessorList().size() != 0) {
            compiledSelectionWithCache.getQuerySelector().process(generateResetComplexEventChunk(outEvent.getOutputData().length, stateEventFactory));
        }
        if (cacheResultsAfterSelection != null) {
            for (Event event : cacheResultsAfterSelection) {
                objects.add(event.getData());
            }
        }
    }
    return new TestStoreWithCacheIterator(objects.iterator());
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StateEvent(io.siddhi.core.event.state.StateEvent) LinkedList(java.util.LinkedList)

Example 5 with StateEventFactory

use of io.siddhi.core.event.state.StateEventFactory in project siddhi by wso2.

the class TestStoreForCacheMiss method query.

@Override
protected RecordIterator<Object[]> query(Map<String, Object> parameterMap, CompiledCondition compiledCondition, CompiledSelection compiledSelection, Attribute[] outputAttributes) {
    StreamEvent outEvent = inMemoryTable.find(compiledCondition, findMatchingEvent);
    List<Object[]> objects = new LinkedList<>();
    CompiledSelectionWithCache compiledSelectionWithCache = null;
    if (outEvent != null) {
        compiledSelectionWithCache = (CompiledSelectionWithCache) compiledSelection;
        StateEventFactory stateEventFactory = new StateEventFactory(compiledSelectionWithCache.getMetaStateEvent());
        Event[] cacheResultsAfterSelection = executeSelector(stateEventFactory, null, outEvent, compiledSelectionWithCache.getStoreEventIndex(), compiledSelectionWithCache.getQuerySelector());
        if (compiledSelectionWithCache.getQuerySelector() != null & compiledSelectionWithCache.getQuerySelector().getAttributeProcessorList().size() != 0) {
            compiledSelectionWithCache.getQuerySelector().process(generateResetComplexEventChunk(outEvent.getOutputData().length, stateEventFactory));
        }
        if (cacheResultsAfterSelection != null) {
            for (Event event : cacheResultsAfterSelection) {
                objects.add(event.getData());
            }
        }
    }
    return new TestStoreWithCacheIterator(objects.iterator());
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StateEventFactory(io.siddhi.core.event.state.StateEventFactory) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StateEvent(io.siddhi.core.event.state.StateEvent) LinkedList(java.util.LinkedList)

Aggregations

StateEventFactory (io.siddhi.core.event.state.StateEventFactory)9 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)6 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)5 ComplexEvent (io.siddhi.core.event.ComplexEvent)3 Event (io.siddhi.core.event.Event)3 StateEvent (io.siddhi.core.event.state.StateEvent)3 StreamEvent (io.siddhi.core.event.stream.StreamEvent)3 CompiledCondition (io.siddhi.core.util.collection.operator.CompiledCondition)3 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)3 LinkedList (java.util.LinkedList)3 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)2 DeleteOnDemandQueryRuntime (io.siddhi.core.query.DeleteOnDemandQueryRuntime)2 FindOnDemandQueryRuntime (io.siddhi.core.query.FindOnDemandQueryRuntime)2 InsertOnDemandQueryRuntime (io.siddhi.core.query.InsertOnDemandQueryRuntime)2 UpdateOnDemandQueryRuntime (io.siddhi.core.query.UpdateOnDemandQueryRuntime)2 UpdateOrInsertOnDemandQueryRuntime (io.siddhi.core.query.UpdateOrInsertOnDemandQueryRuntime)2 QuerySelector (io.siddhi.core.query.selector.QuerySelector)2 Attribute (io.siddhi.query.api.definition.Attribute)2 ReturnStream (io.siddhi.query.api.execution.query.output.stream.ReturnStream)2 StateEventCloner (io.siddhi.core.event.state.StateEventCloner)1