Search in sources :

Example 21 with ComplexEventChunk

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

the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method constructOutputChunk.

private void constructOutputChunk(List<ComplexEventChunk<ComplexEvent>> outputEventChunks) {
    ComplexEventChunk<ComplexEvent> outputEventChunk = new ComplexEventChunk<ComplexEvent>(false);
    for (GroupedComplexEvent originalComplexEvent : eventList) {
        String currentGroupByKey = originalComplexEvent.getGroupKey();
        Map<Integer, Object> currentAggregateAttributeValueMap = groupByAggregateAttributeValueMap.get(currentGroupByKey);
        ComplexEvent eventCopy = cloneComplexEvent(originalComplexEvent.getComplexEvent());
        for (Integer position : aggregateAttributePositionList) {
            eventCopy.getOutputData()[position] = currentAggregateAttributeValueMap.get(position);
        }
        outputEventChunk.add(eventCopy);
    }
    outputEventChunks.add(outputEventChunk);
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent)

Example 22 with ComplexEventChunk

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

the class AggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        complexEventChunk.reset();
        String currentGroupByKey = null;
        Map<Integer, Object> currentAggregateAttributeValueMap = null;
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                if (currentGroupByKey == null || !currentGroupByKey.equals(groupedComplexEvent.getGroupKey())) {
                    currentGroupByKey = groupedComplexEvent.getGroupKey();
                    currentAggregateAttributeValueMap = groupByAggregateAttributeValueMap.get(currentGroupByKey);
                    if (currentAggregateAttributeValueMap == null) {
                        currentAggregateAttributeValueMap = new HashMap<Integer, Object>(aggregateAttributePositionList.size());
                        groupByAggregateAttributeValueMap.put(currentGroupByKey, currentAggregateAttributeValueMap);
                    }
                }
                if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
                    eventList.add(groupedComplexEvent);
                    for (Integer position : aggregateAttributePositionList) {
                        currentAggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                    }
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                    for (Iterator<GroupedComplexEvent> iterator = eventList.iterator(); iterator.hasNext(); ) {
                        GroupedComplexEvent currentEvent = iterator.next();
                        if (comparator.compare(currentEvent.getComplexEvent(), groupedComplexEvent.getComplexEvent()) == 0) {
                            iterator.remove();
                            for (Integer position : aggregateAttributePositionList) {
                                currentAggregateAttributeValueMap.put(position, groupedComplexEvent.getOutputData()[position]);
                            }
                            break;
                        }
                    }
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.RESET) {
                    eventList.clear();
                    groupByAggregateAttributeValueMap.clear();
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent)

Example 23 with ComplexEventChunk

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

