Search in sources :

Example 1 with MetaStateEventAttribute

use of org.wso2.siddhi.core.event.state.MetaStateEventAttribute 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)

Example 2 with MetaStateEventAttribute

use of org.wso2.siddhi.core.event.state.MetaStateEventAttribute in project siddhi by wso2.

the class StateEventPopulatorFactory method getMappingElements.

private static List<StateMappingElement> getMappingElements(MetaStateEvent metaStateEvent) {
    List<StateMappingElement> stateMappingElements = new ArrayList<StateMappingElement>(metaStateEvent.getOutputDataAttributes().size());
    List<MetaStateEventAttribute> currentDataList = metaStateEvent.getOutputDataAttributes();
    if (currentDataList != null) {
        int i = 0;
        for (MetaStateEventAttribute metaStateEventAttribute : currentDataList) {
            // will be filled.
            if (metaStateEventAttribute == null) {
                i++;
            } else {
                StateMappingElement stateMappingElement = new StateMappingElement();
                stateMappingElement.setFromPosition(metaStateEventAttribute.getPosition());
                int toPosition = i;
                stateMappingElement.setToPosition(toPosition);
                stateMappingElements.add(stateMappingElement);
                i++;
            }
        }
    }
    return stateMappingElements;
}
Also used : ArrayList(java.util.ArrayList) MetaStateEventAttribute(org.wso2.siddhi.core.event.state.MetaStateEventAttribute)

Aggregations

ArrayList (java.util.ArrayList)2 MetaStateEventAttribute (org.wso2.siddhi.core.event.state.MetaStateEventAttribute)2 MetaStateEvent (org.wso2.siddhi.core.event.state.MetaStateEvent)1 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)1 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)1 ExpressionExecutor (org.wso2.siddhi.core.executor.ExpressionExecutor)1 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)1 ConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor)1 AttributeProcessor (org.wso2.siddhi.core.query.selector.attribute.processor.AttributeProcessor)1 AbstractDefinition (org.wso2.siddhi.query.api.definition.AbstractDefinition)1 Attribute (org.wso2.siddhi.query.api.definition.Attribute)1 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)1 DuplicateAttributeException (org.wso2.siddhi.query.api.exception.DuplicateAttributeException)1 OutputAttribute (org.wso2.siddhi.query.api.execution.query.selection.OutputAttribute)1 Variable (org.wso2.siddhi.query.api.expression.Variable)1