Search in sources :

Example 6 with ConstantExpressionExecutor

use of org.wso2.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.

the class CollectionExpressionParser method buildCollectionExecutor.

public static CollectionExecutor buildCollectionExecutor(CollectionExpression collectionExpression, MatchingMetaInfoHolder matchingMetaInfoHolder, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, SiddhiAppContext siddhiAppContext, boolean isFirst, String queryName) {
    if (collectionExpression instanceof AttributeCollectionExpression) {
        ExpressionExecutor expressionExecutor = null;
        if (isFirst) {
            expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        }
        return new CompareCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex(), ((AttributeCollectionExpression) collectionExpression).getAttribute(), Compare.Operator.EQUAL, new ConstantExpressionExecutor(true, Attribute.Type.BOOL));
    } else if (collectionExpression instanceof CompareCollectionExpression) {
        ExpressionExecutor valueExpressionExecutor = ExpressionParser.parseExpression(((CompareCollectionExpression) collectionExpression).getValueCollectionExpression().getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        AttributeCollectionExpression attributeCollectionExpression = ((AttributeCollectionExpression) ((CompareCollectionExpression) collectionExpression).getAttributeCollectionExpression());
        ExpressionExecutor expressionExecutor = null;
        if (isFirst) {
            expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        }
        return new CompareCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex(), attributeCollectionExpression.getAttribute(), ((CompareCollectionExpression) collectionExpression).getOperator(), valueExpressionExecutor);
    } else if (collectionExpression instanceof NullCollectionExpression) {
        ExpressionExecutor expressionExecutor = null;
        if (isFirst) {
            expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
        }
        return new CompareCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex(), ((NullCollectionExpression) collectionExpression).getAttribute(), Compare.Operator.EQUAL, new ConstantExpressionExecutor(null, Attribute.Type.OBJECT));
    } else if (collectionExpression instanceof AndMultiPrimaryKeyCollectionExpression) {
        Map<String, ExpressionExecutor> multiPrimaryKeyExpressionExecutors = buildMultiPrimaryKeyExpressionExecutors(collectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, queryName);
        List<Attribute> attributes = matchingMetaInfoHolder.getStoreDefinition().getAttributeList();
        StringBuilder compositePrimaryKey = new StringBuilder();
        List<ExpressionExecutor> sortedExecutors = new ArrayList<ExpressionExecutor>();
        for (Attribute attribute : attributes) {
            ExpressionExecutor expressionExecutor = multiPrimaryKeyExpressionExecutors.get(attribute.getName());
            if (expressionExecutor != null) {
                sortedExecutors.add(expressionExecutor);
                compositePrimaryKey.append(attribute.getName()).append(SiddhiConstants.KEY_DELIMITER);
            }
        }
        return new AndMultiPrimaryKeyCollectionExecutor(compositePrimaryKey.toString(), sortedExecutors);
    } else if (collectionExpression instanceof AndCollectionExpression) {
        CollectionExpression leftCollectionExpression = ((AndCollectionExpression) collectionExpression).getLeftCollectionExpression();
        CollectionExpression rightCollectionExpression = ((AndCollectionExpression) collectionExpression).getRightCollectionExpression();
        ExpressionExecutor expressionExecutor = null;
        CollectionExecutor aCollectionExecutor = null;
        ExhaustiveCollectionExecutor exhaustiveCollectionExecutor = null;
        CollectionExecutor leftCollectionExecutor;
        CollectionExecutor rightCollectionExecutor;
        switch(leftCollectionExpression.getCollectionScope()) {
            case NON:
                switch(rightCollectionExpression.getCollectionScope()) {
                    case NON:
                        expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                        return new NonCollectionExecutor(expressionExecutor);
                    case INDEXED_ATTRIBUTE:
                    case INDEXED_RESULT_SET:
                    case PRIMARY_KEY_ATTRIBUTE:
                    case PRIMARY_KEY_RESULT_SET:
                    case PARTIAL_PRIMARY_KEY_RESULT_SET:
                    case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
                    case EXHAUSTIVE:
                        expressionExecutor = ExpressionParser.parseExpression(leftCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                        aCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
                        return new NonAndCollectionExecutor(expressionExecutor, aCollectionExecutor, rightCollectionExpression.getCollectionScope());
                }
                break;
            case INDEXED_ATTRIBUTE:
            case PRIMARY_KEY_ATTRIBUTE:
                switch(rightCollectionExpression.getCollectionScope()) {
                    case NON:
                        expressionExecutor = ExpressionParser.parseExpression(rightCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                        aCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
                        return new NonAndCollectionExecutor(expressionExecutor, aCollectionExecutor, rightCollectionExpression.getCollectionScope());
                    case INDEXED_ATTRIBUTE:
                    case INDEXED_RESULT_SET:
                    case PRIMARY_KEY_ATTRIBUTE:
                    case PRIMARY_KEY_RESULT_SET:
                    case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
                        exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
                        leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
                        rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
                        return new AnyAndCollectionExecutor(leftCollectionExecutor, rightCollectionExecutor, exhaustiveCollectionExecutor);
                    case PARTIAL_PRIMARY_KEY_RESULT_SET:
                    case EXHAUSTIVE:
                        leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
                        if (isFirst || leftCollectionExecutor.getDefaultCost() == CollectionExecutor.Cost.SINGLE_RETURN_INDEX_MATCHING) {
                            exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
                        }
                        return new CompareExhaustiveAndCollectionExecutor(leftCollectionExecutor, exhaustiveCollectionExecutor);
                }
                break;
            case INDEXED_RESULT_SET:
            case PRIMARY_KEY_RESULT_SET:
            case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
                switch(rightCollectionExpression.getCollectionScope()) {
                    case NON:
                        expressionExecutor = ExpressionParser.parseExpression(rightCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                        aCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
                        return new NonAndCollectionExecutor(expressionExecutor, aCollectionExecutor, rightCollectionExpression.getCollectionScope());
                    case INDEXED_ATTRIBUTE:
                    case PRIMARY_KEY_ATTRIBUTE:
                        exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
                        leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
                        rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
                        return new AnyAndCollectionExecutor(rightCollectionExecutor, leftCollectionExecutor, exhaustiveCollectionExecutor);
                    case INDEXED_RESULT_SET:
                    case PRIMARY_KEY_RESULT_SET:
                    case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
                        exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
                        leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
                        rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, false, queryName);
                        return new AnyAndCollectionExecutor(leftCollectionExecutor, rightCollectionExecutor, exhaustiveCollectionExecutor);
                    case PARTIAL_PRIMARY_KEY_RESULT_SET:
                    case EXHAUSTIVE:
                        leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
                        if (isFirst || leftCollectionExecutor.getDefaultCost() == CollectionExecutor.Cost.SINGLE_RETURN_INDEX_MATCHING) {
                            exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
                        }
                        return new CompareExhaustiveAndCollectionExecutor(leftCollectionExecutor, exhaustiveCollectionExecutor);
                }
                break;
            case PARTIAL_PRIMARY_KEY_RESULT_SET:
            case EXHAUSTIVE:
                switch(rightCollectionExpression.getCollectionScope()) {
                    case NON:
                        expressionExecutor = ExpressionParser.parseExpression(rightCollectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                        aCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
                        return new NonAndCollectionExecutor(expressionExecutor, aCollectionExecutor, rightCollectionExpression.getCollectionScope());
                    case INDEXED_ATTRIBUTE:
                    case INDEXED_RESULT_SET:
                    case PRIMARY_KEY_ATTRIBUTE:
                    case PRIMARY_KEY_RESULT_SET:
                    case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
                        rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
                        if (isFirst || rightCollectionExecutor.getDefaultCost() == CollectionExecutor.Cost.SINGLE_RETURN_INDEX_MATCHING) {
                            exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
                        }
                        return new CompareExhaustiveAndCollectionExecutor(rightCollectionExecutor, exhaustiveCollectionExecutor);
                    case PARTIAL_PRIMARY_KEY_RESULT_SET:
                    case EXHAUSTIVE:
                        if (isFirst) {
                            expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                        }
                        return new ExhaustiveCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
                }
                break;
        }
    } else if (collectionExpression instanceof OrCollectionExpression) {
        CollectionExpression leftCollectionExpression = ((OrCollectionExpression) collectionExpression).getLeftCollectionExpression();
        CollectionExpression rightCollectionExpression = ((OrCollectionExpression) collectionExpression).getRightCollectionExpression();
        ExpressionExecutor expressionExecutor = null;
        CollectionExecutor aCollectionExecutor = null;
        CollectionExecutor leftCollectionExecutor;
        CollectionExecutor rightCollectionExecutor;
        if (leftCollectionExpression.getCollectionScope() == NON && rightCollectionExpression.getCollectionScope() == NON) {
            expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
            return new NonCollectionExecutor(expressionExecutor);
        } else if ((leftCollectionExpression.getCollectionScope() == EXHAUSTIVE && leftCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET) || (rightCollectionExpression.getCollectionScope() == EXHAUSTIVE && rightCollectionExpression.getCollectionScope() == PARTIAL_PRIMARY_KEY_RESULT_SET)) {
            if (isFirst) {
                expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
            }
            return new ExhaustiveCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
        } else {
            if (isFirst) {
                aCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
            }
            leftCollectionExecutor = buildCollectionExecutor(leftCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
            rightCollectionExecutor = buildCollectionExecutor(rightCollectionExpression, matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
            return new OrCollectionExecutor(leftCollectionExecutor, rightCollectionExecutor, aCollectionExecutor);
        }
    } else if (collectionExpression instanceof NotCollectionExpression) {
        ExpressionExecutor expressionExecutor = null;
        switch(collectionExpression.getCollectionScope()) {
            case NON:
                expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                return new NonCollectionExecutor(expressionExecutor);
            case INDEXED_ATTRIBUTE:
            case INDEXED_RESULT_SET:
            case PRIMARY_KEY_ATTRIBUTE:
            case PRIMARY_KEY_RESULT_SET:
            case OPTIMISED_PRIMARY_KEY_OR_INDEXED_RESULT_SET:
                ExhaustiveCollectionExecutor exhaustiveCollectionExecutor = null;
                if (isFirst) {
                    exhaustiveCollectionExecutor = new ExhaustiveCollectionExecutor(ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName), matchingMetaInfoHolder.getStoreEventIndex());
                }
                CollectionExecutor notCollectionExecutor = buildCollectionExecutor(((NotCollectionExpression) collectionExpression).getCollectionExpression(), matchingMetaInfoHolder, variableExpressionExecutors, tableMap, siddhiAppContext, isFirst, queryName);
                return new NotCollectionExecutor(notCollectionExecutor, exhaustiveCollectionExecutor);
            case PARTIAL_PRIMARY_KEY_RESULT_SET:
            case EXHAUSTIVE:
                if (isFirst) {
                    expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
                }
                return new ExhaustiveCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
        }
    } else {
        // Basic
        ExpressionExecutor expressionExecutor = null;
        if (collectionExpression.getCollectionScope() == NON) {
            expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
            return new NonCollectionExecutor(expressionExecutor);
        } else {
            // EXHAUSTIVE
            if (isFirst) {
                expressionExecutor = ExpressionParser.parseExpression(collectionExpression.getExpression(), matchingMetaInfoHolder.getMetaStateEvent(), matchingMetaInfoHolder.getCurrentState(), tableMap, variableExpressionExecutors, siddhiAppContext, false, 0, queryName);
            }
            return new ExhaustiveCollectionExecutor(expressionExecutor, matchingMetaInfoHolder.getStoreEventIndex());
        }
    }
    throw new UnsupportedOperationException(collectionExpression.getClass().getName() + " not supported!");
}
Also used : Attribute(org.wso2.siddhi.query.api.definition.Attribute) AttributeCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AttributeCollectionExpression) CompareCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.CompareCollectionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) CompareExhaustiveAndCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.CompareExhaustiveAndCollectionExecutor) AndCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndCollectionExpression) NullCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NullCollectionExpression) List(java.util.List) ArrayList(java.util.ArrayList) 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) NonCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.NonCollectionExecutor) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ExhaustiveCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.ExhaustiveCollectionExecutor) NotCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.NotCollectionExecutor) AndMultiPrimaryKeyCollectionExpression(org.wso2.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) AndMultiPrimaryKeyCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.AndMultiPrimaryKeyCollectionExecutor) OrCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.OrCollectionExecutor) NonAndCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.NonAndCollectionExecutor) CompareCollectionExpression(org.wso2.siddhi.core.util.collection.expression.CompareCollectionExpression) OrCollectionExpression(org.wso2.siddhi.core.util.collection.expression.OrCollectionExpression) ExhaustiveCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.ExhaustiveCollectionExecutor) OrCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.OrCollectionExecutor) AndMultiPrimaryKeyCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.AndMultiPrimaryKeyCollectionExecutor) NonAndCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.NonAndCollectionExecutor) CompareExhaustiveAndCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.CompareExhaustiveAndCollectionExecutor) CollectionExecutor(org.wso2.siddhi.core.util.collection.executor.CollectionExecutor) NotCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.NotCollectionExecutor) NonCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.NonCollectionExecutor) CompareCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.CompareCollectionExecutor) AnyAndCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.AnyAndCollectionExecutor) Map(java.util.Map) HashMap(java.util.HashMap) AnyAndCollectionExecutor(org.wso2.siddhi.core.util.collection.executor.AnyAndCollectionExecutor) NotCollectionExpression(org.wso2.siddhi.core.util.collection.expression.NotCollectionExpression)

