Search in sources :

Example 6 with SingleStreamRuntime

use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.

the class EventTestCase method testQueryParser.

@Test
public void testQueryParser() {
    StreamDefinition streamDefinition = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.INT);
    StreamDefinition outStreamDefinition = StreamDefinition.id("outputStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT);
    Query query = new Query();
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.NOT_EQUAL, Expression.value(50))));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
    query.insertInto("outputStream");
    Map<String, AbstractDefinition> tableDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> windowDefinitionMap = new HashMap<>();
    Map<String, AbstractDefinition> aggregationDefinitionMap = new HashMap<>();
    Map<String, Table> tableMap = new HashMap<String, Table>();
    Map<String, Window> eventWindowMap = new HashMap<String, Window>();
    Map<String, AggregationRuntime> aggregationMap = new HashMap<String, AggregationRuntime>();
    Map<String, List<Source>> eventSourceMap = new HashMap<String, List<Source>>();
    Map<String, List<Sink>> eventSinkMap = new HashMap<String, List<Sink>>();
    Map<String, AbstractDefinition> streamDefinitionMap = new HashMap<String, AbstractDefinition>();
    LockSynchronizer lockSynchronizer = new LockSynchronizer();
    streamDefinitionMap.put("cseEventStream", streamDefinition);
    streamDefinitionMap.put("outputStream", outStreamDefinition);
    SiddhiContext siddhicontext = new SiddhiContext();
    SiddhiAppContext context = new SiddhiAppContext();
    context.setSiddhiContext(siddhicontext);
    context.setElementIdGenerator(new ElementIdGenerator(context.getName()));
    context.setSnapshotService(new SnapshotService(context));
    QueryRuntime runtime = QueryParser.parse(query, context, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, aggregationMap, eventWindowMap, lockSynchronizer, "1");
    AssertJUnit.assertNotNull(runtime);
    AssertJUnit.assertTrue(runtime.getStreamRuntime() instanceof SingleStreamRuntime);
    AssertJUnit.assertNotNull(runtime.getSelector());
    AssertJUnit.assertTrue(runtime.getMetaComplexEvent() instanceof MetaStreamEvent);
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) HashMap(java.util.HashMap) ElementIdGenerator(org.ballerinalang.siddhi.core.util.ElementIdGenerator) Source(org.ballerinalang.siddhi.core.stream.input.source.Source) SiddhiContext(org.ballerinalang.siddhi.core.config.SiddhiContext) Sink(org.ballerinalang.siddhi.core.stream.output.sink.Sink) QueryRuntime(org.ballerinalang.siddhi.core.query.QueryRuntime) LockSynchronizer(org.ballerinalang.siddhi.core.util.lock.LockSynchronizer) List(java.util.List) AggregationRuntime(org.ballerinalang.siddhi.core.aggregation.AggregationRuntime) Window(org.ballerinalang.siddhi.core.window.Window) SnapshotService(org.ballerinalang.siddhi.core.util.snapshot.SnapshotService) Table(org.ballerinalang.siddhi.core.table.Table) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) AbstractDefinition(org.ballerinalang.siddhi.query.api.definition.AbstractDefinition) SiddhiAppContext(org.ballerinalang.siddhi.core.config.SiddhiAppContext) MetaStreamEvent(org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent) Test(org.testng.annotations.Test)

Example 7 with SingleStreamRuntime

use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.query.api.execution.query.Query) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) SingleInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.SingleInputStream) JoinStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.join.JoinStreamRuntime) JoinInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.JoinInputStream) EveryStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.EveryStateElement) LogicalStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.LogicalStateElement) StateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StateElement) NextStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.NextStateElement) CountStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement) StreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement) ArrayList(java.util.ArrayList) List(java.util.List) StateInputStream(org.ballerinalang.siddhi.query.api.execution.query.input.stream.StateInputStream) StateStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.state.StateStreamRuntime)

Example 8 with SingleStreamRuntime

use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.

the class JoinStreamRuntime method clone.

