Search in sources :

Example 11 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class AggregationRuntime method alterMetaInfoHolderForStoreQuery.

private static MatchingMetaInfoHolder alterMetaInfoHolderForStoreQuery(MetaStreamEvent newMetaStreamEventWithStartEnd, MatchingMetaInfoHolder matchingMetaInfoHolder) {
    MetaStateEvent metaStateEvent = new MetaStateEvent(2);
    MetaStreamEvent incomingMetaStreamEvent = matchingMetaInfoHolder.getMetaStateEvent().getMetaStreamEvent(0);
    metaStateEvent.addEvent(newMetaStreamEventWithStartEnd);
    metaStateEvent.addEvent(incomingMetaStreamEvent);
    return new MatchingMetaInfoHolder(metaStateEvent, 0, 1, newMetaStreamEventWithStartEnd.getLastInputDefinition(), incomingMetaStreamEvent.getLastInputDefinition(), UNKNOWN_STATE);
}
Also used : MatchingMetaInfoHolder(org.ballerinalang.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Example 12 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class EventTestCase method testUpdateMetaEvent.

@Test
public void testUpdateMetaEvent() {
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    Attribute price = new Attribute("price", Attribute.Type.FLOAT);
    Attribute volume = new Attribute("volume", Attribute.Type.INT);
    Attribute symbol = new Attribute("symbol", Attribute.Type.STRING);
    MetaStreamEvent metaStreamEvent = new MetaStreamEvent();
    metaStreamEvent.addData(volume);
    metaStreamEvent.addData(price);
    metaStreamEvent.addData(symbol);
    metaStreamEvent.initializeAfterWindowData();
    metaStreamEvent.addData(price);
    metaStreamEvent.addOutputData(symbol);
    metaStreamEvent.addOutputData(null);
    MetaStateEvent metaStateEvent = new MetaStateEvent(1);
    metaStateEvent.addEvent(metaStreamEvent);
    VariableExpressionExecutor priceVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("price", Attribute.Type.FLOAT), 0, 0);
    VariableExpressionExecutor volumeVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("volume", Attribute.Type.INT), 0, 0);
    VariableExpressionExecutor symbolVariableExpressionExecutor = new VariableExpressionExecutor(new Attribute("symbol", Attribute.Type.STRING), 0, 0);
    QueryParserHelper.reduceMetaComplexEvent(metaStateEvent);
    QueryParserHelper.updateVariablePosition(metaStateEvent, Arrays.asList(priceVariableExpressionExecutor, volumeVariableExpressionExecutor, symbolVariableExpressionExecutor));
    AssertJUnit.assertEquals(1, metaStreamEvent.getBeforeWindowData().size());
    AssertJUnit.assertEquals(1, metaStreamEvent.getOnAfterWindowData().size());
    AssertJUnit.assertEquals(2, metaStreamEvent.getOutputData().size());
    AssertJUnit.assertArrayEquals(new int[] { 0, 0, 1, 0 }, priceVariableExpressionExecutor.getPosition());
    AssertJUnit.assertArrayEquals(new int[] { 0, 0, 0, 0 }, volumeVariableExpressionExecutor.getPosition());
    AssertJUnit.assertArrayEquals(new int[] { 0, 0, 2, 0 }, symbolVariableExpressionExecutor.getPosition());
}
Also used : StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) VariableExpressionExecutor(org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) Test(org.testng.annotations.Test)

Example 13 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class WrappedSnapshotOutputRateLimiter method init.

public void init(int outPutAttributeSize, List<AttributeProcessor> attributeProcessorList, MetaComplexEvent metaComplexEvent) {
    for (AttributeProcessor attributeProcessor : attributeProcessorList) {
        if (attributeProcessor.getExpressionExecutor() instanceof AbstractAggregationAttributeExecutor) {
            aggregateAttributePositionList.add(attributeProcessor.getOutputPosition());
        }
    }
    if (windowed) {
        if (groupBy) {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationGroupByWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, aggregateAttributePositionList, this, siddhiAppContext, queryName);
            } else {
                // No aggregation
                // GroupBy is same as Non GroupBy
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
            }
        } else {
            if (outPutAttributeSize == aggregateAttributePositionList.size()) {
                // All Aggregation
                outputRateLimiter = new AllAggregationPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
            } else if (aggregateAttributePositionList.size() > 0) {
                // Some Aggregation
                outputRateLimiter = new AggregationWindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, aggregateAttributePositionList, this, siddhiAppContext, queryName);
            } else {
                // No aggregation
                outputRateLimiter = new WindowedPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
            }
        }
    } else {
        if (groupBy) {
            outputRateLimiter = new GroupByPerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
        } else {
            outputRateLimiter = new PerSnapshotOutputRateLimiter(id, value, scheduledExecutorService, this, siddhiAppContext, queryName);
        }
    }
    if (metaComplexEvent instanceof MetaStateEvent) {
        StateEventPool stateEventPool = new StateEventPool((MetaStateEvent) metaComplexEvent, 5);
        outputRateLimiter.setStateEventCloner(new StateEventCloner((MetaStateEvent) metaComplexEvent, stateEventPool));
    } else {
        StreamEventPool streamEventPool = new StreamEventPool((MetaStreamEvent) metaComplexEvent, 5);
        outputRateLimiter.setStreamEventCloner(new StreamEventCloner((MetaStreamEvent) metaComplexEvent, streamEventPool));
    }
}
Also used : AbstractAggregationAttributeExecutor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.executor.AbstractAggregationAttributeExecutor) StateEventPool(org.ballerinalang.siddhi.core.event.state.StateEventPool) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent) StreamEventPool(org.ballerinalang.siddhi.core.event.stream.StreamEventPool) StreamEventCloner(org.ballerinalang.siddhi.core.event.stream.StreamEventCloner) AttributeProcessor(org.ballerinalang.siddhi.core.query.selector.attribute.processor.AttributeProcessor) StateEventCloner(org.ballerinalang.siddhi.core.event.state.StateEventCloner) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)