Example 7 with ConstantExpressionExecutor

use of org.wso2.siddhi.core.executor.ConstantExpressionExecutor 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");
    }
}
Also used : OperationNotSupportedException(org.wso2.siddhi.core.exception.OperationNotSupportedException) LengthWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.LengthWindowProcessor) FindableProcessor(org.wso2.siddhi.core.query.processor.stream.window.FindableProcessor) FindableProcessor(org.wso2.siddhi.core.query.processor.stream.window.FindableProcessor) WindowWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.WindowWindowProcessor) AggregateWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.AggregateWindowProcessor) TableWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.TableWindowProcessor) Processor(org.wso2.siddhi.core.query.processor.Processor) WindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor) LengthWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.LengthWindowProcessor) JoinProcessor(org.wso2.siddhi.core.query.input.stream.join.JoinProcessor) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) ConfigReader(org.wso2.siddhi.core.util.config.ConfigReader) WindowWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.WindowWindowProcessor) AggregateWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.AggregateWindowProcessor) TableWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.TableWindowProcessor) WindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.WindowProcessor) LengthWindowProcessor(org.wso2.siddhi.core.query.processor.stream.window.LengthWindowProcessor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Example 8 with ConstantExpressionExecutor

use of org.wso2.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.

the class EventTestCase method testConditionExpressionExecutors.

@Test
public void testConditionExpressionExecutors() {
    // StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
    // .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("price", Attribute.Type.FLOAT), 0, 0);
    priceVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 1 });
    VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("volume", Attribute.Type.INT), 0, 0);
    volumeVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 2 });
    ExpressionExecutor compareLessThanExecutor = new LessThanCompareConditionExpressionExecutorFloatFloat(new ConstantExpressionExecutor(10f, Attribute.Type.FLOAT), priceVariableExpressionExecutor);
    ExpressionExecutor compareGreaterThanExecutor = new GreaterThanCompareConditionExpressionExecutorIntInt(new ConstantExpressionExecutor(10, Attribute.Type.INT), volumeVariableExpressionExecutor);
    ExpressionExecutor andExecutor = new AndConditionExpressionExecutor(compareLessThanExecutor, compareGreaterThanExecutor);
    int count = 0;
    for (int i = 0; i < 3; i++) {
        StreamEvent event = new StreamEvent(0, 0, 3);
        event.setOutputData(new Object[] { "WSO2", i * 11f, 5 });
        if ((Boolean) andExecutor.execute(event)) {
            count++;
        }
    }
    AssertJUnit.assertEquals("Two events should pass through executor", 2, count);
}
Also used : LessThanCompareConditionExpressionExecutorFloatFloat(org.wso2.siddhi.core.executor.condition.compare.lessthan.LessThanCompareConditionExpressionExecutorFloatFloat) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) AndConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) Attribute(org.wso2.siddhi.query.api.definition.Attribute) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) GreaterThanCompareConditionExpressionExecutorIntInt(org.wso2.siddhi.core.executor.condition.compare.greaterthan.GreaterThanCompareConditionExpressionExecutorIntInt) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) AndConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor) Test(org.testng.annotations.Test)

