Search in sources :

Example 11 with CompiledCondition

use of org.wso2.siddhi.core.util.collection.operator.CompiledCondition 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 12 with CompiledCondition

use of org.wso2.siddhi.core.util.collection.operator.CompiledCondition in project siddhi by wso2.

the class FindStoreQueryRuntime method execute.

@Override
public Event[] execute() {
    try {
        StateEvent stateEvent = new StateEvent(1, 0);
        StreamEvent streamEvents = null;
        switch(eventType) {
            case TABLE:
                streamEvents = table.find(stateEvent, compiledCondition);
                break;
            case WINDOW:
                streamEvents = window.find(stateEvent, compiledCondition);
                break;
            case AGGREGATE:
                stateEvent = new StateEvent(2, 0);
                StreamEvent streamEvent = new StreamEvent(0, 2, 0);
                stateEvent.addEvent(0, streamEvent);
                streamEvents = aggregation.find(stateEvent, compiledCondition);
                break;
            case DEFAULT:
                break;
        }
        if (streamEvents == null) {
            return null;
        } else {
            if (selector != null) {
                return executeSelector(streamEvents, eventType);
            } else {
                List<Event> events = new ArrayList<Event>();
                while (streamEvents != null) {
                    events.add(new Event(streamEvents.getTimestamp(), streamEvents.getOutputData()));
                    streamEvents = streamEvents.getNext();
                }
                return events.toArray(new Event[0]);
            }
        }
    } catch (Throwable t) {
        throw new StoreQueryRuntimeException("Error executing '" + queryName + "', " + t.getMessage(), t);
    }
}
Also used : MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) StoreQueryRuntimeException(org.wso2.siddhi.core.exception.StoreQueryRuntimeException) ArrayList(java.util.ArrayList) StateEvent(org.wso2.siddhi.core.event.state.StateEvent) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ComplexEvent(org.wso2.siddhi.core.event.ComplexEvent) Event(org.wso2.siddhi.core.event.Event) StateEvent(org.wso2.siddhi.core.event.state.StateEvent)

Example 13 with CompiledCondition

use of org.wso2.siddhi.core.util.collection.operator.CompiledCondition in project siddhi by wso2.

the class AbstractQueryableRecordTable method query.

@Override
public StreamEvent query(StateEvent matchingEvent, CompiledCondition compiledCondition, CompiledSelection compiledSelection) throws ConnectionUnavailableException {
    RecordStoreCompiledSelection recordStoreCompiledSelection = ((RecordStoreCompiledSelection) compiledSelection);
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    Map<String, Object> parameterMap = new HashMap<>();
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
        parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }
    for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledSelection.variableExpressionExecutorMap.entrySet()) {
        parameterMap.put(entry.getKey(), entry.getValue().execute(matchingEvent));
    }
    Iterator<Object[]> records;
    if (recordTableHandler != null) {
        records = recordTableHandler.query(matchingEvent.getTimestamp(), parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
    } else {
        records = query(parameterMap, recordStoreCompiledCondition.compiledCondition, recordStoreCompiledSelection.compiledSelection);
    }
    ComplexEventChunk<StreamEvent> streamEventComplexEventChunk = new ComplexEventChunk<>(true);
    if (records != null) {
        while (records.hasNext()) {
            Object[] record = records.next();
            StreamEvent streamEvent = storeEventPool.borrowEvent();
            System.arraycopy(record, 0, streamEvent.getOutputData(), 0, record.length);
            streamEventComplexEventChunk.add(streamEvent);
        }
    }
    return streamEventComplexEventChunk.getFirst();
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) HashMap(java.util.HashMap) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 14 with CompiledCondition

use of org.wso2.siddhi.core.util.collection.operator.CompiledCondition in project siddhi by wso2.

the class AbstractRecordTable method update.

@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet) throws ConnectionUnavailableException {
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
    List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
    List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
    updatingEventChunk.reset();
    long timestamp = 0L;
    while (updatingEventChunk.hasNext()) {
        StateEvent stateEvent = updatingEventChunk.next();
        Map<String, Object> variableMap = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
            variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateConditionParameterMaps.add(variableMap);
        Map<String, Object> variableMapForUpdateSet = new HashMap<>();
        for (Map.Entry<String, ExpressionExecutor> entry : recordTableCompiledUpdateSet.getExpressionExecutorMap().entrySet()) {
            variableMapForUpdateSet.put(entry.getKey(), entry.getValue().execute(stateEvent));
        }
        updateSetParameterMaps.add(variableMapForUpdateSet);
        timestamp = stateEvent.getTimestamp();
    }
    if (recordTableHandler != null) {
        recordTableHandler.update(timestamp, recordStoreCompiledCondition.compiledCondition, updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps);
    } else {
        update(recordStoreCompiledCondition.compiledCondition, updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps);
    }
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StateEvent(org.wso2.siddhi.core.event.state.StateEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 15 with CompiledCondition

use of org.wso2.siddhi.core.util.collection.operator.CompiledCondition in project siddhi by wso2.

the class AbstractRecordTable method compileCondition.

@Override
public CompiledCondition compileCondition(Expression condition, MatchingMetaInfoHolder matchingMetaInfoHolder, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) {
    ExpressionBuilder expressionBuilder = new ExpressionBuilder(condition, matchingMetaInfoHolder, siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
    CompiledCondition compileCondition = compileCondition(expressionBuilder);
    Map<String, ExpressionExecutor> expressionExecutorMap = expressionBuilder.getVariableExpressionExecutorMap();
    return new RecordStoreCompiledCondition(expressionExecutorMap, compileCondition);
}
Also used : CompiledCondition(org.wso2.siddhi.core.util.collection.operator.CompiledCondition) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor)

Aggregations

VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)9 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)8 CompiledCondition (org.wso2.siddhi.core.util.collection.operator.CompiledCondition)8 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)7 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)7 MatchingMetaInfoHolder (org.wso2.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)7 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)5 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)4 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)4 Attribute (org.wso2.siddhi.query.api.definition.Attribute)4 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)3 Table (org.wso2.siddhi.core.table.Table)3 IncrementalAggregateCompileCondition (org.wso2.siddhi.core.util.collection.operator.IncrementalAggregateCompileCondition)3 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)2 Event (org.wso2.siddhi.core.event.Event)2 StreamEventPool (org.wso2.siddhi.core.event.stream.StreamEventPool)2 ComplexEventPopulater (org.wso2.siddhi.core.event.stream.populater.ComplexEventPopulater)2