@Override
public StreamRuntime clone(String key) {
    JoinStreamRuntime joinStreamRuntime = new JoinStreamRuntime(siddhiAppContext, metaStateEvent);
    for (SingleStreamRuntime singleStreamRuntime : singleStreamRuntimeList) {
        joinStreamRuntime.addRuntime((SingleStreamRuntime) singleStreamRuntime.clone(key));
    }
    SingleStreamRuntime leftSingleStreamRuntime = joinStreamRuntime.getSingleStreamRuntimes().get(0);
    SingleStreamRuntime rightSingleStreamRuntime = joinStreamRuntime.getSingleStreamRuntimes().get(1);
    Processor lastLeftProcessor = leftSingleStreamRuntime.getProcessorChain();
    while (!(lastLeftProcessor instanceof JoinProcessor)) {
        lastLeftProcessor = lastLeftProcessor.getNextProcessor();
    }
    JoinProcessor leftPreJoinProcessor = (JoinProcessor) lastLeftProcessor;
    WindowProcessor leftWindowProcessor = (WindowProcessor) leftPreJoinProcessor.getNextProcessor();
    JoinProcessor leftPostJoinProcessor = (JoinProcessor) leftWindowProcessor.getNextProcessor();
    Processor lastRightProcessor = rightSingleStreamRuntime.getProcessorChain();
    while (!(lastRightProcessor instanceof JoinProcessor)) {
        lastRightProcessor = lastRightProcessor.getNextProcessor();
    }
    JoinProcessor rightPreJoinProcessor = (JoinProcessor) lastRightProcessor;
    WindowProcessor rightWindowProcessor = (WindowProcessor) rightPreJoinProcessor.getNextProcessor();
    JoinProcessor rightPostJoinProcessor = (JoinProcessor) rightWindowProcessor.getNextProcessor();
    rightPostJoinProcessor.setFindableProcessor((FindableProcessor) leftWindowProcessor);
    rightPreJoinProcessor.setFindableProcessor((FindableProcessor) leftWindowProcessor);
    leftPreJoinProcessor.setFindableProcessor((FindableProcessor) rightWindowProcessor);
    leftPostJoinProcessor.setFindableProcessor((FindableProcessor) rightWindowProcessor);
    return joinStreamRuntime;
}
Also used : Processor(org.ballerinalang.siddhi.core.query.processor.Processor) FindableProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.FindableProcessor) WindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) WindowProcessor(org.ballerinalang.siddhi.core.query.processor.stream.window.WindowProcessor)

Example 9 with SingleStreamRuntime

use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.

the class StreamInnerStateRuntime method clone.

@Override
public InnerStateRuntime clone(String key) {
    StreamInnerStateRuntime streamInnerStateRuntime = new StreamInnerStateRuntime(stateType);
    for (SingleStreamRuntime singleStreamRuntime : singleStreamRuntimeList) {
        streamInnerStateRuntime.singleStreamRuntimeList.add((SingleStreamRuntime) singleStreamRuntime.clone(key));
    }
    Processor processor = streamInnerStateRuntime.singleStreamRuntimeList.get(0).getProcessorChain();
    streamInnerStateRuntime.firstProcessor = (StreamPreStateProcessor) processor;
    while (processor != null) {
        if (processor instanceof StreamPostStateProcessor) {
            streamInnerStateRuntime.lastProcessor = (StreamPostStateProcessor) processor;
            break;
        } else {
            processor = processor.getNextProcessor();
        }
    }
    ((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor).setThisStatePreProcessor((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor);
    ((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor).setThisStatePostProcessor((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor);
    ((StreamPreStateProcessor) streamInnerStateRuntime.firstProcessor).setThisLastProcessor((StreamPostStateProcessor) streamInnerStateRuntime.lastProcessor);
    return streamInnerStateRuntime;
}
Also used : Processor(org.ballerinalang.siddhi.core.query.processor.Processor) StreamPostStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.StreamPostStateProcessor) StreamPreStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor) PostStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.PostStateProcessor) PreStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.PreStateProcessor) StreamPostStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.StreamPostStateProcessor) SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamPreStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.StreamPreStateProcessor)

Example 10 with SingleStreamRuntime

use of org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime in project ballerina by ballerina-lang.

the class LogicalInnerStateRuntime method clone.