Example 9 with ConstantExpressionExecutor

use of org.wso2.siddhi.core.executor.ConstantExpressionExecutor in project siddhi by wso2.

the class EventTestCase method testConditionExpressionExecutorValidation.

@Test(expectedExceptions = OperationNotSupportedException.class)
public void testConditionExpressionExecutorValidation() {
    // StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute
    // .Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("volume", Attribute.Type.INT), 0, 0);
    volumeVariableExpressionExecutor.setPosition(new int[] { 0, SiddhiConstants.UNKNOWN_STATE, SiddhiConstants.OUTPUT_DATA_INDEX, 2 });
    ConstantExpressionExecutor constantExpressionExecutor = new ConstantExpressionExecutor(10f, Attribute.Type.FLOAT);
    ExpressionExecutor compareGreaterThanExecutor = new GreaterThanCompareConditionExpressionExecutorIntInt(new ConstantExpressionExecutor(10, Attribute.Type.INT), volumeVariableExpressionExecutor);
    ExpressionExecutor andExecutor = new AndConditionExpressionExecutor(constantExpressionExecutor, compareGreaterThanExecutor);
}
Also used : VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) AndConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) Attribute(org.wso2.siddhi.query.api.definition.Attribute) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) GreaterThanCompareConditionExpressionExecutorIntInt(org.wso2.siddhi.core.executor.condition.compare.greaterthan.GreaterThanCompareConditionExpressionExecutorIntInt) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) AndConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor) Test(org.testng.annotations.Test)

