Search in sources :

Example 1 with PartitionExecutor

use of io.siddhi.core.partition.executor.PartitionExecutor in project siddhi by wso2.

the class StreamPartitioner method createSingleInputStreamExecutors.

private void createSingleInputStreamExecutors(SingleInputStream inputStream, Partition partition, MetaStreamEvent metaEvent, List<VariableExpressionExecutor> executors, Map<String, Table> tableMap, SiddhiQueryContext siddhiQueryContext) {
    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, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext)));
                }
            } 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, false, 0, ProcessingMode.BATCH, false, siddhiQueryContext), rangePartitionProperty.getPartitionKey()));
                    }
                }
            }
        }
    }
}
Also used : ValuePartitionExecutor(io.siddhi.core.partition.executor.ValuePartitionExecutor) RangePartitionType(io.siddhi.query.api.execution.partition.RangePartitionType) PartitionExecutor(io.siddhi.core.partition.executor.PartitionExecutor) RangePartitionExecutor(io.siddhi.core.partition.executor.RangePartitionExecutor) ValuePartitionExecutor(io.siddhi.core.partition.executor.ValuePartitionExecutor) ArrayList(java.util.ArrayList) RangePartitionExecutor(io.siddhi.core.partition.executor.RangePartitionExecutor) ValuePartitionType(io.siddhi.query.api.execution.partition.ValuePartitionType) ConditionExpressionExecutor(io.siddhi.core.executor.condition.ConditionExpressionExecutor) PartitionType(io.siddhi.query.api.execution.partition.PartitionType) ValuePartitionType(io.siddhi.query.api.execution.partition.ValuePartitionType) RangePartitionType(io.siddhi.query.api.execution.partition.RangePartitionType)

Example 2 with PartitionExecutor

use of io.siddhi.core.partition.executor.PartitionExecutor in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

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

Example 3 with PartitionExecutor

use of io.siddhi.core.partition.executor.PartitionExecutor in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

@Override
public void receive(Event event) {
    StreamEvent newEvent = streamEventFactory.newInstance();
    streamEventConverter.convertEvent(event, newEvent);
    for (PartitionExecutor partitionExecutor : partitionExecutors) {
        String key = partitionExecutor.execute(newEvent);
        send(key, newEvent);
    }
    if (partitionExecutors.size() == 0) {
        send(newEvent);
    }
}
Also used : PartitionExecutor(io.siddhi.core.partition.executor.PartitionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 4 with PartitionExecutor

use of io.siddhi.core.partition.executor.PartitionExecutor in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

@Override
public void receive(List<Event> events) {
    if (partitionExecutors.size() == 0) {
        StreamEvent firstEvent = null;
        StreamEvent currentEvent = null;
        for (Event event : events) {
            StreamEvent nextEvent = streamEventFactory.newInstance();
            streamEventConverter.convertEvent(event, nextEvent);
            if (firstEvent == null) {
                firstEvent = nextEvent;
            } else {
                currentEvent.setNext(nextEvent);
            }
            currentEvent = nextEvent;
        }
        send(firstEvent);
    } else {
        String key = null;
        StreamEvent firstEvent = null;
        StreamEvent currentEvent = null;
        for (Event event : events) {
            StreamEvent nextEvent = streamEventFactory.newInstance();
            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);
                        key = currentKey;
                        firstEvent = nextEvent;
                    } else {
                        currentEvent.setNext(nextEvent);
                    }
                    currentEvent = nextEvent;
                }
            }
        }
        send(key, firstEvent);
    }
}
Also used : PartitionExecutor(io.siddhi.core.partition.executor.PartitionExecutor) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent) Event(io.siddhi.core.event.Event) ComplexEvent(io.siddhi.core.event.ComplexEvent) StreamEvent(io.siddhi.core.event.stream.StreamEvent) MetaStreamEvent(io.siddhi.core.event.stream.MetaStreamEvent)

Example 5 with PartitionExecutor

use of io.siddhi.core.partition.executor.PartitionExecutor in project siddhi by wso2.

the class PartitionStreamReceiver method receive.

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

Aggregations

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