use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.
the class IndexEventHolder method findEvents.
@Override
public Collection<StreamEvent> findEvents(String attribute, Compare.Operator operator, Object value) {
if (primaryKeyData != null && attribute.equals(primaryKeyAttributes)) {
StreamEvent resultEvent;
HashSet<StreamEvent> resultEventSet;
switch(operator) {
case LESS_THAN:
return ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, false).values();
case GREATER_THAN:
return ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, false).values();
case LESS_THAN_EQUAL:
return ((TreeMap<Object, StreamEvent>) primaryKeyData).headMap(value, true).values();
case GREATER_THAN_EQUAL:
return ((TreeMap<Object, StreamEvent>) primaryKeyData).tailMap(value, true).values();
case EQUAL:
resultEventSet = new HashSet<StreamEvent>();
resultEvent = primaryKeyData.get(value);
if (resultEvent != null) {
resultEventSet.add(resultEvent);
}
return resultEventSet;
case NOT_EQUAL:
if (primaryKeyData.size() > 0) {
resultEventSet = new HashSet<StreamEvent>(primaryKeyData.values());
} else {
return new HashSet<StreamEvent>();
}
resultEvent = primaryKeyData.get(value);
if (resultEvent != null) {
resultEventSet.remove(resultEvent);
}
return resultEventSet;
}
} else {
HashSet<StreamEvent> resultEventSet = new HashSet<StreamEvent>();
TreeMap<Object, Set<StreamEvent>> currentIndexedData = indexData.get(attribute);
Set<StreamEvent> resultEvents;
switch(operator) {
case LESS_THAN:
for (Set<StreamEvent> eventSet : currentIndexedData.headMap(value, false).values()) {
resultEventSet.addAll(eventSet);
}
return resultEventSet;
case GREATER_THAN:
for (Set<StreamEvent> eventSet : currentIndexedData.tailMap(value, false).values()) {
resultEventSet.addAll(eventSet);
}
return resultEventSet;
case LESS_THAN_EQUAL:
for (Set<StreamEvent> eventSet : currentIndexedData.headMap(value, true).values()) {
resultEventSet.addAll(eventSet);
}
return resultEventSet;
case GREATER_THAN_EQUAL:
for (Set<StreamEvent> eventSet : currentIndexedData.tailMap(value, true).values()) {
resultEventSet.addAll(eventSet);
}
return resultEventSet;
case EQUAL:
resultEvents = currentIndexedData.get(value);
if (resultEvents != null) {
resultEventSet.addAll(resultEvents);
}
return resultEventSet;
case NOT_EQUAL:
if (currentIndexedData.size() > 0) {
resultEventSet = new HashSet<StreamEvent>();
for (Set<StreamEvent> eventSet : currentIndexedData.values()) {
resultEventSet.addAll(eventSet);
}
} else {
resultEventSet = new HashSet<StreamEvent>();
}
resultEvents = currentIndexedData.get(value);
if (resultEvents != null) {
resultEventSet.removeAll(resultEvents);
}
return resultEventSet;
}
}
throw new OperationNotSupportedException(operator + " not supported for '" + value + "' by " + getClass().getName());
}
use of org.wso2.carbon.registry.core.Collection 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.carbon.registry.core.Collection in project siddhi by wso2.
the class OperatorParser method constructOperator.
public static Operator constructOperator(Object storeEvents, Expression expression, MatchingMetaInfoHolder matchingMetaInfoHolder, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) {
if (storeEvents instanceof IndexedEventHolder) {
CollectionExpression collectionExpression = CollectionExpressionParser.parseCollectionExpression(expression, matchingMetaInfoHolder, (IndexedEventHolder) storeEvents);
CollectionExecutor collectionExecutor = CollectionExpressionParser.buildCollectionExecutor(collectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, true, queryName);
if (collectionExpression instanceof CompareCollectionExpression && ((CompareCollectionExpression) collectionExpression).getOperator() == Compare.Operator.EQUAL && (collectionExpression.getCollectionScope() == INDEXED_RESULT_SET || collectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET) && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders() != null && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders().length == 1 && ((IndexedEventHolder) storeEvents).getPrimaryKeyReferenceHolders()[0].getPrimaryKeyAttribute().equals(((AttributeCollectionExpression) ((CompareCollectionExpression) collectionExpression).getAttributeCollectionExpression()).getAttribute())) {
return new OverwriteTableIndexOperator(collectionExecutor, queryName);
} else if (collectionExpression instanceof AndMultiPrimaryKeyCollectionExpression && collectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET) {
return new OverwriteTableIndexOperator(collectionExecutor, queryName);
} else {
return new IndexOperator(collectionExecutor, queryName);
}
} else if (storeEvents instanceof ComplexEventChunk) {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
return new EventChunkOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
} else if (storeEvents instanceof Map) {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
return new MapOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
} else if (storeEvents instanceof Collection) {
ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
return new CollectionOperator(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
} else {
throw new OperationNotSupportedException(storeEvents.getClass() + " is not supported by OperatorParser!");
}
}
use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.
the class AnyAndCollectionExecutor method find.
public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
Collection<StreamEvent> resultEventSet = findEvents(matchingEvent, indexedEventHolder);
ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
if (resultEventSet != null) {
for (StreamEvent resultEvent : resultEventSet) {
if (storeEventCloner != null) {
returnEventChunk.add(storeEventCloner.copyStreamEvent(resultEvent));
} else {
returnEventChunk.add(resultEvent);
}
}
return returnEventChunk.getFirst();
} else {
return exhaustiveCollectionExecutor.find(matchingEvent, indexedEventHolder, storeEventCloner);
}
}
use of org.wso2.carbon.registry.core.Collection in project siddhi by wso2.
the class ExhaustiveCollectionExecutor method find.
public StreamEvent find(StateEvent matchingEvent, IndexedEventHolder indexedEventHolder, StreamEventCloner storeEventCloner) {
ComplexEventChunk<StreamEvent> returnEventChunk = new ComplexEventChunk<StreamEvent>(false);
Collection<StreamEvent> storeEvents = indexedEventHolder.getAllEvents();
for (StreamEvent storeEvent : storeEvents) {
matchingEvent.setEvent(storeEventIndex, storeEvent);
if ((Boolean) expressionExecutor.execute(matchingEvent)) {
if (storeEventCloner != null) {
returnEventChunk.add(storeEventCloner.copyStreamEvent(storeEvent));
} else {
returnEventChunk.add(storeEvent);
}
}
matchingEvent.setEvent(storeEventIndex, null);
}
return returnEventChunk.getFirst();
}
Aggregations