Search in sources :

Example 6 with Add

use of org.wso2.siddhi.query.api.expression.math.Add in project siddhi by wso2.

the class FrequentWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        StreamEvent streamEvent = streamEventChunk.getFirst();
        streamEventChunk.clear();
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        while (streamEvent != null) {
            StreamEvent next = streamEvent.getNext();
            streamEvent.setNext(null);
            StreamEvent clonedEvent = streamEventCloner.copyStreamEvent(streamEvent);
            clonedEvent.setType(StreamEvent.Type.EXPIRED);
            String key = generateKey(streamEvent);
            StreamEvent oldEvent = map.put(key, clonedEvent);
            if (oldEvent != null) {
                countMap.put(key, countMap.get(key) + 1);
                streamEventChunk.add(streamEvent);
            } else {
                // This is a new event
                if (map.size() > mostFrequentCount) {
                    List<String> keys = new ArrayList<String>(countMap.keySet());
                    for (int i = 0; i < mostFrequentCount; i++) {
                        int count = countMap.get(keys.get(i)) - 1;
                        if (count == 0) {
                            countMap.remove(keys.get(i));
                            StreamEvent expiredEvent = map.remove(keys.get(i));
                            expiredEvent.setTimestamp(currentTime);
                            streamEventChunk.add(expiredEvent);
                        } else {
                            countMap.put(keys.get(i), count);
                        }
                    }
                    // now we have tried to remove one for newly added item
                    if (map.size() > mostFrequentCount) {
                        // nothing happend by the attempt to remove one from the
                        // map so we are ignoring this event
                        map.remove(key);
                    // Here we do nothing just drop the message
                    } else {
                        // we got some space, event is already there in map object
                        // we just have to add it to the countMap
                        countMap.put(key, 1);
                        streamEventChunk.add(streamEvent);
                    }
                } else {
                    countMap.put(generateKey(streamEvent), 1);
                    streamEventChunk.add(streamEvent);
                }
            }
            streamEvent = next;
        }
    }
    nextProcessor.process(streamEventChunk);
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList)

Example 7 with Add

use of org.wso2.siddhi.query.api.expression.math.Add in project siddhi by wso2.

the class LengthBatchWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<ComplexEventChunk<StreamEvent>>();
    synchronized (this) {
        ComplexEventChunk<StreamEvent> outputStreamEventChunk = new ComplexEventChunk<StreamEvent>(true);
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
            currentEventChunk.add(clonedStreamEvent);
            count++;
            if (count == length) {
                if (outputExpectsExpiredEvents) {
                    if (expiredEventChunk.getFirst() != null) {
                        while (expiredEventChunk.hasNext()) {
                            StreamEvent expiredEvent = expiredEventChunk.next();
                            expiredEvent.setTimestamp(currentTime);
                        }
                        outputStreamEventChunk.add(expiredEventChunk.getFirst());
                    }
                }
                if (expiredEventChunk != null) {
                    expiredEventChunk.clear();
                }
                if (currentEventChunk.getFirst() != null) {
                    // add reset event in front of current events
                    outputStreamEventChunk.add(resetEvent);
                    resetEvent = null;
                    if (expiredEventChunk != null) {
                        currentEventChunk.reset();
                        while (currentEventChunk.hasNext()) {
                            StreamEvent currentEvent = currentEventChunk.next();
                            StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
                            toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                            expiredEventChunk.add(toExpireEvent);
                        }
                    }
                    resetEvent = streamEventCloner.copyStreamEvent(currentEventChunk.getFirst());
                    resetEvent.setType(ComplexEvent.Type.RESET);
                    outputStreamEventChunk.add(currentEventChunk.getFirst());
                }
                currentEventChunk.clear();
                count = 0;
                if (outputStreamEventChunk.getFirst() != null) {
                    streamEventChunks.add(outputStreamEventChunk);
                }
            }
        }
    }
    for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
        nextProcessor.process(outputStreamEventChunk);
    }
}
Also used : ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList)

Example 8 with Add

use of org.wso2.siddhi.query.api.expression.math.Add in project siddhi by wso2.

