Search in sources :

Example 1 with PartitionExecutor

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

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.wso2.siddhi.core.partition.executor.PartitionExecutor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 2 with PartitionExecutor

use of org.wso2.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) {
        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.wso2.siddhi.core.event.ComplexEvent) PartitionExecutor(org.wso2.siddhi.core.partition.executor.PartitionExecutor) ComplexEventChunk(org.wso2.siddhi.core.event.ComplexEventChunk) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 3 with PartitionExecutor

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

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.wso2.siddhi.core.partition.executor.PartitionExecutor) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent) StreamEvent(org.wso2.siddhi.core.event.stream.StreamEvent)

Example 4 with PartitionExecutor

use of org.wso2.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, 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.wso2.siddhi.core.partition.executor.ValuePartitionExecutor) RangePartitionType(org.wso2.siddhi.query.api.execution.partition.RangePartitionType) RangePartitionExecutor(org.wso2.siddhi.core.partition.executor.RangePartitionExecutor) ValuePartitionExecutor(org.wso2.siddhi.core.partition.executor.ValuePartitionExecutor) PartitionExecutor(org.wso2.siddhi.core.partition.executor.PartitionExecutor) ArrayList(java.util.ArrayList) RangePartitionExecutor(org.wso2.siddhi.core.partition.executor.RangePartitionExecutor) ValuePartitionType(org.wso2.siddhi.query.api.execution.partition.ValuePartitionType) ConditionExpressionExecutor(org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor) PartitionType(org.wso2.siddhi.query.api.execution.partition.PartitionType) RangePartitionType(org.wso2.siddhi.query.api.execution.partition.RangePartitionType) ValuePartitionType(org.wso2.siddhi.query.api.execution.partition.ValuePartitionType)

Example 5 with PartitionExecutor

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

the class PartitionRuntime method addPartitionReceiver.

public void addPartitionReceiver(QueryRuntime queryRuntime, List<VariableExpressionExecutor> executors, MetaStateEvent metaEvent) {
    Query query = queryRuntime.getQuery();
    List<List<PartitionExecutor>> partitionExecutors = new StreamPartitioner(query.getInputStream(), partition, metaEvent, executors, siddhiAppContext, null).getPartitionExecutorLists();
    if (queryRuntime.getStreamRuntime() instanceof SingleStreamRuntime) {
        SingleInputStream singleInputStream = (SingleInputStream) query.getInputStream();
        addPartitionReceiver(singleInputStream.getStreamId(), singleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
    } else if (queryRuntime.getStreamRuntime() instanceof JoinStreamRuntime) {
        SingleInputStream leftSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getLeftInputStream();
        addPartitionReceiver(leftSingleInputStream.getStreamId(), leftSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(0), partitionExecutors.get(0));
        SingleInputStream rightSingleInputStream = (SingleInputStream) ((JoinInputStream) query.getInputStream()).getRightInputStream();
        addPartitionReceiver(rightSingleInputStream.getStreamId(), rightSingleInputStream.isInnerStream(), metaEvent.getMetaStreamEvent(1), partitionExecutors.get(1));
    } else if (queryRuntime.getStreamRuntime() instanceof StateStreamRuntime) {
        StateElement stateElement = ((StateInputStream) query.getInputStream()).getStateElement();
        addPartitionReceiverForStateElement(stateElement, metaEvent, partitionExecutors, 0);
    }
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinStreamRuntime(org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) StateElement(org.wso2.siddhi.query.api.execution.query.input.state.StateElement) CountStateElement(org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement) LogicalStateElement(org.wso2.siddhi.query.api.execution.query.input.state.LogicalStateElement) EveryStateElement(org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement) StreamStateElement(org.wso2.siddhi.query.api.execution.query.input.state.StreamStateElement) NextStateElement(org.wso2.siddhi.query.api.execution.query.input.state.NextStateElement) ArrayList(java.util.ArrayList) List(java.util.List) StateInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.StateInputStream) StateStreamRuntime(org.wso2.siddhi.core.query.input.stream.state.StateStreamRuntime)

Aggregations

PartitionExecutor (org.wso2.siddhi.core.partition.executor.PartitionExecutor)5 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)4 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)4 ArrayList (java.util.ArrayList)2 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)2 List (java.util.List)1 ComplexEventChunk (org.wso2.siddhi.core.event.ComplexEventChunk)1 Event (org.wso2.siddhi.core.event.Event)1 ConditionExpressionExecutor (org.wso2.siddhi.core.executor.condition.ConditionExpressionExecutor)1 RangePartitionExecutor (org.wso2.siddhi.core.partition.executor.RangePartitionExecutor)1 ValuePartitionExecutor (org.wso2.siddhi.core.partition.executor.ValuePartitionExecutor)1 JoinStreamRuntime (org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime)1 SingleStreamRuntime (org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime)1 StateStreamRuntime (org.wso2.siddhi.core.query.input.stream.state.StateStreamRuntime)1 PartitionType (org.wso2.siddhi.query.api.execution.partition.PartitionType)1 RangePartitionType (org.wso2.siddhi.query.api.execution.partition.RangePartitionType)1 ValuePartitionType (org.wso2.siddhi.query.api.execution.partition.ValuePartitionType)1 Query (org.wso2.siddhi.query.api.execution.query.Query)1 CountStateElement (org.wso2.siddhi.query.api.execution.query.input.state.CountStateElement)1 EveryStateElement (org.wso2.siddhi.query.api.execution.query.input.state.EveryStateElement)1