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);
}
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());
}
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));
}
}
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);
}
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;
}
Aggregations