the class TimeBatchWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner) {
    synchronized (this) {
        if (nextEmitTime == -1) {
            long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
            if (isStartTimeEnabled) {
                nextEmitTime = getNextEmitTime(currentTime);
            } else {
                nextEmitTime = siddhiAppContext.getTimestampGenerator().currentTime() + timeInMilliSeconds;
            }
            scheduler.notifyAt(nextEmitTime);
        }
        long currentTime = siddhiAppContext.getTimestampGenerator().currentTime();
        boolean sendEvents;
        if (currentTime >= nextEmitTime) {
            nextEmitTime += timeInMilliSeconds;
            scheduler.notifyAt(nextEmitTime);
            sendEvents = true;
        } else {
            sendEvents = false;
        }
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            if (streamEvent.getType() != ComplexEvent.Type.CURRENT) {
                continue;
            }
            StreamEvent clonedStreamEvent = streamEventCloner.copyStreamEvent(streamEvent);
            currentEventChunk.add(clonedStreamEvent);
        }
        streamEventChunk.clear();
        if (sendEvents) {
            if (outputExpectsExpiredEvents) {
                if (expiredEventChunk.getFirst() != null) {
                    while (expiredEventChunk.hasNext()) {
                        StreamEvent expiredEvent = expiredEventChunk.next();
                        expiredEvent.setTimestamp(currentTime);
                    }
                    streamEventChunk.add(expiredEventChunk.getFirst());
                }
            }
            if (expiredEventChunk != null) {
                expiredEventChunk.clear();
            }
            if (currentEventChunk.getFirst() != null) {
                // add reset event in front of current events
                streamEventChunk.add(resetEvent);
                resetEvent = null;
                if (expiredEventChunk != null) {
                    currentEventChunk.reset();
                    while (currentEventChunk.hasNext()) {
                        StreamEvent currentEvent = currentEventChunk.next();
                        StreamEvent toExpireEvent = streamEventCloner.copyStreamEvent(currentEvent);
                        toExpireEvent.setType(StreamEvent.Type.EXPIRED);
                        expiredEventChunk.add(toExpireEvent);
                    }
                }
                resetEvent = streamEventCloner.copyStreamEvent(currentEventChunk.getFirst());
                resetEvent.setType(ComplexEvent.Type.RESET);
                streamEventChunk.add(currentEventChunk.getFirst());
            }
            currentEventChunk.clear();
        }
    }
    if (streamEventChunk.getFirst() != null) {
        streamEventChunk.setBatch(true);
        nextProcessor.process(streamEventChunk);
        streamEventChunk.setBatch(false);
    }
}
Also used : StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 9 with Add

use of org.wso2.siddhi.query.api.expression.math.Add in project siddhi by wso2.

the class CollectionExpressionParser method parseInternalCollectionExpression.

/**
 * Parse the given expression and create the appropriate Executor by recursively traversing the expression.
 *
 * @param expression             Expression to be parsed
 * @param matchingMetaInfoHolder matchingMetaInfoHolder
 * @param indexedEventHolder     indexed event holder
 * @return ExpressionExecutor
 */
