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;
}
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);
}
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);
}
}
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();
}
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;
}
Aggregations