Search in sources :

Example 31 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class AbstractStreamProcessor method cloneProcessor.

@Override
public Processor cloneProcessor(String key) {
    try {
        AbstractStreamProcessor abstractStreamProcessor = this.getClass().newInstance();
        abstractStreamProcessor.inputDefinition = inputDefinition;
        ExpressionExecutor[] innerExpressionExecutors = new ExpressionExecutor[attributeExpressionLength];
        ExpressionExecutor[] attributeExpressionExecutors1 = this.attributeExpressionExecutors;
        for (int i = 0; i < attributeExpressionLength; i++) {
            innerExpressionExecutors[i] = attributeExpressionExecutors1[i].cloneExecutor(key);
        }
        abstractStreamProcessor.attributeExpressionExecutors = innerExpressionExecutors;
        abstractStreamProcessor.attributeExpressionLength = attributeExpressionLength;
        abstractStreamProcessor.additionalAttributes = additionalAttributes;
        abstractStreamProcessor.complexEventPopulater = complexEventPopulater;
        abstractStreamProcessor.siddhiAppContext = siddhiAppContext;
        abstractStreamProcessor.elementId = elementId + "-" + key;
        abstractStreamProcessor.init(inputDefinition, attributeExpressionExecutors, configReader, siddhiAppContext, outputExpectsExpiredEvents);
        abstractStreamProcessor.start();
        return abstractStreamProcessor;
    } catch (Exception e) {
        throw new SiddhiAppRuntimeException("Exception in cloning " + this.getClass().getCanonicalName(), e);
    }
}
Also used : ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) SiddhiAppRuntimeException(org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) SiddhiAppRuntimeException(org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException)

Example 32 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class SelectorParser method getAttributeProcessors.

/**
 * Method to construct AttributeProcessor list for the selector.
 *
 * @param selector                    Selector
 * @param id                          stream id
 * @param siddhiAppContext            siddhi app context
 * @param metaComplexEvent            meta ComplexEvent
 * @param tableMap                    Table Map
 * @param variableExpressionExecutors list of VariableExpressionExecutors
 * @param outputStream
 * @return list of AttributeProcessors
 */
