use of org.wso2.siddhi.core.exception.OperationNotSupportedException 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.siddhi.core.exception.OperationNotSupportedException 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.exception.OperationNotSupportedException in project siddhi by wso2.
the class EventHolderPasser method parse.
public static EventHolder parse(AbstractDefinition tableDefinition, StreamEventPool tableStreamEventPool, SiddhiAppContext siddhiAppContext) {
ZeroStreamEventConverter eventConverter = new ZeroStreamEventConverter();
PrimaryKeyReferenceHolder[] primaryKeyReferenceHolders = null;
Map<String, Integer> indexMetaData = new HashMap<String, Integer>();
// primaryKey.
Annotation primaryKeyAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_PRIMARY_KEY, tableDefinition.getAnnotations());
if (primaryKeyAnnotation != null) {
if (primaryKeyAnnotation.getElements().size() == 0) {
throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_PRIMARY_KEY + " annotation " + "contains " + primaryKeyAnnotation.getElements().size() + " element, at '" + tableDefinition.getId() + "'");
}
primaryKeyReferenceHolders = primaryKeyAnnotation.getElements().stream().map(element -> element.getValue().trim()).map(key -> new PrimaryKeyReferenceHolder(key, tableDefinition.getAttributePosition(key))).toArray(PrimaryKeyReferenceHolder[]::new);
}
// indexes.
Annotation indexAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_INDEX, tableDefinition.getAnnotations());
if (indexAnnotation != null) {
if (indexAnnotation.getElements().size() == 0) {
throw new SiddhiAppValidationException(SiddhiConstants.ANNOTATION_INDEX + " annotation contains " + indexAnnotation.getElements().size() + " element");
}
for (Element element : indexAnnotation.getElements()) {
Integer previousValue = indexMetaData.put(element.getValue().trim(), tableDefinition.getAttributePosition(element.getValue().trim()));
if (previousValue != null) {
throw new SiddhiAppCreationException("Multiple " + SiddhiConstants.ANNOTATION_INDEX + " " + "annotations defined with same attribute '" + element.getValue().trim() + "', at '" + tableDefinition.getId() + "'", indexAnnotation.getQueryContextStartIndex(), indexAnnotation.getQueryContextEndIndex());
}
}
}
// not support indexBy.
Annotation indexByAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_INDEX_BY, tableDefinition.getAnnotations());
if (indexByAnnotation != null) {
throw new OperationNotSupportedException(SiddhiConstants.ANNOTATION_INDEX_BY + " annotation is not " + "supported anymore, please use @PrimaryKey or @Index annotations instead," + " at '" + tableDefinition.getId() + "'");
}
if (primaryKeyReferenceHolders != null || indexMetaData.size() > 0) {
boolean isNumeric = false;
if (primaryKeyReferenceHolders != null) {
if (primaryKeyReferenceHolders.length == 1) {
Attribute.Type type = tableDefinition.getAttributeType(primaryKeyReferenceHolders[0].getPrimaryKeyAttribute());
if (type == Attribute.Type.DOUBLE || type == Attribute.Type.FLOAT || type == Attribute.Type.INT || type == Attribute.Type.LONG) {
isNumeric = true;
}
}
}
return new IndexEventHolder(tableStreamEventPool, eventConverter, primaryKeyReferenceHolders, isNumeric, indexMetaData, tableDefinition, siddhiAppContext);
} else {
return new ListEventHolder(tableStreamEventPool, eventConverter);
}
}
use of org.wso2.siddhi.core.exception.OperationNotSupportedException in project siddhi by wso2.
the class JoinInputStreamParser method insertJoinProcessorsAndGetFindable.
private static FindableProcessor insertJoinProcessorsAndGetFindable(JoinProcessor preJoinProcessor, JoinProcessor postJoinProcessor, SingleStreamRuntime streamRuntime, SiddhiAppContext siddhiAppContext, boolean outputExpectsExpiredEvents, String queryName, InputStream inputStream) {
Processor lastProcessor = streamRuntime.getProcessorChain();
Processor prevLastProcessor = null;
if (lastProcessor != null) {
while (lastProcessor.getNextProcessor() != null) {
prevLastProcessor = lastProcessor;
lastProcessor = lastProcessor.getNextProcessor();
}
}
if (lastProcessor == null) {
try {
WindowProcessor windowProcessor = new LengthWindowProcessor();
ExpressionExecutor[] expressionExecutors = new ExpressionExecutor[1];
expressionExecutors[0] = new ConstantExpressionExecutor(0, Attribute.Type.INT);
ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader("", "length");
windowProcessor.initProcessor(((MetaStreamEvent) streamRuntime.getMetaComplexEvent()).getLastInputDefinition(), expressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents, queryName, inputStream);
lastProcessor = windowProcessor;
} catch (Throwable t) {
throw new SiddhiAppCreationException(t);
}
}
if (lastProcessor instanceof FindableProcessor) {
if (prevLastProcessor != null) {
prevLastProcessor.setNextProcessor(preJoinProcessor);
} else {
streamRuntime.setProcessorChain(preJoinProcessor);
}
preJoinProcessor.setNextProcessor(lastProcessor);
lastProcessor.setNextProcessor(postJoinProcessor);
return (FindableProcessor) lastProcessor;
} else {
throw new OperationNotSupportedException("Stream " + ((MetaStreamEvent) streamRuntime.getMetaComplexEvent()).getLastInputDefinition().getId() + "'s last processor " + lastProcessor.getClass().getCanonicalName() + " is not an instance of " + FindableProcessor.class.getCanonicalName() + " hence join cannot be proceed");
}
}
use of org.wso2.siddhi.core.exception.OperationNotSupportedException 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!");
}
}
Aggregations