private static CollectionExpression parseInternalCollectionExpression(Expression expression, MatchingMetaInfoHolder matchingMetaInfoHolder, IndexedEventHolder indexedEventHolder) {
    if (expression instanceof And) {
        CollectionExpression leftCollectionExpression = parseInternalCollectionExpression(((And) expression).getLeftExpression(), matchingMetaInfoHolder, indexedEventHolder);
        CollectionExpression rightCollectionExpression = parseInternalCollectionExpression(((And) expression).getRightExpression(), matchingMetaInfoHolder, indexedEventHolder);
        if (leftCollectionExpression.getCollectionScope() == NON && rightCollectionExpression.getCollectionScope() == NON) {
            return new BasicCollectionExpression(expression, NON);
        } else if ((leftCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET) && (rightCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PRIMARY_KEY_RESULT_SET || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET)) {
            Set<String> primaryKeys = new HashSet<>();
            primaryKeys.addAll(leftCollectionExpression.getMultiPrimaryKeys());
            primaryKeys.addAll(rightCollectionExpression.getMultiPrimaryKeys());
            if (indexedEventHolder.getPrimaryKeyReferenceHolders() != null && primaryKeys.size() == indexedEventHolder.getPrimaryKeyReferenceHolders().length) {
                return new AndMultiPrimaryKeyCollectionExpression(expression, PRIMARY_KEY_RESULT_SET, leftCollectionExpression, rightCollectionExpression);
            } else {
                return new AndCollectionExpression(expression, PARTIAL_PRIMARY_KEY_RESULT_SET, leftCollectionExpression, rightCollectionExpression);
            }
        // TODO support query rewriting to group all PARTIAL_PRIMARY_KEY_RESULT_SETs together such that it can
        // build AndMultiPrimaryKeyCollectionExpression.
        } else if ((leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET || leftCollectionExpression.getCollectionScope() == NON || leftCollectionExpression.getCollectionScope() == EXHAUSTIVE) && (rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET || rightCollectionExpression.getCollectionScope() == NON || rightCollectionExpression.getCollectionScope() == EXHAUSTIVE)) {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        } else {
            return new AndCollectionExpression(expression, OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET, leftCollectionExpression, rightCollectionExpression);
        }
    } else if (expression instanceof Or) {
        CollectionExpression leftCollectionExpression = parseInternalCollectionExpression(((Or) expression).getLeftExpression(), matchingMetaInfoHolder, indexedEventHolder);
        CollectionExpression rightCollectionExpression = parseInternalCollectionExpression(((Or) expression).getRightExpression(), matchingMetaInfoHolder, indexedEventHolder);
        if (leftCollectionExpression.getCollectionScope() == NON && rightCollectionExpression.getCollectionScope() == NON) {
            return new BasicCollectionExpression(expression, NON);
        } else if (leftCollectionExpression.getCollectionScope() == EXHAUSTIVE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET || rightCollectionExpression.getCollectionScope() == EXHAUSTIVE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET) {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        } else {
            return new OrCollectionExpression(expression, OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET, leftCollectionExpression, rightCollectionExpression);
        }
    } else if (expression instanceof Not) {
        CollectionExpression notCollectionExpression = parseInternalCollectionExpression(((Not) expression).getExpression(), matchingMetaInfoHolder, indexedEventHolder);
        switch(notCollectionExpression.getCollectionScope()) {
            case NON:
                return new BasicCollectionExpression(expression, NON);
            case PRIMARY_KEY_ATTRIBUTE:
                return new NotCollectionExpression(expression, PRIMARY_KEY_RESULT_SET, notCollectionExpression);
            case INDEXED_ATTRIBUTE:
                return new NotCollectionExpression(expression, INDEXED_RESULT_SET, notCollectionExpression);
            case PRIMARY_KEY_RESULT_SET:
            case INDEXED_RESULT_SET:
            case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
                return new NotCollectionExpression(expression, OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET, notCollectionExpression);
            case PARTIAL_PRIMARY_KEY_ATTRIBUTE:
            case PARTIAL_PRIMARY_KEY_RESULT_SET:
            case EXHAUSTIVE:
                return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
    } else if (expression instanceof Compare) {
        CollectionExpression leftCollectionExpression = parseInternalCollectionExpression(((Compare) expression).getLeftExpression(), matchingMetaInfoHolder, indexedEventHolder);
        CollectionExpression rightCollectionExpression = parseInternalCollectionExpression(((Compare) expression).getRightExpression(), matchingMetaInfoHolder, indexedEventHolder);
        if (leftCollectionExpression.getCollectionScope() == NON && rightCollectionExpression.getCollectionScope() == NON) {
            // comparing two stream attributes with O(1) time complexity
            return new BasicCollectionExpression(expression, NON);
        } else if ((leftCollectionExpression.getCollectionScope() == INDEXED_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE || leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE) && rightCollectionExpression.getCollectionScope() == NON) {
            switch(leftCollectionExpression.getCollectionScope()) {
                case INDEXED_ATTRIBUTE:
                    return new CompareCollectionExpression((Compare) expression, INDEXED_RESULT_SET, leftCollectionExpression, ((Compare) expression).getOperator(), rightCollectionExpression);
                case PRIMARY_KEY_ATTRIBUTE:
                    return new CompareCollectionExpression((Compare) expression, PRIMARY_KEY_RESULT_SET, leftCollectionExpression, ((Compare) expression).getOperator(), rightCollectionExpression);
                case PARTIAL_PRIMARY_KEY_ATTRIBUTE:
                    return new CompareCollectionExpression((Compare) expression, PARTIAL_PRIMARY_KEY_RESULT_SET, leftCollectionExpression, ((Compare) expression).getOperator(), rightCollectionExpression);
            }
        } else if (leftCollectionExpression.getCollectionScope() == NON && (rightCollectionExpression.getCollectionScope() == INDEXED_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE || rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_ATTRIBUTE)) {
            Compare.Operator operator = ((Compare) expression).getOperator();
            // moving let to right
            switch(operator) {
                case LESS_THAN:
                    operator = Compare.Operator.GREATER_THAN;
                    break;
                case GREATER_THAN:
                    operator = Compare.Operator.LESS_THAN;
                    break;
                case LESS_THAN_EQUAL:
                    operator = Compare.Operator.GREATER_THAN_EQUAL;
                    break;
                case GREATER_THAN_EQUAL:
                    operator = Compare.Operator.LESS_THAN_EQUAL;
                    break;
                case EQUAL:
                    break;
                case NOT_EQUAL:
                    break;
            }
            switch(rightCollectionExpression.getCollectionScope()) {
                case INDEXED_ATTRIBUTE:
                    return new CompareCollectionExpression((Compare) expression, INDEXED_RESULT_SET, rightCollectionExpression, operator, leftCollectionExpression);
                case PRIMARY_KEY_ATTRIBUTE:
                    return new CompareCollectionExpression((Compare) expression, PRIMARY_KEY_RESULT_SET, rightCollectionExpression, operator, leftCollectionExpression);
                case PARTIAL_PRIMARY_KEY_ATTRIBUTE:
                    return new CompareCollectionExpression((Compare) expression, PARTIAL_PRIMARY_KEY_RESULT_SET, rightCollectionExpression, operator, leftCollectionExpression);
            }
        } else {
            // comparing non indexed table with stream attributes or another table attribute
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
    } else if (expression instanceof Constant) {
        return new BasicCollectionExpression(expression, NON);
    } else if (expression instanceof Variable) {
        if (isCollectionVariable(matchingMetaInfoHolder, (Variable) expression)) {
            if (indexedEventHolder.isAttributeIndexed(((Variable) expression).getAttributeName())) {
                return new AttributeCollectionExpression(expression, ((Variable) expression).getAttributeName(), INDEXED_ATTRIBUTE);
            } else if (indexedEventHolder.isMultiPrimaryKeyAttribute(((Variable) expression).getAttributeName())) {
                if (indexedEventHolder.getPrimaryKeyReferenceHolders() != null && indexedEventHolder.getPrimaryKeyReferenceHolders().length == 1) {
                    return new AttributeCollectionExpression(expression, ((Variable) expression).getAttributeName(), PRIMARY_KEY_ATTRIBUTE);
                } else {
                    return new AttributeCollectionExpression(expression, ((Variable) expression).getAttributeName(), PARTIAL_PRIMARY_KEY_ATTRIBUTE);
                }
            } else {
                return new BasicCollectionExpression(expression, EXHAUSTIVE);
            }
        } else {
            return new BasicCollectionExpression(expression, NON);
        }
    } else if (expression instanceof Multiply) {
        CollectionExpression left = parseInternalCollectionExpression(((Multiply) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
        CollectionExpression right = parseInternalCollectionExpression(((Multiply) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
        if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
            return new BasicCollectionExpression(expression, NON);
        } else {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
    } else if (expression instanceof Add) {
        CollectionExpression left = parseInternalCollectionExpression(((Add) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
        CollectionExpression right = parseInternalCollectionExpression(((Add) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
        if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
            return new BasicCollectionExpression(expression, NON);
        } else {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
    } else if (expression instanceof Subtract) {
        CollectionExpression left = parseInternalCollectionExpression(((Subtract) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
        CollectionExpression right = parseInternalCollectionExpression(((Subtract) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
        if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
            return new BasicCollectionExpression(expression, NON);
        } else {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
    } else if (expression instanceof Mod) {
        CollectionExpression left = parseInternalCollectionExpression(((Mod) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
        CollectionExpression right = parseInternalCollectionExpression(((Mod) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
        if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
            return new BasicCollectionExpression(expression, NON);
        } else {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
    } else if (expression instanceof Divide) {
        CollectionExpression left = parseInternalCollectionExpression(((Divide) expression).getLeftValue(), matchingMetaInfoHolder, indexedEventHolder);
        CollectionExpression right = parseInternalCollectionExpression(((Divide) expression).getRightValue(), matchingMetaInfoHolder, indexedEventHolder);
        if (left.getCollectionScope() == NON && right.getCollectionScope() == NON) {
            return new BasicCollectionExpression(expression, NON);
        } else {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
    } else if (expression instanceof AttributeFunction) {
        Expression[] innerExpressions = ((AttributeFunction) expression).getParameters();
        for (Expression aExpression : innerExpressions) {
            CollectionExpression aCollectionExpression = parseInternalCollectionExpression(aExpression, matchingMetaInfoHolder, indexedEventHolder);
            if (aCollectionExpression.getCollectionScope() != NON) {
                return new BasicCollectionExpression(expression, EXHAUSTIVE);
            }
        }
        return new BasicCollectionExpression(expression, NON);
    } else if (expression instanceof In) {
        CollectionExpression inCollectionExpression = parseInternalCollectionExpression(((In) expression).getExpression(), matchingMetaInfoHolder, indexedEventHolder);
        if (inCollectionExpression.getCollectionScope() != NON) {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
        return new BasicCollectionExpression(expression, NON);
    } else if (expression instanceof IsNull) {
        CollectionExpression nullCollectionExpression = parseInternalCollectionExpression(((IsNull) expression).getExpression(), matchingMetaInfoHolder, indexedEventHolder);
        if (nullCollectionExpression.getCollectionScope() == NON) {
            return new BasicCollectionExpression(expression, NON);
        } else if (nullCollectionExpression.getCollectionScope() == INDEXED_ATTRIBUTE) {
            return new NullCollectionExpression(expression, INDEXED_RESULT_SET, ((AttributeCollectionExpression) nullCollectionExpression).getAttribute());
        } else if (nullCollectionExpression.getCollectionScope() == PRIMARY_KEY_ATTRIBUTE) {
            return new NullCollectionExpression(expression, PRIMARY_KEY_RESULT_SET, ((AttributeCollectionExpression) nullCollectionExpression).getAttribute());
        } else {
            return new BasicCollectionExpression(expression, EXHAUSTIVE);
        }
    }
    throw new UnsupportedOperationException(expression.toString() + " not supported!");
}
Also used : Add(org.wso2.siddhi.query.api.expression.math.Add) Set(java.util.Set) HashSet(java.util.HashSet) Or(org.wso2.siddhi.query.api.expression.condition.Or) Variable(org.wso2.siddhi.query.api.expression.Variable) BasicCollectionExpression(org.wso2.siddhi.core.util.collection.expression.BasicCollectionExpression) In(org.wso2.siddhi.query.api.expression.condition.In) Constant(org.wso2.siddhi.query.api.expression.constant.Constant) AttributeCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AttributeCollectionExpression) Divide(org.wso2.siddhi.query.api.expression.math.Divide) AndCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndCollectionExpression) Multiply(org.wso2.siddhi.query.api.expression.math.Multiply) NullCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NullCollectionExpression) Compare(org.wso2.siddhi.query.api.expression.condition.Compare) NotCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NotCollectionExpression) AndCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndCollectionExpression) BasicCollectionExpression(org.wso2.siddhi.core.util.collection.expression.BasicCollectionExpression) CompareCollectionExpression(org.wso2.siddhi.core.util.collection.expression.CompareCollectionExpression) CollectionExpression(org.wso2.siddhi.core.util.collection.expression.CollectionExpression) OrCollectionExpression(org.wso2.siddhi.core.util.collection.expression.OrCollectionExpression) AttributeCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AttributeCollectionExpression) AndMultiPrimaryKeyCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) NullCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NullCollectionExpression) Mod(org.wso2.siddhi.query.api.expression.math.Mod) AndMultiPrimaryKeyCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) AttributeFunction(org.wso2.siddhi.query.api.expression.AttributeFunction) Not(org.wso2.siddhi.query.api.expression.condition.Not) CompareCollectionExpression(org.wso2.siddhi.core.util.collection.expression.CompareCollectionExpression) NotCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NotCollectionExpression) AndCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndCollectionExpression) BasicCollectionExpression(org.wso2.siddhi.core.util.collection.expression.BasicCollectionExpression) CompareCollectionExpression(org.wso2.siddhi.core.util.collection.expression.CompareCollectionExpression) CollectionExpression(org.wso2.siddhi.core.util.collection.expression.CollectionExpression) OrCollectionExpression(org.wso2.siddhi.core.util.collection.expression.OrCollectionExpression) AttributeCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AttributeCollectionExpression) Expression(org.wso2.siddhi.query.api.expression.Expression) AndMultiPrimaryKeyCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) NullCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NullCollectionExpression) And(org.wso2.siddhi.query.api.expression.condition.And) OrCollectionExpression(org.wso2.siddhi.core.util.collection.expression.OrCollectionExpression) Subtract(org.wso2.siddhi.query.api.expression.math.Subtract) IsNull(org.wso2.siddhi.query.api.expression.condition.IsNull) NotCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NotCollectionExpression)

Example 10 with Add

use of org.wso2.siddhi.query.api.expression.math.Add in project siddhi by wso2.

the class DefinitionParserHelper method validateDefinition.

public static void validateDefinition(AbstractDefinition definition, ConcurrentMap<String, AbstractDefinition> streamDefinitionMap, ConcurrentMap<String, AbstractDefinition> tableDefinitionMap, ConcurrentMap<String, AbstractDefinition> windowDefinitionMap, ConcurrentMap<String, AbstractDefinition> aggregationDefinitionMap) {
    AbstractDefinition existingTableDefinition = tableDefinitionMap.get(definition.getId());
    if (existingTableDefinition != null && (!existingTableDefinition.equals(definition) || definition instanceof StreamDefinition)) {
        throw new DuplicateDefinitionException("Table Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingTableDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingStreamDefinition = streamDefinitionMap.get(definition.getId());
    if (existingStreamDefinition != null && (!existingStreamDefinition.equals(definition) || definition instanceof TableDefinition)) {
        throw new DuplicateDefinitionException("Stream Definition with same Stream Id '" + definition.getId() + "' already exist : " + existingStreamDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingWindowDefinition = windowDefinitionMap.get(definition.getId());
    if (existingWindowDefinition != null && (!existingWindowDefinition.equals(definition) || definition instanceof WindowDefinition)) {
        throw new DuplicateDefinitionException("Window Definition with same Window Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
    AbstractDefinition existingAggregationDefinition = aggregationDefinitionMap.get(definition.getId());
    if (existingAggregationDefinition != null && (!existingAggregationDefinition.equals(definition) || definition instanceof AggregationDefinition)) {
        throw new DuplicateDefinitionException("Aggregation Definition with same Aggregation Id '" + definition.getId() + "' already exist : " + existingWindowDefinition + ", hence cannot add " + definition, definition.getQueryContextStartIndex(), definition.getQueryContextEndIndex());
    }
}
Also used : StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) DuplicateDefinitionException(org.wso2.siddhi.query.api.exception.DuplicateDefinitionException) AggregationDefinition(org.wso2.siddhi.query.api.definition.AggregationDefinition) AbstractDefinition(org.wso2.siddhi.query.api.definition.AbstractDefinition) TableDefinition(org.wso2.siddhi.query.api.definition.TableDefinition) WindowDefinition(org.wso2.siddhi.query.api.definition.WindowDefinition)

Aggregations

Test (org.testng.annotations.Test)134 API (org.wso2.carbon.apimgt.core.models.API)63 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)60 ArrayList (java.util.ArrayList)57 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)55 HashMap (java.util.HashMap)51 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)44 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)43 Application (org.wso2.carbon.apimgt.core.models.Application)37 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)35 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)33 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)30 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)29 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)26 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)26 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)25 APISubscriptionDAO (org.wso2.carbon.apimgt.core.dao.APISubscriptionDAO)23 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)22 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)22 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)22