use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class IndexEventHolder method deleteAll.
@Override
public void deleteAll(Collection<StreamEvent> storeEventSet) {
for (StreamEvent streamEvent : storeEventSet) {
if (primaryKeyData != null) {
Object primaryKey = constructPrimaryKey(streamEvent, primaryKeyReferenceHolders);
StreamEvent deletedEvent = primaryKeyData.remove(primaryKey);
if (indexData != null) {
deleteFromIndexes(deletedEvent);
}
} else if (indexData != null) {
deleteFromIndexes(streamEvent);
}
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class IndexEventHolder method add.
@Override
public void add(ComplexEventChunk<StreamEvent> addingEventChunk) {
addingEventChunk.reset();
while (addingEventChunk.hasNext()) {
ComplexEvent complexEvent = addingEventChunk.next();
StreamEvent streamEvent = tableStreamEventPool.borrowEvent();
eventConverter.convertComplexEvent(complexEvent, streamEvent);
add(streamEvent);
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class IndexEventHolder method overwrite.
@Override
public void overwrite(StreamEvent streamEvent) {
StreamEvent deletedEvent = null;
if (primaryKeyData != null) {
Object primaryKey = constructPrimaryKey(streamEvent, primaryKeyReferenceHolders);
deletedEvent = primaryKeyData.put(primaryKey, streamEvent);
}
if (indexData != null) {
for (Map.Entry<String, Integer> indexEntry : indexMetaData.entrySet()) {
TreeMap<Object, Set<StreamEvent>> indexMap = indexData.get(indexEntry.getKey());
Object key = streamEvent.getOutputData()[indexEntry.getValue()];
if (deletedEvent != null) {
Set<StreamEvent> values = indexMap.get(key);
values.remove(deletedEvent);
if (values.size() == 0) {
indexMap.remove(key);
}
}
Set<StreamEvent> values = indexMap.get(key);
if (values == null) {
values = new HashSet<StreamEvent>();
values.add(streamEvent);
indexMap.put(streamEvent.getOutputData()[indexEntry.getValue()], values);
} else {
values.add(streamEvent);
}
}
}
}
use of org.wso2.siddhi.core.event.stream.StreamEvent in project siddhi by wso2.
the class IndexEventHolder method delete.
@Override
public void delete(String attribute, Compare.Operator operator, Object value) {
if (primaryKeyData != null && attribute.equals(primaryKeyAttributes)) {
switch(operator) {
case LESS_THAN:
for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, false).values().iterator(); iterator.hasNext(); ) {
StreamEvent toDeleteEvent = iterator.next();
iterator.remove();
deleteFromIndexes(toDeleteEvent);
}
return;
case GREATER_THAN:
for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, false).values().iterator(); iterator.hasNext(); ) {
StreamEvent toDeleteEvent = iterator.next();
iterator.remove();
deleteFromIndexes(toDeleteEvent);
}
return;
case LESS_THAN_EQUAL:
for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, true).values().iterator(); iterator.hasNext(); ) {
StreamEvent toDeleteEvent = iterator.next();
iterator.remove();
deleteFromIndexes(toDeleteEvent);
}
return;
case GREATER_THAN_EQUAL:
for (Iterator<StreamEvent> iterator = ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, true).values().iterator(); iterator.hasNext(); ) {
StreamEvent toDeleteEvent = iterator.next();
iterator.remove();
deleteFromIndexes(toDeleteEvent);
}
return;
case EQUAL:
StreamEvent deletedEvent = primaryKeyData.remove(value);
if (deletedEvent != null) {
deleteFromIndexes(deletedEvent);
}
return;
case NOT_EQUAL:
StreamEvent streamEvent = primaryKeyData.get(value);
deleteAll();
if (streamEvent != null) {
add(streamEvent);
}
return;
}
} else {
switch(operator) {
case LESS_THAN:
for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).headMap(value, false).values().iterator(); iterator.hasNext(); ) {
Set<StreamEvent> deletedEventSet = iterator.next();
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
iterator.remove();
}
return;
case GREATER_THAN:
for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).tailMap(value, false).values().iterator(); iterator.hasNext(); ) {
Set<StreamEvent> deletedEventSet = iterator.next();
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
iterator.remove();
}
return;
case LESS_THAN_EQUAL:
for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).headMap(value, true).values().iterator(); iterator.hasNext(); ) {
Set<StreamEvent> deletedEventSet = iterator.next();
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
iterator.remove();
}
return;
case GREATER_THAN_EQUAL:
for (Iterator<Set<StreamEvent>> iterator = indexData.get(attribute).tailMap(value, true).values().iterator(); iterator.hasNext(); ) {
Set<StreamEvent> deletedEventSet = iterator.next();
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
iterator.remove();
}
return;
case EQUAL:
Set<StreamEvent> deletedEventSet = indexData.get(attribute).remove(value);
if (deletedEventSet != null && deletedEventSet.size() > 0) {
deleteFromIndexesAndPrimaryKey(attribute, deletedEventSet);
}
return;
case NOT_EQUAL:
Set<StreamEvent> matchingEventSet = indexData.get(attribute).get(value);
deleteAll();
for (StreamEvent matchingEvent : matchingEventSet) {
add(matchingEvent);
}
return;
}
}
throw new OperationNotSupportedException(operator + " not supported for '" + value + "' by " + getClass().getName());
}
use of org.wso2.siddhi.core.event.stream.StreamEvent 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.compiledCondition);
} else {
records = find(findConditionParameterMap, recordStoreCompiledCondition.compiledCondition);
}
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();
}
Aggregations