use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class UpdateOrInsertReducer method reduceEventsForInsert.
public List<Object[]> reduceEventsForInsert(List<Object[]> failedRecords, Map<String, ExpressionExecutor> inMemorySetExecutors) {
ComplexEventChunk<StreamEvent> toInsertEventChunk = new ComplexEventChunk<>();
StateEvent joinEvent = stateEventFactory.newInstance();
for (Object[] data : failedRecords) {
StreamEvent failedEvent = streamEventFactory.newInstance();
failedEvent.setOutputData(data);
joinEvent.setEvent(streamEventIndex, failedEvent);
boolean updated = false;
toInsertEventChunk.reset();
while (toInsertEventChunk.hasNext()) {
StreamEvent toInsertEvent = toInsertEventChunk.next();
joinEvent.setEvent(storeEventIndex, toInsertEvent);
if ((Boolean) inMemoryCompiledCondition.execute(joinEvent)) {
for (Map.Entry<String, ExpressionExecutor> entry : inMemorySetExecutors.entrySet()) {
toInsertEvent.setOutputData(entry.getValue().execute(failedEvent), attributeMap.get(entry.getKey()));
}
updated = true;
}
}
if (!updated) {
toInsertEventChunk.add(failedEvent);
}
}
List<Object[]> toInsertRecords = new LinkedList<>();
toInsertEventChunk.reset();
while (toInsertEventChunk.hasNext()) {
StreamEvent streamEvent = toInsertEventChunk.next();
toInsertRecords.add(streamEvent.getOutputData());
}
return toInsertRecords;
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbstractRecordTable method update.
@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, CompiledCondition compiledCondition, CompiledUpdateSet compiledUpdateSet) {
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();
}
try {
if (recordTableHandler != null) {
recordTableHandler.update(timestamp, recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps);
} else {
update(recordStoreCompiledCondition.getCompiledCondition(), updateConditionParameterMaps, recordTableCompiledUpdateSet.getUpdateSetMap(), updateSetParameterMaps);
}
} catch (ConnectionUnavailableException | DatabaseRuntimeException e) {
onUpdateError(updatingEventChunk, compiledCondition, compiledUpdateSet, e);
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class AbstractRecordTable method delete.
@Override
public void delete(ComplexEventChunk<StateEvent> deletingEventChunk, CompiledCondition compiledCondition) {
RecordStoreCompiledCondition recordStoreCompiledCondition = ((RecordStoreCompiledCondition) compiledCondition);
List<Map<String, Object>> deleteConditionParameterMaps = new ArrayList<>();
deletingEventChunk.reset();
long timestamp = 0L;
while (deletingEventChunk.hasNext()) {
StateEvent stateEvent = deletingEventChunk.next();
Map<String, Object> variableMap = new HashMap<>();
for (Map.Entry<String, ExpressionExecutor> entry : recordStoreCompiledCondition.variableExpressionExecutorMap.entrySet()) {
variableMap.put(entry.getKey(), entry.getValue().execute(stateEvent));
}
deleteConditionParameterMaps.add(variableMap);
timestamp = stateEvent.getTimestamp();
}
try {
if (recordTableHandler != null) {
recordTableHandler.delete(timestamp, deleteConditionParameterMaps, recordStoreCompiledCondition.getCompiledCondition());
} else {
delete(deleteConditionParameterMaps, recordStoreCompiledCondition.getCompiledCondition());
}
} catch (ConnectionUnavailableException | DatabaseRuntimeException e) {
onDeleteError(deletingEventChunk, compiledCondition, e);
}
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class OverwriteTableIndexOperator method tryUpdate.
@Override
public ComplexEventChunk<StateEvent> tryUpdate(ComplexEventChunk<StateEvent> updatingOrAddingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet, AddingStreamEventExtractor addingStreamEventExtractor) {
updatingOrAddingEventChunk.reset();
while (updatingOrAddingEventChunk.hasNext()) {
StateEvent overwritingOrAddingEvent = updatingOrAddingEventChunk.next();
((IndexedEventHolder) storeEvents).overwrite(addingStreamEventExtractor.getAddingStreamEvent(overwritingOrAddingEvent));
}
return null;
}
use of io.siddhi.core.event.state.StateEvent in project siddhi by wso2.
the class EventChunkOperator method update.
@Override
public void update(ComplexEventChunk<StateEvent> updatingEventChunk, Object storeEvents, InMemoryCompiledUpdateSet compiledUpdateSet) {
ComplexEventChunk<StreamEvent> storeEventChunk = (ComplexEventChunk<StreamEvent>) storeEvents;
updatingEventChunk.reset();
while (updatingEventChunk.hasNext()) {
StateEvent updatingEvent = updatingEventChunk.next();
try {
storeEventChunk.reset();
while (storeEventChunk.hasNext()) {
StreamEvent storeEvent = storeEventChunk.next();
updatingEvent.setEvent(storeEventPosition, storeEvent);
if ((Boolean) expressionExecutor.execute(updatingEvent)) {
for (Map.Entry<Integer, ExpressionExecutor> entry : compiledUpdateSet.getExpressionExecutorMap().entrySet()) {
storeEvent.setOutputData(entry.getValue().execute(updatingEvent), entry.getKey());
}
}
}
} finally {
updatingEvent.setEvent(storeEventPosition, null);
}
}
}
Aggregations