private static List<AttributeProcessor> getAttributeProcessors(Selector selector, String id, SiddhiAppContext siddhiAppContext, MetaComplexEvent metaComplexEvent, Map<String, Table> tableMap, List<VariableExpressionExecutor> variableExpressionExecutors, OutputStream outputStream, String queryName, int metaPosition) {
    List<AttributeProcessor> attributeProcessorList = new ArrayList<>();
    StreamDefinition outputDefinition = StreamDefinition.id(id);
    outputDefinition.setQueryContextStartIndex(outputStream.getQueryContextStartIndex());
    outputDefinition.setQueryContextEndIndex(outputStream.getQueryContextEndIndex());
    List<OutputAttribute> outputAttributes = selector.getSelectionList();
    if (selector.getSelectionList().size() == 0) {
        if (metaComplexEvent instanceof MetaStreamEvent) {
            List<Attribute> attributeList = ((MetaStreamEvent) metaComplexEvent).getLastInputDefinition().getAttributeList();
            for (Attribute attribute : attributeList) {
                outputAttributes.add(new OutputAttribute(new Variable(attribute.getName())));
            }
        } else {
            int position = 0;
            for (MetaStreamEvent metaStreamEvent : ((MetaStateEvent) metaComplexEvent).getMetaStreamEvents()) {
                if (metaPosition == SiddhiConstants.UNKNOWN_STATE || metaPosition == position) {
                    List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList();
                    for (Attribute attribute : attributeList) {
                        OutputAttribute outputAttribute = new OutputAttribute(new Variable(attribute.getName()));
                        if (!outputAttributes.contains(outputAttribute)) {
                            outputAttributes.add(outputAttribute);
                        } else {
                            List<AbstractDefinition> definitions = new ArrayList<>();
                            for (MetaStreamEvent aMetaStreamEvent : ((MetaStateEvent) metaComplexEvent).getMetaStreamEvents()) {
                                definitions.add(aMetaStreamEvent.getLastInputDefinition());
                            }
                            throw new DuplicateAttributeException("Duplicate attribute exist in streams " + definitions, outputStream.getQueryContextStartIndex(), outputStream.getQueryContextEndIndex());
                        }
                    }
                }
                ++position;
            }
        }
    }
    int i = 0;
    for (OutputAttribute outputAttribute : outputAttributes) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(outputAttribute.getExpression(), metaComplexEvent, SiddhiConstants.UNKNOWN_STATE, tableMap, variableExpressionExecutors, siddhiAppContext, !(selector.getGroupByList().isEmpty()), 0, queryName);
        if (expressionExecutor instanceof VariableExpressionExecutor) {
            // for variables we will directly put
            // value at conversion stage
            VariableExpressionExecutor executor = ((VariableExpressionExecutor) expressionExecutor);
            if (metaComplexEvent instanceof MetaStateEvent) {
                ((MetaStateEvent) metaComplexEvent).addOutputDataAllowingDuplicate(new MetaStateEventAttribute(executor.getAttribute(), executor.getPosition()));
            } else {
                ((MetaStreamEvent) metaComplexEvent).addOutputDataAllowingDuplicate(executor.getAttribute());
            }
            outputDefinition.attribute(outputAttribute.getRename(), ((VariableExpressionExecutor) expressionExecutor).getAttribute().getType());
        } else {
            // To maintain output variable positions
            if (metaComplexEvent instanceof MetaStateEvent) {
                ((MetaStateEvent) metaComplexEvent).addOutputDataAllowingDuplicate(null);
            } else {
                ((MetaStreamEvent) metaComplexEvent).addOutputDataAllowingDuplicate(null);
            }
            AttributeProcessor attributeProcessor = new AttributeProcessor(expressionExecutor);
            attributeProcessor.setOutputPosition(i);
            attributeProcessorList.add(attributeProcessor);
            outputDefinition.attribute(outputAttribute.getRename(), attributeProcessor.getOutputType());
        }
        i++;
    }
    metaComplexEvent.setOutputDefinition(outputDefinition);
    return attributeProcessorList;
}
Also used : Variable(org.ballerinalang.siddhi.query.api.expression.Variable) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute) MetaStateEventAttribute(org.ballerinalang.siddhi.core.event.state.MetaStateEventAttribute) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) AbstractDefinition(org.ballerinalang.siddhi.query.api.definition.AbstractDefinition) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute) DuplicateAttributeException(org.ballerinalang.siddhi.query.api.exception.DuplicateAttributeException) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) MetaStateEventAttribute(org.ballerinalang.siddhi.core.event.state.MetaStateEventAttribute) AttributeProcessor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)

Example 33 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class AggregationParser method populateIncomingAggregatorsAndExecutors.

