Search in sources :

Example 46 with MetaStreamEvent

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

the class MatcherParser method constructMatchingMetaStateHolder.

public static MatchingMetaInfoHolder constructMatchingMetaStateHolder(MetaComplexEvent matchingMetaComplexEvent, int defaultStreamEventIndex, AbstractDefinition candsidateDefinition, int currentState) {
    int storeEventIndex = 0;
    MetaStreamEvent tableStreamEvent = new MetaStreamEvent();
    tableStreamEvent.setEventType(MetaStreamEvent.EventType.TABLE);
    tableStreamEvent.addInputDefinition(candsidateDefinition);
    for (Attribute attribute : candsidateDefinition.getAttributeList()) {
        tableStreamEvent.addOutputData(attribute);
    }
    MetaStateEvent metaStateEvent = null;
    if (matchingMetaComplexEvent instanceof MetaStreamEvent) {
        metaStateEvent = new MetaStateEvent(2);
        metaStateEvent.addEvent(((MetaStreamEvent) matchingMetaComplexEvent));
        metaStateEvent.addEvent(tableStreamEvent);
        storeEventIndex = 1;
        defaultStreamEventIndex = 0;
        if (currentState == SiddhiConstants.UNKNOWN_STATE) {
            currentState = defaultStreamEventIndex;
        }
    } else {
        MetaStreamEvent[] metaStreamEvents = ((MetaStateEvent) matchingMetaComplexEvent).getMetaStreamEvents();
        // for join
        for (; storeEventIndex < metaStreamEvents.length; storeEventIndex++) {
            MetaStreamEvent metaStreamEvent = metaStreamEvents[storeEventIndex];
            if (storeEventIndex != defaultStreamEventIndex && metaStreamEvent.getLastInputDefinition().equalsIgnoreAnnotations(candsidateDefinition)) {
                metaStateEvent = ((MetaStateEvent) matchingMetaComplexEvent);
                break;
            }
        }
        if (metaStateEvent == null) {
            metaStateEvent = new MetaStateEvent(metaStreamEvents.length + 1);
            for (MetaStreamEvent metaStreamEvent : metaStreamEvents) {
                metaStateEvent.addEvent(metaStreamEvent);
            }
            metaStateEvent.addEvent(tableStreamEvent);
            storeEventIndex = metaStreamEvents.length;
        }
    }
    return new MatchingMetaInfoHolder(metaStateEvent, defaultStreamEventIndex, storeEventIndex, metaStateEvent.getMetaStreamEvent(defaultStreamEventIndex).getLastInputDefinition(), candsidateDefinition, currentState);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) MatchingMetaInfoHolder(io.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 47 with MetaStreamEvent

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

the class CacheTable method initCacheTable.

public void initCacheTable(TableDefinition cacheTableDefinition, ConfigReader configReader, SiddhiAppContext siddhiAppContext, RecordTableHandler recordTableHandler, boolean cacheExpiryEnabled, int maxSize, String cachePolicy) {
    this.maxSize = maxSize;
    this.cacheExpiryEnabled = cacheExpiryEnabled;
    this.siddhiAppContext = siddhiAppContext;
    addRequiredFieldsToCacheTableDefinition(cacheTableDefinition, cacheExpiryEnabled);
    // initialize cache table
    MetaStreamEvent cacheTableMetaStreamEvent = new MetaStreamEvent();
    cacheTableMetaStreamEvent.addInputDefinition(cacheTableDefinition);
    for (Attribute attribute : cacheTableDefinition.getAttributeList()) {
        cacheTableMetaStreamEvent.addOutputData(attribute);
    }
    StreamEventFactory cacheTableStreamEventFactory = new StreamEventFactory(cacheTableMetaStreamEvent);
    StreamEventCloner cacheTableStreamEventCloner = new StreamEventCloner(cacheTableMetaStreamEvent, cacheTableStreamEventFactory);
    super.initTable(cacheTableDefinition, cacheTableStreamEventFactory, cacheTableStreamEventCloner, configReader, siddhiAppContext, recordTableHandler);
}
Also used : Attribute(io.siddhi.query.api.definition.Attribute) StreamEventFactory(io.siddhi.core.event.stream.StreamEventFactory) StreamEventCloner(io.siddhi.core.event.stream.StreamEventCloner) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 48 with MetaStreamEvent

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

the class ExpressionBatchWindowProcessor method processAllExpiredEvents.

private void processAllExpiredEvents(StreamEventCloner streamEventCloner, WindowState state, long currentTime, List<ComplexEventChunk<StreamEvent>> streamEventChunks) {
    MetaStateEvent metaStateEvent = constructExpression(metaStreamEvent, siddhiQueryContext);
    QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
    if (!streamInputEvents) {
        StreamEvent expiredEvent = state.currentEventQueue.getFirst();
        state.currentEventQueue.clear();
        while (expiredEvent != null) {
            StreamEvent aExpiredEvent = expiredEvent;
            expiredEvent = expiredEvent.getNext();
            aExpiredEvent.setNext(null);
            processStreamEvent(state, currentTime, aExpiredEvent, streamEventCloner, streamEventChunks);
        }
        state.currentEventQueue.reset();
    } else {
        StreamEvent expiredEvent = state.expiredEventQueue.getFirst();
        state.expiredEventQueue.clear();
        while (expiredEvent != null) {
            StreamEvent aExpiredEvent = expiredEvent;
            expiredEvent = expiredEvent.getNext();
            aExpiredEvent.setNext(null);
            processStreamEventAsStream(state, currentTime, aExpiredEvent, streamEventCloner, streamEventChunks, false);
        }
        state.expiredEventQueue.reset();
    }
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 49 with MetaStreamEvent

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

the class ExpressionBatchWindowProcessor method process.

@Override
protected void process(ComplexEventChunk<StreamEvent> streamEventChunk, Processor nextProcessor, StreamEventCloner streamEventCloner, WindowState state) {
    if (expressionStringExecutor == null && !init) {
        MetaStateEvent metaStateEvent = new MetaStateEvent(new MetaStreamEvent[] { metaStreamEvent, metaStreamEvent, metaStreamEvent });
        QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
        init = true;
    }
    List<ComplexEventChunk<StreamEvent>> streamEventChunks = new ArrayList<>();
    synchronized (state) {
        long currentTime = siddhiQueryContext.getSiddhiAppContext().getTimestampGenerator().currentTime();
        while (streamEventChunk.hasNext()) {
            StreamEvent streamEvent = streamEventChunk.next();
            streamEventChunk.remove();
            if (expressionStringExecutor != null) {
                String expressionStringNew = (String) expressionStringExecutor.execute(streamEvent);
                if (!expressionStringNew.equals(expressionString)) {
                    expressionString = expressionStringNew;
                    processAllExpiredEvents(streamEventCloner, state, currentTime, streamEventChunks);
                }
            }
            if (!streamInputEvents) {
                processStreamEvent(state, currentTime, streamEvent, streamEventCloner, streamEventChunks);
            } else {
                processStreamEventAsStream(state, currentTime, streamEvent, streamEventCloner, streamEventChunks, true);
            }
        }
    }
    for (ComplexEventChunk<StreamEvent> outputStreamEventChunk : streamEventChunks) {
        nextProcessor.process(outputStreamEventChunk);
    }
}
Also used : ComplexEventChunk(io.siddhi.core.event.ComplexEventChunk) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) ArrayList(java.util.ArrayList) MetaStateEvent(io.siddhi.core.event.state.MetaStateEvent)

Example 50 with MetaStreamEvent

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

the class ExpressionWindowProcessor method processAllExpiredEvents.

private void processAllExpiredEvents(ComplexEventChunk<StreamEvent> streamEventChunk, WindowState state, long currentTime) {
    MetaStateEvent metaStateEvent = constructExpression(metaStreamEvent, siddhiQueryContext);
    QueryParserHelper.updateVariablePosition(metaStateEvent, variableExpressionExecutors);
    StreamEvent expiredEvent = state.expiredEventQueue.getFirst();
    state.expiredEventQueue.clear();
    while (expiredEvent != null) {
        StreamEvent aExpiredEvent = expiredEvent;
        expiredEvent = expiredEvent.getNext();
        aExpiredEvent.setNext(null);
        processStreamEvent(streamEventChunk, state, currentTime, aExpiredEvent);
    }
    state.expiredEventQueue.reset();
}
Also used : StreamEvent(io.siddhi.core.event.stream.StreamEvent) 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