Example 14 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class AggregationRuntime method createNewStreamTableMetaInfoHolder.

private static MatchingMetaInfoHolder createNewStreamTableMetaInfoHolder(MetaStreamEvent metaStreamEventWithStartEnd, AbstractDefinition tableDefinition) {
    MetaStateEvent metaStateEvent = new MetaStateEvent(2);
    MetaStreamEvent metaStreamEventForTable = new MetaStreamEvent();
    metaStreamEventForTable.setEventType(MetaStreamEvent.EventType.TABLE);
    initMetaStreamEvent(metaStreamEventForTable, tableDefinition);
    metaStateEvent.addEvent(metaStreamEventWithStartEnd);
    metaStateEvent.addEvent(metaStreamEventForTable);
    return new MatchingMetaInfoHolder(metaStateEvent, 0, 1, metaStreamEventWithStartEnd.getLastInputDefinition(), tableDefinition, UNKNOWN_STATE);
}
Also used : MatchingMetaInfoHolder(org.ballerinalang.siddhi.core.util.collection.operator.MatchingMetaInfoHolder) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Example 15 with MetaStateEvent

use of org.ballerinalang.siddhi.core.event.state.MetaStateEvent in project ballerina by ballerina-lang.

the class PartitionParser method createMetaEventForPartitioner.

/**
 * Create metaEvent to be used by StreamPartitioner with output attributes.
 *
 * @param stateEvent metaStateEvent of the queryRuntime
 * @return metaStateEvent
 */
private static MetaStateEvent createMetaEventForPartitioner(MetaComplexEvent stateEvent) {
    MetaStateEvent metaStateEvent;
    if (stateEvent instanceof MetaStateEvent) {
        metaStateEvent = new MetaStateEvent(((MetaStateEvent) stateEvent).getStreamEventCount());
        for (MetaStreamEvent metaStreamEvent : ((MetaStateEvent) stateEvent).getMetaStreamEvents()) {
            AbstractDefinition definition = metaStreamEvent.getLastInputDefinition();
            MetaStreamEvent newMetaStreamEvent = new MetaStreamEvent();
            for (Attribute attribute : definition.getAttributeList()) {
                newMetaStreamEvent.addOutputData(attribute);
            }
            newMetaStreamEvent.addInputDefinition(definition);
            newMetaStreamEvent.setEventType(metaStreamEvent.getEventType());
            metaStateEvent.addEvent(newMetaStreamEvent);
        }
    } else {
        metaStateEvent = new MetaStateEvent(1);
        AbstractDefinition definition = ((MetaStreamEvent) stateEvent).getLastInputDefinition();
        MetaStreamEvent newMetaStreamEvent = new MetaStreamEvent();
        for (Attribute attribute : definition.getAttributeList()) {
            newMetaStreamEvent.addOutputData(attribute);
        }
        newMetaStreamEvent.addInputDefinition(definition);
        newMetaStreamEvent.setEventType(((MetaStreamEvent) stateEvent).getEventType());
        metaStateEvent.addEvent(newMetaStreamEvent);
    }
    return metaStateEvent;
}
Also used : Attribute(org.ballerinalang.siddhi.query.api.definition.Attribute) AbstractDefinition(org.ballerinalang.siddhi.query.api.definition.AbstractDefinition) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) MetaStateEvent(org.ballerinalang.siddhi.core.event.state.MetaStateEvent)

Aggregations

MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)22 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)19 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)10 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)8 AbstractDefinition (org.ballerinalang.siddhi.query.api.definition.AbstractDefinition)7 MatchingMetaInfoHolder (org.ballerinalang.siddhi.core.util.collection.operator.MatchingMetaInfoHolder)6 Variable (org.ballerinalang.siddhi.query.api.expression.Variable)5 ArrayList (java.util.ArrayList)4 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)4 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)4 SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)4 Expression (org.ballerinalang.siddhi.query.api.expression.Expression)4 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)3 ConstantExpressionExecutor (org.ballerinalang.siddhi.core.executor.ConstantExpressionExecutor)3 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)3 ProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver)3 StateEventCloner (org.ballerinalang.siddhi.core.event.state.StateEventCloner)2 StateEventPool (org.ballerinalang.siddhi.core.event.state.StateEventPool)2 StreamEventCloner (org.ballerinalang.siddhi.core.event.stream.StreamEventCloner)2 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)2