Search in sources :

Example 26 with MetaStreamEvent

use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.

the class InsertOnDemandQueryRuntime method generateResetComplexEventChunk.

private ComplexEventChunk<ComplexEvent> generateResetComplexEventChunk(MetaStreamEvent metaStreamEvent) {
    StreamEvent streamEvent = new StreamEvent(metaStreamEvent.getBeforeWindowData().size(), metaStreamEvent.getOnAfterWindowData().size(), metaStreamEvent.getOutputData().size());
    streamEvent.setType(ComplexEvent.Type.RESET);
    StateEvent stateEvent = stateEventFactory.newInstance();
    stateEvent.addEvent(0, streamEvent);
    stateEvent.setType(ComplexEvent.Type.RESET);
    ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<>();
    complexEventChunk.add(stateEvent);
    return complexEventChunk;
}
Also used : ComplexEvent(io.siddhi.core.event.ComplexEvent) ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) StateEvent(io.siddhi.core.event.state.StateEvent)

Example 27 with MetaStreamEvent

use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.

the class ExpressionBuilder method buildVariableExecutors.

private void buildVariableExecutors(Expression expression, ExpressionVisitor expressionVisitor) {
    try {
        if (expression instanceof And) {
            expressionVisitor.beginVisitAnd();
            expressionVisitor.beginVisitAndLeftOperand();
            buildVariableExecutors(((And) expression).getLeftExpression(), expressionVisitor);
            expressionVisitor.endVisitAndLeftOperand();
            expressionVisitor.beginVisitAndRightOperand();
            buildVariableExecutors(((And) expression).getRightExpression(), expressionVisitor);
            expressionVisitor.endVisitAndRightOperand();
            expressionVisitor.endVisitAnd();
        } else if (expression instanceof Or) {
            expressionVisitor.beginVisitOr();
            expressionVisitor.beginVisitOrLeftOperand();
            buildVariableExecutors(((Or) expression).getLeftExpression(), expressionVisitor);
            expressionVisitor.endVisitOrLeftOperand();
            expressionVisitor.beginVisitOrRightOperand();
            buildVariableExecutors(((Or) expression).getRightExpression(), expressionVisitor);
            expressionVisitor.endVisitOrRightOperand();
            expressionVisitor.endVisitOr();
        } else if (expression instanceof Not) {
            expressionVisitor.beginVisitNot();
            buildVariableExecutors(((Not) expression).getExpression(), expressionVisitor);
            expressionVisitor.endVisitNot();
        } else if (expression instanceof Compare) {
            expressionVisitor.beginVisitCompare(((Compare) expression).getOperator());
            expressionVisitor.beginVisitCompareLeftOperand(((Compare) expression).getOperator());
            buildVariableExecutors(((Compare) expression).getLeftExpression(), expressionVisitor);
            expressionVisitor.endVisitCompareLeftOperand(((Compare) expression).getOperator());
            expressionVisitor.beginVisitCompareRightOperand(((Compare) expression).getOperator());
            buildVariableExecutors(((Compare) expression).getRightExpression(), expressionVisitor);
            expressionVisitor.endVisitCompareRightOperand(((Compare) expression).getOperator());
            expressionVisitor.endVisitCompare(((Compare) expression).getOperator());
        } else if (expression instanceof Add) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.ADD);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.ADD);
            buildVariableExecutors(((Add) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.ADD);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.ADD);
            buildVariableExecutors(((Add) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.ADD);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.ADD);
        } else if (expression instanceof Subtract) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.SUBTRACT);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.SUBTRACT);
            buildVariableExecutors(((Subtract) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.SUBTRACT);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.SUBTRACT);
            buildVariableExecutors(((Subtract) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.SUBTRACT);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.SUBTRACT);
        } else if (expression instanceof Divide) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.DIVIDE);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.DIVIDE);
            buildVariableExecutors(((Divide) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.DIVIDE);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.DIVIDE);
            buildVariableExecutors(((Divide) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.DIVIDE);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.DIVIDE);
        } else if (expression instanceof Multiply) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.MULTIPLY);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.MULTIPLY);
            buildVariableExecutors(((Multiply) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.MULTIPLY);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.MULTIPLY);
            buildVariableExecutors(((Multiply) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.MULTIPLY);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.MULTIPLY);
        } else if (expression instanceof Mod) {
            expressionVisitor.beginVisitMath(ExpressionVisitor.MathOperator.MOD);
            expressionVisitor.beginVisitMathLeftOperand(ExpressionVisitor.MathOperator.MOD);
            buildVariableExecutors(((Mod) expression).getLeftValue(), expressionVisitor);
            expressionVisitor.endVisitMathLeftOperand(ExpressionVisitor.MathOperator.MOD);
            expressionVisitor.beginVisitMathRightOperand(ExpressionVisitor.MathOperator.MOD);
            buildVariableExecutors(((Mod) expression).getRightValue(), expressionVisitor);
            expressionVisitor.endVisitMathRightOperand(ExpressionVisitor.MathOperator.MOD);
            expressionVisitor.endVisitMath(ExpressionVisitor.MathOperator.MOD);
        } else if (expression instanceof IsNull) {
            IsNull isNull = (IsNull) expression;
            if (isNull.getExpression() != null) {
                expressionVisitor.beginVisitIsNull(null);
                buildVariableExecutors(((IsNull) expression).getExpression(), expressionVisitor);
                expressionVisitor.endVisitIsNull(null);
            } else {
                String streamId = isNull.getStreamId();
                MetaStateEvent metaStateEvent = matchingMetaInfoHolder.getMetaStateEvent();
                if (streamId == null) {
                    throw new SiddhiAppCreationException("IsNull does not support streamId being null");
                } else {
                    AbstractDefinition definitionOutput = null;
                    MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
                    for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
                        MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
                        AbstractDefinition definition = metaStreamEvent.getLastInputDefinition();
                        if (metaStreamEvent.getInputReferenceId() == null) {
                            if (definition.getId().equals(streamId)) {
                                definitionOutput = definition;
                                break;
                            }
                        } else {
                            if (metaStreamEvent.getInputReferenceId().equals(streamId)) {
                                definitionOutput = definition;
                                break;
                            }
                        }
                    }
                    if (definitionOutput != null) {
                        expressionVisitor.beginVisitIsNull(definitionOutput.getId());
                        expressionVisitor.endVisitIsNull(definitionOutput.getId());
                    } else {
                        expressionVisitor.beginVisitIsNull(null);
                        expressionVisitor.endVisitIsNull(null);
                    }
                }
            }
        } else if (expression instanceof In) {
            expressionVisitor.beginVisitIn(((In) expression).getSourceId());
            buildVariableExecutors(((In) expression).getExpression(), expressionVisitor);
            expressionVisitor.endVisitIn(((In) expression).getSourceId());
        } else if (expression instanceof Constant) {
            if (expression instanceof DoubleConstant) {
                expressionVisitor.beginVisitConstant(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
                expressionVisitor.endVisitConstant(((DoubleConstant) expression).getValue(), Attribute.Type.DOUBLE);
            } else if (expression instanceof StringConstant) {
                expressionVisitor.beginVisitConstant(((StringConstant) expression).getValue(), Attribute.Type.STRING);
                expressionVisitor.endVisitConstant(((StringConstant) expression).getValue(), Attribute.Type.STRING);
            } else if (expression instanceof IntConstant) {
                expressionVisitor.beginVisitConstant(((IntConstant) expression).getValue(), Attribute.Type.INT);
                expressionVisitor.endVisitConstant(((IntConstant) expression).getValue(), Attribute.Type.INT);
            } else if (expression instanceof BoolConstant) {
                expressionVisitor.beginVisitConstant(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
                expressionVisitor.endVisitConstant(((BoolConstant) expression).getValue(), Attribute.Type.BOOL);
            } else if (expression instanceof FloatConstant) {
                expressionVisitor.beginVisitConstant(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
                expressionVisitor.endVisitConstant(((FloatConstant) expression).getValue(), Attribute.Type.FLOAT);
            } else if (expression instanceof LongConstant) {
                expressionVisitor.beginVisitConstant(((LongConstant) expression).getValue(), Attribute.Type.LONG);
                expressionVisitor.endVisitConstant(((LongConstant) expression).getValue(), Attribute.Type.LONG);
            } else {
                throw new OperationNotSupportedException("No constant exist with type " + expression.getClass().getName());
            }
        } else if (expression instanceof AttributeFunction) {
            expressionVisitor.beginVisitAttributeFunction(((AttributeFunction) expression).getNamespace(), ((AttributeFunction) expression).getName());
            Expression[] expressions = ((AttributeFunction) expression).getParameters();
            if (expressions != null) {
                for (int i = 0; i < expressions.length; i++) {
                    expressionVisitor.beginVisitParameterAttributeFunction(i);
                    buildVariableExecutors(expressions[i], expressionVisitor);
                    expressionVisitor.endVisitParameterAttributeFunction(i);
                }
            }
            expressionVisitor.endVisitAttributeFunction(((AttributeFunction) expression).getNamespace(), ((AttributeFunction) expression).getName());
        } else if (expression instanceof Variable) {
            Variable variable = ((Variable) expression);
            String attributeName = variable.getAttributeName();
            AbstractDefinition definition;
            Attribute.Type type = null;
            int streamEventChainIndex = matchingMetaInfoHolder.getCurrentState();
            if (variable.getStreamId() == null) {
                MetaStreamEvent[] metaStreamEvents = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents();
                if (streamEventChainIndex == UNKNOWN_STATE) {
                    String firstInput = null;
                    for (int i = 0; i < metaStreamEvents.length; i++) {
                        MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
                        definition = metaStreamEvent.getLastInputDefinition();
                        if (type == null) {
                            try {
                                type = definition.getAttributeType(attributeName);
                                firstInput = "Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId();
                                streamEventChainIndex = i;
                            } catch (AttributeNotExistException e) {
                            // do nothing
                            }
                        } else {
                            try {
                                definition.getAttributeType(attributeName);
                                throw new SiddhiAppValidationException(firstInput + " and Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId() + " contains attribute " + "with same" + " name '" + attributeName + "'");
                            } catch (AttributeNotExistException e) {
                            // do nothing as its expected
                            }
                        }
                    }
                    if (streamEventChainIndex != UNKNOWN_STATE) {
                        if (matchingMetaInfoHolder.getMatchingStreamEventIndex() == streamEventChainIndex) {
                            buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
                        } else {
                            buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                        }
                    } else {
                        // Having state : i.e attribute is in the select clause
                        definition = matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition();
                        try {
                            type = definition.getAttributeType(attributeName);
                            buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                        } catch (AttributeNotExistException e) {
                        // do nothing as its not expected
                        }
                    }
                } else {
                    MetaStreamEvent metaStreamEvent = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvent(matchingMetaInfoHolder.getCurrentState());
                    definition = metaStreamEvent.getLastInputDefinition();
                    try {
                        type = definition.getAttributeType(attributeName);
                    } catch (AttributeNotExistException e) {
                        // Having state : i.e attribute is in the select clause
                        definition = matchingMetaInfoHolder.getMetaStateEvent().getOutputStreamDefinition();
                        try {
                            type = definition.getAttributeType(attributeName);
                            buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                        } catch (AttributeNotExistException e1) {
                            throw new SiddhiAppValidationException(e1.getMessageWithOutContext() + " Input Stream: " + definition.getId() + " with " + "reference: " + metaStreamEvent.getInputReferenceId(), e1.getQueryContextStartIndex(), e1.getQueryContextEndIndex(), siddhiQueryContext.getSiddhiAppContext().getName(), siddhiQueryContext.getSiddhiAppContext().getSiddhiAppString());
                        }
                    }
                    if (matchingMetaInfoHolder.getCurrentState() == matchingMetaInfoHolder.getMatchingStreamEventIndex()) {
                        buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
                    } else {
                        buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                    }
                }
            } else {
                MetaStreamEvent[] metaStreamEvents = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents();
                for (int i = 0, metaStreamEventsLength = metaStreamEvents.length; i < metaStreamEventsLength; i++) {
                    MetaStreamEvent metaStreamEvent = metaStreamEvents[i];
                    definition = metaStreamEvent.getLastInputDefinition();
                    if (metaStreamEvent.getInputReferenceId() == null) {
                        if (definition.getId().equals(variable.getStreamId())) {
                            type = definition.getAttributeType(attributeName);
                            streamEventChainIndex = i;
                            break;
                        }
                    } else {
                        if (metaStreamEvent.getInputReferenceId().equals(variable.getStreamId())) {
                            type = definition.getAttributeType(attributeName);
                            streamEventChainIndex = i;
                            break;
                        }
                    }
                }
                if (matchingMetaInfoHolder.getMatchingStreamEventIndex() == streamEventChainIndex) {
                    buildStreamVariableExecutor(variable, streamEventChainIndex, expressionVisitor, type);
                } else {
                    buildStoreVariableExecutor(variable, expressionVisitor, type, matchingMetaInfoHolder.getStoreDefinition());
                }
            }
        }
    } catch (Throwable t) {
        ExceptionUtil.populateQueryContext(t, expression, siddhiQueryContext.getSiddhiAppContext(), siddhiQueryContext);
        throw t;
    }
}
Also used : Add(io.siddhi.query.api.expression.math.Add) DoubleConstant(io.siddhi.query.api.expression.constant.DoubleConstant) Or(io.siddhi.query.api.expression.condition.Or) Variable(io.siddhi.query.api.expression.Variable) In(io.siddhi.query.api.expression.condition.In) StringConstant(io.siddhi.query.api.expression.constant.StringConstant) DoubleConstant(io.siddhi.query.api.expression.constant.DoubleConstant) FloatConstant(io.siddhi.query.api.expression.constant.FloatConstant) LongConstant(io.siddhi.query.api.expression.constant.LongConstant) IntConstant(io.siddhi.query.api.expression.constant.IntConstant) Constant(io.siddhi.query.api.expression.constant.Constant) BoolConstant(io.siddhi.query.api.expression.constant.BoolConstant) FloatConstant(io.siddhi.query.api.expression.constant.FloatConstant) Divide(io.siddhi.query.api.expression.math.Divide) AttributeNotExistException(io.siddhi.query.api.exception.AttributeNotExistException) Multiply(io.siddhi.query.api.expression.math.Multiply) IntConstant(io.siddhi.query.api.expression.constant.IntConstant) Compare(io.siddhi.query.api.expression.condition.Compare) LongConstant(io.siddhi.query.api.expression.constant.LongConstant) OperationNotSupportedException(io.siddhi.core.exception.OperationNotSupportedException) BoolConstant(io.siddhi.query.api.expression.constant.BoolConstant) Mod(io.siddhi.query.api.expression.math.Mod) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) AbstractDefinition(io.siddhi.query.api.definition.AbstractDefinition) SiddhiAppValidationException(io.siddhi.query.api.exception.SiddhiAppValidationException) AttributeFunction(io.siddhi.query.api.expression.AttributeFunction) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent) Not(io.siddhi.query.api.expression.condition.Not) Expression(io.siddhi.query.api.expression.Expression) And(io.siddhi.query.api.expression.condition.And) Subtract(io.siddhi.query.api.expression.math.Subtract) IsNull(io.siddhi.query.api.expression.condition.IsNull) StringConstant(io.siddhi.query.api.expression.constant.StringConstant) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 28 with MetaStreamEvent

