Search in sources :

Example 1 with PartitionExecutor

use of org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor in project ballerina by ballerina-lang.

the class PartitionStreamReceiver method receive.

@Override
public void receive(long timestamp, Object[] data) {
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    streamEventConverter.convertData(timestamp, data, borrowedEvent);
    if (partitionExecutors.size() == 0) {
        send(borrowedEvent);
    } else {
        for (PartitionExecutor partitionExecutor : partitionExecutors) {
            String key = partitionExecutor.execute(borrowedEvent);
            send(key, borrowedEvent);
        }
    }
    eventPool.returnEvents(borrowedEvent);
}
Also used : PartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 2 with PartitionExecutor

use of org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor in project ballerina by ballerina-lang.

the class PartitionStreamReceiver method receive.

@Override
public void receive(Event event) {
    StreamEvent borrowedEvent = eventPool.borrowEvent();
    streamEventConverter.convertEvent(event, borrowedEvent);
    for (PartitionExecutor partitionExecutor : partitionExecutors) {
        String key = partitionExecutor.execute(borrowedEvent);
        send(key, borrowedEvent);
    }
    if (partitionExecutors.size() == 0) {
        send(borrowedEvent);
    }
    eventPool.returnEvents(borrowedEvent);
}
Also used : PartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 3 with PartitionExecutor

use of org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor in project ballerina by ballerina-lang.

the class StreamPartitioner method createSingleInputStreamExecutors.

private void createSingleInputStreamExecutors(SingleInputStream inputStream, Partition partition, MetaStreamEvent metaEvent, List<VariableExpressionExecutor> executors, Map<String, Table> tableMap, SiddhiAppContext siddhiAppContext, String queryName) {
    List<PartitionExecutor> executorList = new ArrayList<PartitionExecutor>();
    partitionExecutorLists.add(executorList);
    if (!inputStream.isInnerStream()) {
        for (PartitionType partitionType : partition.getPartitionTypeMap().values()) {
            if (partitionType instanceof ValuePartitionType) {
                if (partitionType.getStreamId().equals(inputStream.getStreamId())) {
                    executorList.add(new ValuePartitionExecutor(ExpressionParser.parseExpression(((ValuePartitionType) partitionType).getExpression(), metaEvent, SiddhiConstants.UNKNOWN_STATE, tableMap, executors, siddhiAppContext, false, 0, queryName)));
                }
            } else {
                for (RangePartitionType.RangePartitionProperty rangePartitionProperty : ((RangePartitionType) partitionType).getRangePartitionProperties()) {
                    if (partitionType.getStreamId().equals(inputStream.getStreamId())) {
                        executorList.add(new RangePartitionExecutor((ConditionExpressionExecutor) ExpressionParser.parseExpression(rangePartitionProperty.getCondition(), metaEvent, SiddhiConstants.UNKNOWN_STATE, tableMap, executors, siddhiAppContext, false, 0, queryName), rangePartitionProperty.getPartitionKey()));
                    }
                }
            }
        }
    }
}
Also used : ValuePartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.ValuePartitionExecutor) RangePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.ValuePartitionExecutor) RangePartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.RangePartitionExecutor) PartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor) ArrayList(java.util.ArrayList) RangePartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.RangePartitionExecutor) ValuePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType) ConditionExpressionExecutor(org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor) RangePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionType(org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType) PartitionType(org.ballerinalang.siddhi.query.api.execution.partition.PartitionType)

Example 4 with PartitionExecutor

use of org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor in project ballerina by ballerina-lang.

the class PartitionStreamReceiver method receive.