@Override
public InnerStateRuntime clone(String key) {
    InnerStateRuntime clonedInnerStateRuntime1 = innerStateRuntime1.clone(key);
    InnerStateRuntime clonedInnerStateRuntime2 = innerStateRuntime2.clone(key);
    LogicalPreStateProcessor logicalPreStateProcessor1 = (LogicalPreStateProcessor) clonedInnerStateRuntime1.getFirstProcessor();
    LogicalPostStateProcessor logicalPostStateProcessor1 = (LogicalPostStateProcessor) clonedInnerStateRuntime1.getLastProcessor();
    LogicalPreStateProcessor logicalPreStateProcessor2 = (LogicalPreStateProcessor) clonedInnerStateRuntime2.getFirstProcessor();
    LogicalPostStateProcessor logicalPostStateProcessor2 = (LogicalPostStateProcessor) clonedInnerStateRuntime2.getLastProcessor();
    logicalPostStateProcessor1.setPartnerPreStateProcessor(logicalPreStateProcessor2);
    logicalPostStateProcessor2.setPartnerPreStateProcessor(logicalPreStateProcessor1);
    logicalPostStateProcessor1.setPartnerPostStateProcessor(logicalPostStateProcessor2);
    logicalPostStateProcessor2.setPartnerPostStateProcessor(logicalPostStateProcessor1);
    logicalPreStateProcessor1.setPartnerStatePreProcessor(logicalPreStateProcessor2);
    logicalPreStateProcessor2.setPartnerStatePreProcessor(logicalPreStateProcessor1);
    LogicalInnerStateRuntime logicalInnerStateRuntime = new LogicalInnerStateRuntime(clonedInnerStateRuntime1, clonedInnerStateRuntime2, stateType);
    logicalInnerStateRuntime.firstProcessor = clonedInnerStateRuntime1.getFirstProcessor();
    logicalInnerStateRuntime.lastProcessor = clonedInnerStateRuntime2.getLastProcessor();
    logicalInnerStateRuntime.getSingleStreamRuntimeList().addAll(clonedInnerStateRuntime2.getSingleStreamRuntimeList());
    logicalInnerStateRuntime.getSingleStreamRuntimeList().addAll(clonedInnerStateRuntime1.getSingleStreamRuntimeList());
    List<SingleStreamRuntime> runtimeList = logicalInnerStateRuntime.getSingleStreamRuntimeList();
    for (int i = 0; i < runtimeList.size(); i++) {
        String streamId = runtimeList.get(i).getProcessStreamReceiver().getStreamId();
        for (int j = i; j < runtimeList.size(); j++) {
            if (streamId.equals(runtimeList.get(j).getProcessStreamReceiver().getStreamId())) {
                runtimeList.get(j).setProcessStreamReceiver(runtimeList.get(i).getProcessStreamReceiver());
            }
        }
    }
    return logicalInnerStateRuntime;
}
Also used : SingleStreamRuntime(org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime) LogicalPreStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.LogicalPreStateProcessor) LogicalPostStateProcessor(org.ballerinalang.siddhi.core.query.input.stream.state.LogicalPostStateProcessor)

Aggregations

SingleStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.single.SingleStreamRuntime)14 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)6 ArrayList (java.util.ArrayList)4 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)4 QueryRuntime (org.ballerinalang.siddhi.core.query.QueryRuntime)4 StreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.StreamRuntime)4 SiddhiAppCreationException (org.ballerinalang.siddhi.core.exception.SiddhiAppCreationException)3 VariableExpressionExecutor (org.ballerinalang.siddhi.core.executor.VariableExpressionExecutor)3 JoinStreamRuntime (org.ballerinalang.siddhi.core.query.input.stream.join.JoinStreamRuntime)3 OutputCallback (org.ballerinalang.siddhi.core.query.output.callback.OutputCallback)3 Processor (org.ballerinalang.siddhi.core.query.processor.Processor)3 Scheduler (org.ballerinalang.siddhi.core.util.Scheduler)3 List (java.util.List)2 ReentrantLock (java.util.concurrent.locks.ReentrantLock)2 AggregationRuntime (org.ballerinalang.siddhi.core.aggregation.AggregationRuntime)2 OperationNotSupportedException (org.ballerinalang.siddhi.core.exception.OperationNotSupportedException)2 ProcessStreamReceiver (org.ballerinalang.siddhi.core.query.input.ProcessStreamReceiver)2 EntryValveProcessor (org.ballerinalang.siddhi.core.query.input.stream.single.EntryValveProcessor)2 LogicalPostStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.LogicalPostStateProcessor)2 LogicalPreStateProcessor (org.ballerinalang.siddhi.core.query.input.stream.state.LogicalPreStateProcessor)2