use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.

the class CacheTable method generateCacheCompileCondition.

public CacheCompiledConditionWithRouteToCache generateCacheCompileCondition(Expression condition, MatchingMetaInfoHolder storeMatchingMetaInfoHolder, SiddhiQueryContext siddhiQueryContext, List<VariableExpressionExecutor> storeVariableExpressionExecutors) {
    boolean routeToCache = checkConditionToRouteToCache(condition, storeMatchingMetaInfoHolder);
    MetaStateEvent metaStateEvent = new MetaStateEvent(storeMatchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents().length);
    for (MetaStreamEvent referenceMetaStreamEvent : storeMatchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvents()) {
        metaStateEvent.addEvent(referenceMetaStreamEvent);
    }
    MatchingMetaInfoHolder matchingMetaInfoHolder = new MatchingMetaInfoHolder(metaStateEvent, storeMatchingMetaInfoHolder.getMatchingStreamEventIndex(), storeMatchingMetaInfoHolder.getStoreEventIndex(), storeMatchingMetaInfoHolder.getMatchingStreamDefinition(), this.tableDefinition, storeMatchingMetaInfoHolder.getCurrentState());
    Map<String, Table> tableMap = new ConcurrentHashMap<>();
    tableMap.put(this.tableDefinition.getId(), this);
    return new CacheCompiledConditionWithRouteToCache(compileCondition(condition, matchingMetaInfoHolder, storeVariableExpressionExecutors, tableMap, siddhiQueryContext, routeToCache), routeToCache);
}
Also used : MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 29 with MetaStreamEvent

