Search in sources :

Example 26 with VariableExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor 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 27 with VariableExpressionExecutor

use of org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor 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)

Example 28 with VariableExpressionExecutor

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

the class ExpressionParser method parseInnerExpression.

/**
 * Parse the set of inner expression of AttributeFunctionExtensions and handling all (*) cases.
 *
 * @param innerExpressions        InnerExpressions to be parsed
 * @param metaEvent               Meta Event
 * @param currentState            Current state number
 * @param tableMap                Event Table Map
 * @param executorList            List to hold VariableExpressionExecutors to update after query parsing @return
 * @param siddhiAppContext        SiddhiAppContext
 * @param groupBy                 is for groupBy expression
 * @param defaultStreamEventIndex Default StreamEvent Index
 * @return List of expressionExecutors
 */
private static ExpressionExecutor[] parseInnerExpression(Expression[] innerExpressions, MetaComplexEvent metaEvent, int currentState, Map<String, Table> tableMap, List<VariableExpressionExecutor> executorList, SiddhiAppContext siddhiAppContext, boolean groupBy, int defaultStreamEventIndex, String queryName) {
    ExpressionExecutor[] innerExpressionExecutors;
    if (innerExpressions != null) {
        if (innerExpressions.length > 0) {
            innerExpressionExecutors = new ExpressionExecutor[innerExpressions.length];
            for (int i = 0, innerExpressionsLength = innerExpressions.length; i < innerExpressionsLength; i++) {
                innerExpressionExecutors[i] = parseExpression(innerExpressions[i], metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            }
        } else {
            List<Expression> outputAttributes = new ArrayList<Expression>();
            if (metaEvent instanceof MetaStreamEvent) {
                List<Attribute> attributeList = ((MetaStreamEvent) metaEvent).getLastInputDefinition().getAttributeList();
                for (Attribute attribute : attributeList) {
                    outputAttributes.add(new Variable(attribute.getName()));
                }
            } else {
                for (MetaStreamEvent metaStreamEvent : ((MetaStateEvent) metaEvent).getMetaStreamEvents()) {
                    List<Attribute> attributeList = metaStreamEvent.getLastInputDefinition().getAttributeList();
                    for (Attribute attribute : attributeList) {
                        Expression outputAttribute = new Variable(attribute.getName());
                        if (!outputAttributes.contains(outputAttribute)) {
                            outputAttributes.add(outputAttribute);
                        } else {
                            List<AbstractDefinition> definitions = new ArrayList<AbstractDefinition>();
                            for (MetaStreamEvent aMetaStreamEvent : ((MetaStateEvent) metaEvent).getMetaStreamEvents()) {
                                definitions.add(aMetaStreamEvent.getLastInputDefinition());
                            }
                            throw new DuplicateAttributeException("Duplicate attribute exist in streams " + definitions, attribute.getQueryContextStartIndex(), attribute.getQueryContextEndIndex());
                        }
                    }
                }
            }
            innerExpressionExecutors = new ExpressionExecutor[outputAttributes.size()];
            for (int i = 0, innerExpressionsLength = outputAttributes.size(); i < innerExpressionsLength; i++) {
                innerExpressionExecutors[i] = parseExpression(outputAttributes.get(i), metaEvent, currentState, tableMap, executorList, siddhiAppContext, groupBy, defaultStreamEventIndex, queryName);
            }
        }
    } else {
        innerExpressionExecutors = new ExpressionExecutor[0];
    }
    return innerExpressionExecutors;
}
Also used : Variable(org.ballerinalang.siddhi.query.api.expression.Variable) InConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.InConditionExpressionExecutor) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) NotConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.NotConditionExpressionExecutor) ConstantExpressionExecutor(org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor) BoolConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.BoolConditionExpressionExecutor) IsNullStreamConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.IsNullStreamConditionExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) OrConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.OrConditionExpressionExecutor) AndConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor) IsNullConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.IsNullConditionExpressionExecutor) ConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) ArrayList(java.util.ArrayList) AbstractDefinition(org.ballerinalang.siddhi.query.api.definition.AbstractDefinition) DuplicateAttributeException(org.ballerinalang.siddhi.query.api.exception.DuplicateAttributeException) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) Expression(org.ballerinalang.siddhi.query.api.expression.Expression) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)