private static void populateIncomingAggregatorsAndExecutors(AggregationDefinition aggregationDefinition, SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, List<VariableExpressionExecutor> incomingVariableExpressionExecutors, String aggregatorName, MetaStreamEvent incomingMetaStreamEvent, List<ExpressionExecutor> incomingExpressionExecutors, List<IncrementalAttributeAggregator> incrementalAttributeAggregators, List<Variable> groupByVariableList, List<Expression> outputExpressions) {
    ExpressionExecutor[] timeStampTimeZoneExecutors = setTimeStampTimeZoneExecutors(aggregationDefinition, siddhiAppContext, tableMap, incomingVariableExpressionExecutors, aggregatorName, incomingMetaStreamEvent);
    ExpressionExecutor timestampExecutor = timeStampTimeZoneExecutors[0];
    ExpressionExecutor timeZoneExecutor = timeStampTimeZoneExecutors[1];
    Attribute timestampAttribute = new Attribute("AGG_TIMESTAMP", Attribute.Type.LONG);
    incomingMetaStreamEvent.addOutputData(timestampAttribute);
    incomingExpressionExecutors.add(timestampExecutor);
    incomingMetaStreamEvent.addOutputData(new Attribute("AGG_TIMEZONE", Attribute.Type.STRING));
    incomingExpressionExecutors.add(timeZoneExecutor);
    AbstractDefinition incomingLastInputStreamDefinition = incomingMetaStreamEvent.getLastInputDefinition();
    for (Variable groupByVariable : groupByVariableList) {
        incomingMetaStreamEvent.addOutputData(incomingLastInputStreamDefinition.getAttributeList().get(incomingLastInputStreamDefinition.getAttributePosition(groupByVariable.getAttributeName())));
        incomingExpressionExecutors.add(ExpressionParser.parseExpression(groupByVariable, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, siddhiAppContext, false, 0, aggregatorName));
    }
    // Add AGG_TIMESTAMP to output as well
    outputExpressions.add(Expression.variable("AGG_TIMESTAMP"));
    aggregationDefinition.getAttributeList().add(timestampAttribute);
    for (OutputAttribute outputAttribute : aggregationDefinition.getSelector().getSelectionList()) {
        Expression expression = outputAttribute.getExpression();
        if (expression instanceof AttributeFunction) {
            IncrementalAttributeAggregator incrementalAggregator = null;
            try {
                incrementalAggregator = (IncrementalAttributeAggregator) SiddhiClassLoader.loadExtensionImplementation(new AttributeFunction("incrementalAggregator", ((AttributeFunction) expression).getName(), ((AttributeFunction) expression).getParameters()), IncrementalAttributeAggregatorExtensionHolder.getInstance(siddhiAppContext));
            } catch (SiddhiAppCreationException ex) {
                try {
                    SiddhiClassLoader.loadExtensionImplementation((AttributeFunction) expression, FunctionExecutorExtensionHolder.getInstance(siddhiAppContext));
                    ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, siddhiAppContext, false, 0, aggregatorName);
                    incomingExpressionExecutors.add(expressionExecutor);
                    incomingMetaStreamEvent.addOutputData(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
                    aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
                    outputExpressions.add(Expression.variable(outputAttribute.getRename()));
                } catch (SiddhiAppCreationException e) {
                    throw new SiddhiAppCreationException("'" + ((AttributeFunction) expression).getName() + "' is neither a incremental attribute aggregator extension or a function" + " extension", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
                }
            }
            if (incrementalAggregator != null) {
                initIncrementalAttributeAggregator(incomingLastInputStreamDefinition, (AttributeFunction) expression, incrementalAggregator);
                incrementalAttributeAggregators.add(incrementalAggregator);
                aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), incrementalAggregator.getReturnType()));
                outputExpressions.add(incrementalAggregator.aggregate());
            }
        } else {
            if (expression instanceof Variable && groupByVariableList.contains(expression)) {
                Attribute groupByAttribute = null;
                for (Attribute attribute : incomingMetaStreamEvent.getOutputData()) {
                    if (attribute.getName().equals(((Variable) expression).getAttributeName())) {
                        groupByAttribute = attribute;
                        break;
                    }
                }
                if (groupByAttribute == null) {
                    throw new SiddhiAppCreationException("Expected GroupBy attribute '" + ((Variable) expression).getAttributeName() + "' not used in aggregation '" + aggregatorName + "' processing.", expression.getQueryContextStartIndex(), expression.getQueryContextEndIndex());
                }
                aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), groupByAttribute.getType()));
                outputExpressions.add(Expression.variable(groupByAttribute.getName()));
            } else {
                ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, incomingMetaStreamEvent, 0, tableMap, incomingVariableExpressionExecutors, siddhiAppContext, false, 0, aggregatorName);
                incomingExpressionExecutors.add(expressionExecutor);
                incomingMetaStreamEvent.addOutputData(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
                aggregationDefinition.getAttributeList().add(new Attribute(outputAttribute.getRename(), expressionExecutor.getReturnType()));
                outputExpressions.add(Expression.variable(outputAttribute.getRename()));
            }
        }
    }
}
Also used : Variable(org.ballerinalang.siddhi.query.api.expression.Variable) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) SiddhiAppCreationException(org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException) IncrementalAttributeAggregator(org.ballerinalang.siddhi.core.query.selector.attribute.aggregator.incremental.IncrementalAttributeAggregator) AbstractDefinition(org.ballerinalang.siddhi.query.api.definition.AbstractDefinition) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute) AttributeFunction(org.ballerinalang.siddhi.query.api.expression.AttributeFunction)

