Search in sources :

Example 1 with DuplicateAttributeException

use of org.wso2.siddhi.query.api.exception.DuplicateAttributeException in project siddhi by wso2.

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.wso2.siddhi.query.api.expression.Variable) AndConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor) InConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.InConditionExpressionExecutor) IsNullStreamConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.IsNullStreamConditionExpressionExecutor) NotConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.NotConditionExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) BoolConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.BoolConditionExpressionExecutor) ConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) OrConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.OrConditionExpressionExecutor) IsNullConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.IsNullConditionExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) Attribute(org.wso2.siddhi.query.api.definition.Attribute) ArrayList(java.util.ArrayList) AbstractDefinition(org.wso2.siddhi.query.api.definition.AbstractDefinition) DuplicateAttributeException(org.wso2.siddhi.query.api.exception.DuplicateAttributeException) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) Expression(org.wso2.siddhi.query.api.expression.Expression) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 2 with DuplicateAttributeException

use of org.wso2.siddhi.query.api.exception.DuplicateAttributeException in project siddhi by wso2.

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.wso2.siddhi.query.api.expression.Variable) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) ConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ExpressionExecutor(org.wso2.siddhi.core.executor.ExpressionExecutor) ConstantExpressionExecutor(org.wso2.siddhi.core.executor.ConstantExpressionExecutor) Attribute(org.wso2.siddhi.query.api.definition.Attribute) MetaStateEventAttribute(org.wso2.siddhi.core.event.state.MetaStateEventAttribute) OutputAttribute(org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) ArrayList(java.util.ArrayList) AbstractDefinition(org.wso2.siddhi.query.api.definition.AbstractDefinition) OutputAttribute(org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute) DuplicateAttributeException(org.wso2.siddhi.query.api.exception.DuplicateAttributeException) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) MetaStateEventAttribute(org.wso2.siddhi.core.event.state.MetaStateEventAttribute) AttributeProcessor(org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Aggregations

ArrayList (java.util.ArrayList)2 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)2 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)2 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)2 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)2 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)2 ConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor)2 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)2 Attribute (org.wso2.siddhi.query.api.definition.Attribute)2 DuplicateAttributeException (org.wso2.siddhi.query.api.exception.DuplicateAttributeException)2 Variable (org.wso2.siddhi.query.api.expression.Variable)2 MetaStateEventAttribute (org.wso2.siddhi.core.event.state.MetaStateEventAttribute)1 AndConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.AndConditionExpressionExecutor)1 BoolConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.BoolConditionExpressionExecutor)1 InConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.InConditionExpressionExecutor)1 IsNullConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.IsNullConditionExpressionExecutor)1 IsNullStreamConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.IsNullStreamConditionExpressionExecutor)1 NotConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.NotConditionExpressionExecutor)1 OrConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.OrConditionExpressionExecutor)1 AttributeProcessor (org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)1