use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.

the class Window method init.

/**
 * Initialize the WindowEvent table by creating {@link WindowProcessor} to handle the events.
 *
 * @param tableMap         map of {@link Table}s
 * @param eventWindowMap   map of EventWindows
 * @param windowName       name of the query window belongs to.
 * @param findToBeExecuted will find will be executed on the window.
 */
public void init(Map<String, Table> tableMap, Map<String, Window> eventWindowMap, String windowName, boolean findToBeExecuted) {
    if (this.windowProcessor != null) {
        return;
    }
    // Create and initialize MetaStreamEvent
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addInputDefinition(windowDefinition);
    metaStreamEvent.setEventType(MetaStreamEvent.EventType.WINDOW);
    for (Attribute attribute : windowDefinition.getAttributeList()) {
        metaStreamEvent.addOutputData(attribute);
    }
    this.streamEventFactory = new StreamEventFactory(metaStreamEvent);
    StreamEventCloner streamEventCloner = new StreamEventCloner(metaStreamEvent, this.streamEventFactory);
    OutputStream.OutputEventType outputEventType = windowDefinition.getOutputEventType();
    boolean outputExpectsExpiredEvents = outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS;
    SiddhiQueryContext siddhiQueryContext = new SiddhiQueryContext(siddhiAppContext, windowName);
    WindowProcessor internalWindowProcessor = (WindowProcessor) SingleInputStreamParser.generateProcessor(windowDefinition.getWindow(), metaStreamEvent, new ArrayList<VariableExpressionExecutor>(), tableMap, false, outputExpectsExpiredEvents, findToBeExecuted, siddhiQueryContext);
    internalWindowProcessor.setStreamEventCloner(streamEventCloner);
    internalWindowProcessor.constructStreamEventPopulater(metaStreamEvent, 0);
    EntryValveProcessor entryValveProcessor = null;
    if (internalWindowProcessor instanceof SchedulingProcessor) {
        entryValveProcessor = new EntryValveProcessor(this.siddhiAppContext);
        Scheduler scheduler = SchedulerParser.parse(entryValveProcessor, siddhiQueryContext);
        scheduler.init(this.lockWrapper, windowName);
        scheduler.setStreamEventFactory(streamEventFactory);
        ((SchedulingProcessor) internalWindowProcessor).setScheduler(scheduler);
    }
    if (entryValveProcessor != null) {
        entryValveProcessor.setToLast(internalWindowProcessor);
        this.windowProcessor = entryValveProcessor;
    } else {
        this.windowProcessor = internalWindowProcessor;
    }
    // StreamPublishProcessor must be the last in chain so that it can publish the events to StreamJunction
    this.windowProcessor.setToLast(new StreamPublishProcessor(outputEventType));
    this.internalWindowProcessor = internalWindowProcessor;
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) Scheduler(io.siddhi.core.util.Scheduler) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) OutputStream(io.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) SchedulingProcessor(io.siddhi.core.query.processor.SchedulingProcessor) SiddhiQueryContext(io.siddhi.core.config.SiddhiQueryContext) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) EntryValveProcessor(io.siddhi.core.query.input.stream.single.EntryValveProcessor) WindowProcessor(io.siddhi.core.query.processor.stream.window.WindowProcessor) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 30 with MetaStreamEvent