Example 34 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

the class AggregationParser method constructProcessExpressionExecutors.

private static List<ExpressionExecutor> constructProcessExpressionExecutors(SiddhiAppContext siddhiAppContext, Map<String, Table> tableMap, String aggregatorName, int baseAggregatorBeginIndex, List<Expression> finalBaseAggregators, StreamDefinition incomingOutputStreamDefinition, MetaStreamEvent processedMetaStreamEvent, List<VariableExpressionExecutor> processVariableExpressionExecutors, boolean groupBy) {
    List<ExpressionExecutor> processExpressionExecutors = new ArrayList<>();
    List<Attribute> attributeList = incomingOutputStreamDefinition.getAttributeList();
    for (int i = 0; i < baseAggregatorBeginIndex; i++) {
        Attribute attribute = attributeList.get(i);
        VariableExpressionExecutor variableExpressionExecutor = (VariableExpressionExecutor) ExpressionParser.parseExpression(new Variable(attribute.getName()), processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, siddhiAppContext, groupBy, 0, aggregatorName);
        processExpressionExecutors.add(variableExpressionExecutor);
    }
    for (Expression expression : finalBaseAggregators) {
        ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, siddhiAppContext, groupBy, 0, aggregatorName);
        processExpressionExecutors.add(expressionExecutor);
    }
    return processExpressionExecutors;
}
Also used : Variable(org.ballerinalang.siddhi.query.api.expression.Variable) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) OutputAttribute(org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList)

Example 35 with ExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.ExpressionExecutor in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.query.api.definition.Attribute) AttributeCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AttributeCollectionExpression) CompareCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.CompareCollectionExecutor) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) CompareExhaustiveAndCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.CompareExhaustiveAndCollectionExecutor) AndCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AndCollectionExpression) NullCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.NullCollectionExpression) List(java.util.List) ArrayList(java.util.ArrayList) OrCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.OrCollectionExpression) CompareCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.CompareCollectionExpression) NullCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.NullCollectionExpression) BasicCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.BasicCollectionExpression) CollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.CollectionExpression) AttributeCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AttributeCollectionExpression) NotCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.NotCollectionExpression) AndMultiPrimaryKeyCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) AndCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AndCollectionExpression) NonCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.NonCollectionExecutor) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) ExhaustiveCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.ExhaustiveCollectionExecutor) NotCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.NotCollectionExecutor) AndMultiPrimaryKeyCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.AndMultiPrimaryKeyCollectionExpression) AndMultiPrimaryKeyCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.AndMultiPrimaryKeyCollectionExecutor) OrCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.OrCollectionExecutor) NonAndCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.NonAndCollectionExecutor) CompareCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.CompareCollectionExpression) OrCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.OrCollectionExpression) NonAndCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.NonAndCollectionExecutor) NotCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.NotCollectionExecutor) NonCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.NonCollectionExecutor) CompareExhaustiveAndCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.CompareExhaustiveAndCollectionExecutor) CompareCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.CompareCollectionExecutor) AnyAndCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.AnyAndCollectionExecutor) CollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.CollectionExecutor) ExhaustiveCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.ExhaustiveCollectionExecutor) OrCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.OrCollectionExecutor) AndMultiPrimaryKeyCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.AndMultiPrimaryKeyCollectionExecutor) Map(java.util.Map) HashMap(java.util.HashMap) AnyAndCollectionExecutor(org.ballerinalang.siddhi.core.util.collection.executor.AnyAndCollectionExecutor) NotCollectionExpression(org.ballerinalang.siddhi.core.util.collection.expression.NotCollectionExpression)

Aggregations

ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)46 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)33 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)15 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)14 Map (java.util.Map)13 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)13 HashMap (java.util.HashMap)11 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)11 ArrayList (java.util.ArrayList)10 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)10 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)10 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)8 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)7 SiddhiAppRuntimeException (org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException)7 Expression (org.ballerinalang.siddhi.query.api.expression.Expression)7 AndConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor)5 AbstractDefinition (org.ballerinalang.siddhi.query.api.definition.AbstractDefinition)5 OutputAttribute (org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute)5 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)4 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)4