Example 29 with VariableExpressionExecutor

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

the class AbstractRecordTable method compileCondition.

@Override
public CompiledCondition compileCondition(Expression condition, MatchingMetaInfoHolder matchingMetaInfoHolder, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) {
    ExpressionBuilder expressionBuilder = new ExpressionBuilder(condition, matchingMetaInfoHolder, siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
    CompiledCondition compileCondition = compileCondition(expressionBuilder);
    Map<String, ExpressionExecutor> expressionExecutorMap = expressionBuilder.getVariableExpressionExecutorMap();
    return new RecordStoreCompiledCondition(expressionExecutorMap, compileCondition);
}
Also used : CompiledCondition(org.ballerinalang.siddhi.core.util.collection.operator.CompiledCondition) ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)

Example 30 with VariableExpressionExecutor

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

the class AbstractRecordTable method compileUpdateSet.

public CompiledUpdateSet compileUpdateSet(UpdateSet updateSet, MatchingMetaInfoHolder matchingMetaInfoHolder, SiddhiAppContext siddhiAppContext, List<VariableExpressionExecutor> variableExpressionExecutors, Map<String, Table> tableMap, String queryName) {
    RecordTableCompiledUpdateSet recordTableCompiledUpdateSet = new RecordTableCompiledUpdateSet();
    Map<String, ExpressionExecutor> parentExecutorMap = new HashMap<>();
    for (UpdateSet.SetAttribute setAttribute : updateSet.getSetAttributeList()) {
        ExpressionBuilder expressionBuilder = new ExpressionBuilder(setAttribute.getAssignmentExpression(), matchingMetaInfoHolder, siddhiAppContext, variableExpressionExecutors, tableMap, queryName);
        CompiledExpression compiledExpression = compileSetAttribute(expressionBuilder);
        recordTableCompiledUpdateSet.put(setAttribute.getTableVariable().getAttributeName(), compiledExpression);
        Map<String, ExpressionExecutor> expressionExecutorMap = expressionBuilder.getVariableExpressionExecutorMap();
        parentExecutorMap.putAll(expressionExecutorMap);
    }
    recordTableCompiledUpdateSet.setExpressionExecutorMap(parentExecutorMap);
    return recordTableCompiledUpdateSet;
}
Also used : ExpressionExecutor(org.ballerinalang.siddhi.core.executor.ExpressionExecutor) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) HashMap(java.util.HashMap) UpdateSet(org.ballerinalang.siddhi.query.api.execution.query.output.stream.UpdateSet) CompiledUpdateSet(org.ballerinalang.siddhi.core.table.CompiledUpdateSet) CompiledExpression(org.ballerinalang.siddhi.core.util.collection.operator.CompiledExpression)

Aggregations

VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)32 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)23 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)15 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)15 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)13 ArrayList (java.util.ArrayList)10 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)10 Expression (org.ballerinalang.siddhi.query.api.expression.Expression)9 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)8 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)8 AbstractDefinition (org.ballerinalang.siddhi.query.api.definition.AbstractDefinition)7 HashMap (java.util.HashMap)6 AndConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.AndConditionExpressionExecutor)5 OutputAttribute (org.ballerinalang.siddhi.query.api.execution.query.selection.OutputAttribute)5 Map (java.util.Map)4 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)4 Table (org.ballerinalang.siddhi.core.table.Table)4 Test (org.testng.annotations.Test)4 AggregationRuntime (org.ballerinalang.siddhi.core.aggregation.AggregationRuntime)3 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)3