@Override
public void receive(ComplexEvent complexEvent) {
    if (partitionExecutors.size() == 0) {
        StreamEvent borrowedEvent = eventPool.borrowEvent();
        streamEventConverter.convertComplexEvent(complexEvent, borrowedEvent);
        send(borrowedEvent);
    } else {
        if (complexEvent.getNext() == null) {
            for (PartitionExecutor partitionExecutor : partitionExecutors) {
                StreamEvent borrowedEvent = eventPool.borrowEvent();
                streamEventConverter.convertComplexEvent(complexEvent, borrowedEvent);
                String key = partitionExecutor.execute(borrowedEvent);
                send(key, borrowedEvent);
            }
        } else {
            ComplexEventChunk<ComplexEvent> complexEventChunk = new ComplexEventChunk<ComplexEvent>(false);
            complexEventChunk.add(complexEvent);
            String currentKey = null;
            while (complexEventChunk.hasNext()) {
                ComplexEvent aEvent = complexEventChunk.next();
                complexEventChunk.remove();
                StreamEvent borrowedEvent = eventPool.borrowEvent();
                streamEventConverter.convertComplexEvent(aEvent, borrowedEvent);
                boolean currentEventMatchedPrevPartitionExecutor = false;
                for (PartitionExecutor partitionExecutor : partitionExecutors) {
                    String key = partitionExecutor.execute(borrowedEvent);
                    if (key != null) {
                        if (currentKey == null) {
                            currentKey = key;
                        } else if (!currentKey.equals(key)) {
                            if (!currentEventMatchedPrevPartitionExecutor) {
                                ComplexEvent firstEvent = streamEventChunk.getFirst();
                                send(currentKey, firstEvent);
                                currentKey = key;
                                streamEventChunk.clear();
                            } else {
                                ComplexEvent firstEvent = streamEventChunk.getFirst();
                                send(currentKey, firstEvent);
                                currentKey = key;
                                streamEventChunk.clear();
                                StreamEvent cloneEvent = eventPool.borrowEvent();
                                streamEventConverter.convertComplexEvent(aEvent, cloneEvent);
                                streamEventChunk.add(cloneEvent);
                            }
                        }
                        if (!currentEventMatchedPrevPartitionExecutor) {
                            streamEventChunk.add(borrowedEvent);
                        }
                        currentEventMatchedPrevPartitionExecutor = true;
                    }
                }
            }
            send(currentKey, streamEventChunk.getFirst());
            streamEventChunk.clear();
        }
    }
}
Also used : ComplexEvent(org.ballerinalang.siddhi.core.event.ComplexEvent) PartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor) ComplexEventChunk(org.ballerinalang.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent)

Example 5 with PartitionExecutor

use of org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor in project ballerina by ballerina-lang.

the class PartitionStreamReceiver method receive.

@Override
public void receive(Event[] events) {
    if (partitionExecutors.size() == 0) {
        StreamEvent currentEvent;
        StreamEvent firstEvent = eventPool.borrowEvent();
        streamEventConverter.convertEvent(events[0], firstEvent);
        currentEvent = firstEvent;
        for (int i = 1; i < events.length; i++) {
            StreamEvent nextEvent = eventPool.borrowEvent();
            streamEventConverter.convertEvent(events[i], nextEvent);
            currentEvent.setNext(nextEvent);
            currentEvent = nextEvent;
        }
        send(firstEvent);
        eventPool.returnEvents(firstEvent);
    } else {
        String key = null;
        StreamEvent firstEvent = null;
        StreamEvent currentEvent = null;
        for (Event event : events) {
            StreamEvent nextEvent = eventPool.borrowEvent();
            streamEventConverter.convertEvent(event, nextEvent);
            for (PartitionExecutor partitionExecutor : partitionExecutors) {
                String currentKey = partitionExecutor.execute(nextEvent);
                if (currentKey != null) {
                    if (key == null) {
                        key = currentKey;
                        firstEvent = nextEvent;
                    } else if (!currentKey.equals(key)) {
                        send(key, firstEvent);
                        eventPool.returnEvents(firstEvent);
                        key = currentKey;
                        firstEvent = nextEvent;
                    } else {
                        currentEvent.setNext(nextEvent);
                    }
                    currentEvent = nextEvent;
                }
            }
        }
        send(key, firstEvent);
        eventPool.returnEvents(firstEvent);
    }
}
Also used : PartitionExecutor(org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.ballerinalang.siddhi.core.event.stream.StreamEvent) 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)

Aggregations

PartitionExecutor (org.ballerinalang.siddhi.core.partition.executor.PartitionExecutor)5 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)4 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)4 ComplexEvent (org.ballerinalang.siddhi.core.event.ComplexEvent)2 ArrayList (java.util.ArrayList)1 ComplexEventChunk (org.ballerinalang.siddhi.core.event.ComplexEventChunk)1 Event (org.ballerinalang.siddhi.core.event.Event)1 ConditionExpressionExecutor (org.ballerinalang.siddhi.core.executor.condition.ConditionExpressionExecutor)1 RangePartitionExecutor (org.ballerinalang.siddhi.core.partition.executor.RangePartitionExecutor)1 ValuePartitionExecutor (org.ballerinalang.siddhi.core.partition.executor.ValuePartitionExecutor)1 PartitionType (org.ballerinalang.siddhi.query.api.execution.partition.PartitionType)1 RangePartitionType (org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType)1 ValuePartitionType (org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType)1