the class AggregationWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    complexEventChunk.reset();
    ArrayList<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                if (event.getType() == ComplexEvent.Type.CURRENT) {
                    eventList.add(event);
                    for (Integer position : aggregateAttributePositionList) {
                        aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                    }
                } else if (event.getType() == ComplexEvent.Type.EXPIRED) {
                    for (Iterator<ComplexEvent> iterator = eventList.iterator(); iterator.hasNext(); ) {
                        ComplexEvent complexEvent = iterator.next();
                        if (comparator.compare(event, complexEvent) == 0) {
                            iterator.remove();
                            for (Integer position : aggregateAttributePositionList) {
                                aggregateAttributeValueMap.put(position, event.getOutputData()[position]);
                            }
                            break;
                        }
                    }
                } else if (event.getType() == ComplexEvent.Type.RESET) {
                    eventList.clear();
                    aggregateAttributeValueMap.clear();
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 24 with ComplexEventChunk

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

the class AllAggregationGroupByWindowedPerSnapshotOutputRateLimiter method process.

@Override
public void process(ComplexEventChunk complexEventChunk) {
    List<ComplexEventChunk<ComplexEvent>> outputEventChunks = new ArrayList<ComplexEventChunk<ComplexEvent>>();
    complexEventChunk.reset();
    synchronized (this) {
        while (complexEventChunk.hasNext()) {
            ComplexEvent event = complexEventChunk.next();
            if (event.getType() == ComplexEvent.Type.TIMER) {
                tryFlushEvents(outputEventChunks, event);
            } else {
                complexEventChunk.remove();
                tryFlushEvents(outputEventChunks, event);
                GroupedComplexEvent groupedComplexEvent = ((GroupedComplexEvent) event);
                LastEventHolder lastEventHolder = groupByKeyEvents.get(groupedComplexEvent.getGroupKey());
                if (lastEventHolder == null) {
                    lastEventHolder = new LastEventHolder();
                    groupByKeyEvents.put(groupedComplexEvent.getGroupKey(), lastEventHolder);
                }
                if (groupedComplexEvent.getType() == ComplexEvent.Type.CURRENT) {
                    lastEventHolder.addLastInEvent(groupedComplexEvent.getComplexEvent());
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.EXPIRED) {
                    lastEventHolder.removeLastInEvent(groupedComplexEvent.getComplexEvent());
                } else if (groupedComplexEvent.getType() == ComplexEvent.Type.RESET) {
                    groupByKeyEvents.clear();
                }
            }
        }
    }
    for (ComplexEventChunk eventChunk : outputEventChunks) {
        sendToCallBacks(eventChunk);
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) ArrayList(java.util.ArrayList) GroupedComplexEvent(org.ballerinalang.siddhi.core.event.GroupedComplexEvent)

Example 25 with ComplexEventChunk

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

the class FindStoreQueryRuntime method executeSelector.

private Event[] executeSelector(StreamEvent streamEvents, MetaStreamEvent.EventType eventType) {
    ComplexEventChunk<StateEvent> complexEventChunk = new ComplexEventChunk<>(true);
    while (streamEvents != null) {
        StreamEvent streamEvent = streamEvents;
        streamEvents = streamEvents.getNext();
        streamEvent.setNext(null);
        StateEvent stateEvent = stateEventPool.borrowEvent();
        if (eventType == MetaStreamEvent.EventType.AGGREGATE) {
            stateEvent.addEvent(1, streamEvent);
        } else {
            stateEvent.addEvent(0, streamEvent);
        }
        complexEventChunk.add(stateEvent);
    }
    ComplexEventChunk outputComplexEventChunk = selector.execute(complexEventChunk);
    if (outputComplexEventChunk != null) {
        List<Event> events = new ArrayList<>();
        outputComplexEventChunk.reset();
        while (outputComplexEventChunk.hasNext()) {
            ComplexEvent complexEvent = outputComplexEventChunk.next();
            events.add(new Event(complexEvent.getTimestamp(), complexEvent.getOutputData()));
        }
        return events.toArray(new Event[0]);
    } else {
        return null;
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) ArrayList(java.util.ArrayList) Event(org.ballerinalang.siddhi.core.event.Event) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent) StateEvent(org.ballerinalang.siddhi.core.event.state.StateEvent)

Aggregations

ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)69 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)41 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)30 ArrayList (java.util.ArrayList)23 StateEvent (org.ballerinalang.siddhi.core.event.state.StateEvent)19 GroupedComplexEvent (org.ballerinalang.siddhi.core.event.GroupedComplexEvent)13 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)12 ExpressionExecutor (org.ballerinalang.siddhi.core.executor.ExpressionExecutor)10 Map (java.util.Map)8 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)4 HashMap (java.util.HashMap)3 Table (org.ballerinalang.siddhi.core.table.Table)3 Collection (java.util.Collection)2 Iterator (java.util.Iterator)2 Event (org.ballerinalang.siddhi.core.event.Event)2 SiddhiAppRuntimeException (org.ballerinalang.siddhi.core.exception.SiddhiAppRuntimeException)2 StreamPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)2 TimePeriod (org.ballerinalang.siddhi.query.api.aggregation.TimePeriod)2 IncrementalDataAggregator (org.ballerinalang.siddhi.core.aggregation.IncrementalDataAggregator)1 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)1