Search in sources :

Example 31 with ExpressionExecutor

use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.

the class InMemoryTable method reduceEventsForUpdateOrInsert.

protected ComplexEventChunk<StreamEvent> reduceEventsForUpdateOrInsert(AddingStreamEventExtractor addingStreamEventExtractor, InMemoryCompiledCondition inMemoryCompiledCondition, InMemoryCompiledUpdateSet compiledUpdateSet, ComplexEventChunk<StateEvent> failedEvents) {
    ComplexEventChunk<StreamEvent> toInsertEventChunk = new ComplexEventChunk<>();
    failedEvents.reset();
    while (failedEvents.hasNext()) {
        StateEvent failedEvent = failedEvents.next();
        boolean updated = false;
        toInsertEventChunk.reset();
        while (toInsertEventChunk.hasNext()) {
            StreamEvent toInsertEvent = toInsertEventChunk.next();
            failedEvent.setEvent(inMemoryCompiledCondition.getStoreEventIndex(), toInsertEvent);
            if ((Boolean) inMemoryCompiledCondition.getUpdateOrInsertExpressionExecutor().execute(failedEvent)) {
                for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                    toInsertEvent.setOutputData(entry.getValue().execute(failedEvent), entry.getKey());
                }
                updated = true;
            }
        }
        if (!updated) {
            toInsertEventChunk.add(addingStreamEventExtractor.getAddingStreamEvent(failedEvent));
        }
    }
    return toInsertEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) HashMap(java.util.HashMap) Map(java.util.Map)

Example 32 with ExpressionExecutor

use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.

the class AbstractRecordTable method compileCondition.

@Override
public CompiledCondition compileCondition(Expression condition, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiQueryContext siddhiQueryContext) {
    ExpressionExecutor inMemoryCompiledCondition = ExpressionParser.parseExpression(condition, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext);
    ExpressionBuilder expressionBuilder = new ExpressionBuilder(condition, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, new UpdateOrInsertReducer(inMemoryCompiledCondition, matchingMetaInfoHolder), null, siddhiQueryContext);
    CompiledCondition compileCondition = compileCondition(expressionBuilder);
    Map<String, ExpressionExecutor> expressionExecutorMap = expressionBuilder.getVariableExpressionExecutorMap();
    return new RecordStoreCompiledCondition(expressionExecutorMap, compileCondition, siddhiQueryContext);
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) CompiledCondition(io.siddhi.core.util.collection.operator.CompiledCondition)

Example 33 with ExpressionExecutor

use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.

the class AbstractRecordTable method updateOrAdd.

@Override
public void updateOrAdd(ComplexEventChunk<StateEvent> updateOrAddingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
    RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = (RecordTableCompiledUpdateSet) compiledUpdateSet;
    List<Map<String, Object>> updateConditionParameterMaps = new ArrayList<>();
    List<Map<String, Object>> updateSetParameterMaps = new ArrayList<>();
    List<Object[]> addingRecords = new ArrayList<>();
    updateOrAddingEventChunk.reset();
    long timestamp = 0L;
    while (updateOrAddingEventChunk.hasNext()) {
        StateEvent stateEvent = updateOrAddingEventChunk.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);
        addingRecords.add(stateEvent.getStreamEvent(0).getOutputData());
        timestamp = stateEvent.getTimestamp();
    }
    try {
        if (recordTableHandler != null) {
            recordTableHandler.updateOrAdd(timestamp, recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
        } else {
            updateOrAdd(recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps, addingRecords);
        }
    } catch (ConnectionUnavailableException | DatabaseRuntimeException e) {
        onUpdateOrAddError(updateOrAddingEventChunk, compiledCondition, compiledUpdateSet, addingStreamEventExtractor, e);
    }
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) HashMap(java.util.HashMap) DatabaseRuntimeException(io.siddhi.core.exception.DatabaseRuntimeException) ArrayList(java.util.ArrayList) StateEvent(io.siddhi.core.event.state.StateEvent) HashMap(java.util.HashMap) Map(java.util.Map) ConnectionUnavailableException(io.siddhi.core.exception.ConnectionUnavailableException)

Example 34 with ExpressionExecutor

use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.

the class AbstractRecordTable method find.

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

Example 35 with ExpressionExecutor

use of io.siddhi.core.executor.ExpressionExecutor in project siddhi by wso2.

the class CollectionOperator method tryUpdate.

@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
    updatingOrAddingEventChunk.reset();
    ComplexEventChunk<StateEvent> failedEventChunk = new ComplexEventChunk<>();
    while (updatingOrAddingEventChunk.hasNext()) {
        StateEvent updateOrAddingEvent = updatingOrAddingEventChunk.next();
        try {
            boolean updated = false;
            if (((Collection<StreamEvent>) storeEvents).size() > 0) {
                for (StreamEvent storeEvent : ((Collection<StreamEvent>) storeEvents)) {
                    updateOrAddingEvent.setEvent(storeEventPosition, storeEvent);
                    if ((Boolean) expressionExecutor.execute(updateOrAddingEvent)) {
                        for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
                            storeEvent.setOutputData(entry.getValue().execute(updateOrAddingEvent), entry.getKey());
                        }
                        updated = true;
                    }
                }
            }
            if (!updated) {
                updatingOrAddingEventChunk.remove();
                failedEventChunk.add(updateOrAddingEvent);
            }
        } finally {
            updateOrAddingEvent.setEvent(storeEventPosition, null);
        }
    }
    return failedEventChunk;
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) ExpressionExecutor(io.siddhi.core.executor.ExpressionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent) Map(java.util.Map)

Aggregations

ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)53 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)43 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)26 Map (java.util.Map)22 Attribute (io.siddhi.query.api.definition.Attribute)21 StreamEvent (io.siddhi.core.event.stream.StreamEvent)20 HashMap (java.util.HashMap)20 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)19 ComplexEventChunk (io.siddhi.core.event.ComplexEventChunk)14 ArrayList (java.util.ArrayList)13 StateEvent (io.siddhi.core.event.state.StateEvent)12 Variable (io.siddhi.query.api.expression.Variable)11 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)10 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)10 Expression (io.siddhi.query.api.expression.Expression)10 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)8 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)8 AndConditionExpressionExecutor (io.siddhi.core.executor.condition.AndConditionExpressionExecutor)5 ConditionExpressionExecutor (io.siddhi.core.executor.condition.ConditionExpressionExecutor)5 QueryableProcessor (io.siddhi.core.query.processor.stream.window.QueryableProcessor)4