Example 10 with ConstantExpressionExecutor

use of org.wso2.siddhi.core.executor.ConstantExpressionExecutor in project carbon-apimgt by wso2.

the class ThrottleStreamProcessor method init.

@Override
protected List<Attribute> init(AbstractDefinition abstractDefinition, ExpressionExecutor[] expressionExecutors, ConfigReader configReader, SiddhiAppContext siddhiAppContext) {
    this.siddhiAppContext = siddhiAppContext;
    if (attributeExpressionExecutors.length == 1) {
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
                timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else {
                throw new SiddhiAppValidationException("Throttle batch window's 1st parameter attribute should be " + "either int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("Throttle batch window 1st parameter needs to be constant " + "parameter attribute but found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
    } else if (attributeExpressionExecutors.length == 2) {
        if (attributeExpressionExecutors[0] instanceof ConstantExpressionExecutor) {
            if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.INT) {
                timeInMilliSeconds = (Integer) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else if (attributeExpressionExecutors[0].getReturnType() == Attribute.Type.LONG) {
                timeInMilliSeconds = (Long) ((ConstantExpressionExecutor) attributeExpressionExecutors[0]).getValue();
            } else {
                throw new SiddhiAppValidationException("Throttle batch window's 1st parameter attribute should be " + "either int or long, but found " + attributeExpressionExecutors[0].getReturnType());
            }
        } else {
            throw new SiddhiAppValidationException("Throttle batch window 1st parameter needs to be constant " + "attribute but found a dynamic attribute " + attributeExpressionExecutors[0].getClass().getCanonicalName());
        }
        if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.INT) {
            startTime = Integer.parseInt(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        } else if (attributeExpressionExecutors[1].getReturnType() == Attribute.Type.LONG) {
            startTime = Long.parseLong(String.valueOf(((ConstantExpressionExecutor) attributeExpressionExecutors[1]).getValue()));
        } else {
            throw new SiddhiAppValidationException("Throttle batch window 2nd parameter needs to be a Long " + "or Int type but found a " + attributeExpressionExecutors[2].getReturnType());
        }
    } else {
        throw new SiddhiAppValidationException("Throttle batch window should only have one/two parameter " + "(<int|long|time> windowTime (and <int|long> startTime), but found " + attributeExpressionExecutors.length + " input attributes");
    }
    List<Attribute> attributeList = new ArrayList<Attribute>();
    attributeList.add(new Attribute(EXPIRY_TIME_STAMP, Attribute.Type.LONG));
    return attributeList;
}
Also used : Attribute(org.wso2.siddhi.query.api.definition.Attribute) ArrayList(java.util.ArrayList) SiddhiAppValidationException(org.wso2.siddhi.query.api.exception.SiddhiAppValidationException) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor)

Aggregations

ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)16 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)10 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)9 Attribute (org.wso2.siddhi.query.api.definition.Attribute)7 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)7 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)6 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)5 ArrayList (java.util.ArrayList)4 AndConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor)4 Test (org.testng.annotations.Test)3 HashMap (java.util.HashMap)2 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)2 ConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor)2 GreaterThanCompareConditionExpressionExecutorIntInt (org.wso2.siddhi.core.executor.condition.compare.greaterthan.GreaterThanCompareConditionExpressionExecutorIntInt)2 AddExpressionExecutorFloat (org.wso2.siddhi.core.executor.math.add.AddExpressionExecutorFloat)2 List (java.util.List)1 Map (java.util.Map)1 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)1 StateEvent (org.wso2.siddhi.core.event.state.StateEvent)1 OperationNotSupportedException (org.wso2.siddhi.core.exception.OperationNotSupportedException)1