use of io.siddhi.core.event.stream.MetaStreamEvent in project siddhi by wso2.

the class QueryParserHelper method updateVariablePosition.

public static void updateVariablePosition(MetaComplexEvent metaComplexEvent, List<VariableExpressionExecutor> variableExpressionExecutorList) {
    for (VariableExpressionExecutor variableExpressionExecutor : variableExpressionExecutorList) {
        int streamEventChainIndex = variableExpressionExecutor.getPosition()[STREAM_EVENT_CHAIN_INDEX];
        if (streamEventChainIndex == HAVING_STATE) {
            if (metaComplexEvent instanceof MetaStreamEvent) {
                variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = OUTPUT_DATA_INDEX;
            } else {
                variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = STATE_OUTPUT_DATA_INDEX;
            }
            variableExpressionExecutor.getPosition()[STREAM_EVENT_CHAIN_INDEX] = UNKNOWN_STATE;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaComplexEvent.getOutputStreamDefinition().getAttributeList().indexOf(variableExpressionExecutor.getAttribute());
            continue;
        } else if (metaComplexEvent instanceof MetaStreamEvent && streamEventChainIndex >= 1) {
            // VariableExpressionExecutor on Event table
            continue;
        } else if (metaComplexEvent instanceof MetaStateEvent && streamEventChainIndex >= ((MetaStateEvent) metaComplexEvent).getMetaStreamEvents().length) {
            // for VariableExpressionExecutor on Event table
            continue;
        }
        MetaStreamEvent metaStreamEvent;
        if (metaComplexEvent instanceof MetaStreamEvent) {
            metaStreamEvent = (MetaStreamEvent) metaComplexEvent;
        } else {
            metaStreamEvent = ((MetaStateEvent) metaComplexEvent).getMetaStreamEvent(streamEventChainIndex);
        }
        if (metaStreamEvent.getOutputData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = OUTPUT_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getOutputData().indexOf(variableExpressionExecutor.getAttribute());
        } else if (metaStreamEvent.getOnAfterWindowData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = ON_AFTER_WINDOW_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getOnAfterWindowData().indexOf(variableExpressionExecutor.getAttribute());
        } else if (metaStreamEvent.getBeforeWindowData().contains(variableExpressionExecutor.getAttribute())) {
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_TYPE_INDEX] = BEFORE_WINDOW_DATA_INDEX;
            variableExpressionExecutor.getPosition()[STREAM_ATTRIBUTE_INDEX_IN_TYPE] = metaStreamEvent.getBeforeWindowData().indexOf(variableExpressionExecutor.getAttribute());
        }
    }
}
Also used : VariableExpressionExecutor(io.siddhi.core.executor.VariableExpressionExecutor) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Aggregations

MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)63 Attribute (io.siddhi.query.api.definition.Attribute)35 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)34 StreamEvent (io.siddhi.core.event.stream.StreamEvent)21 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)17 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)17 ArrayList (java.util.ArrayList)17 StreamEventCloner (io.siddhi.core.event.stream.StreamEventCloner)14 MatchingMetaInfoHolder (io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)14 Variable (io.siddhi.query.api.expression.Variable)14 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)13 HashMap (java.util.HashMap)13 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)12 Expression (io.siddhi.query.api.expression.Expression)12 ExpressionExecutor (io.siddhi.core.executor.ExpressionExecutor)10 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)10 Map (java.util.Map)10 Test (org.testng.annotations.Test)10 ConstantExpressionExecutor (io.siddhi.core.executor.ConstantExpressionExecutor)9 TableDefinition (io.siddhi.query.api.definition.TableDefinition)9