Search in sources :

Example 56 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class DefineStreamTestCase method testAnnotatingStreamDefinition3.

@Test
public void testAnnotatingStreamDefinition3() {
    Element element = new Element("name", "query1");
    String annotationString = "[@map( type = \"xml\", namespace = \"h=uri, a=uri\", @attributes( \"//h:time\", " + "\"//h:data\"))]";
    String elementString = "name = \"query1\"";
    Annotation annotation = Annotation.annotation("source").element("type", "http").element("context", "/test").element("transport", "http,https").annotation(Annotation.annotation("map").element("type", "xml").element("namespace", "h=uri, a=uri").annotation(Annotation.annotation("attributes").element("//h:time").element("//h:data")));
    StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).annotation(annotation.element(element));
    annotation.setName("sink");
    AssertJUnit.assertEquals(annotationString, annotation.getAnnotations().toString());
    AssertJUnit.assertEquals(annotationString, annotation.getAnnotations("map").toString());
    AssertJUnit.assertEquals("sink", annotation.getName());
    AssertJUnit.assertEquals("http", annotation.getElement("type"));
    AssertJUnit.assertEquals("name", element.getKey());
    AssertJUnit.assertEquals("query1", element.getValue());
    AssertJUnit.assertEquals(elementString, element.toString());
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Element(io.siddhi.query.api.annotation.Element) Annotation(io.siddhi.query.api.annotation.Annotation) Test(org.testng.annotations.Test)

Example 57 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class DefineStreamTestCase method testStreamDefinition5.

@Test
public void testStreamDefinition5() {
    StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT);
    String[] list = new String[] { "symbol", "price", "volume" };
    AssertJUnit.assertEquals(Arrays.toString(list), Arrays.toString(streamDefinition.getAttributeNameArray()));
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 58 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class DefineStreamTestCase method testStreamDefinition4.

@Test
public void testStreamDefinition4() {
    String attributeList = "[Attribute{id='symbol', type=STRING}, Attribute{id='price', type=INT}," + " Attribute{id='volume', type=FLOAT}]";
    StreamDefinition streamDefinition = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT);
    AssertJUnit.assertEquals(attributeList, streamDefinition.getAttributeList().toString());
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 59 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class DefineStreamTestCase method testStreamIdNull.

@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testStreamIdNull() {
    StreamDefinition streamDefinition = StreamDefinition.id(null);
    SiddhiApp.siddhiApp("Test").defineStream(streamDefinition);
}
Also used : StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) Test(org.testng.annotations.Test)

Example 60 with StreamDefinition

use of io.siddhi.query.api.definition.StreamDefinition in project siddhi by wso2.

the class SiddhiAppRuntimeBuilder method addQuery.

public String addQuery(QueryRuntimeImpl queryRuntime) {
    QueryRuntime oldQueryRuntime = queryProcessorMap.put(queryRuntime.getQueryId(), queryRuntime);
    if (oldQueryRuntime != null) {
        throw new SiddhiAppCreationException("Multiple queries with name '" + queryRuntime.getQueryId() + "' defined in Siddhi App '" + siddhiAppContext.getName() + "'", queryRuntime.getQuery().getQueryContextStartIndex(), queryRuntime.getQuery().getQueryContextEndIndex());
    }
    StreamRuntime streamRuntime = queryRuntime.getStreamRuntime();
    for (SingleStreamRuntime singleStreamRuntime : streamRuntime.getSingleStreamRuntimes()) {
        ProcessStreamReceiver processStreamReceiver = singleStreamRuntime.getProcessStreamReceiver();
        if (processStreamReceiver.toStream()) {
            StreamJunction streamJunction = streamJunctionMap.get(processStreamReceiver.getStreamId());
            if (streamJunction != null) {
                streamJunction.subscribe(processStreamReceiver);
            } else {
                throw new SiddhiAppCreationException("Expecting a stream, but provided '" + processStreamReceiver.getStreamId() + "' is not a stream");
            }
        }
    }
    OutputCallback outputCallback = queryRuntime.getOutputCallback();
    if (outputCallback != null && outputCallback instanceof InsertIntoStreamCallback) {
        InsertIntoStreamCallback insertIntoStreamCallback = (InsertIntoStreamCallback) outputCallback;
        StreamDefinition streamDefinition = insertIntoStreamCallback.getOutputStreamDefinition();
        streamDefinitionMap.putIfAbsent(streamDefinition.getId(), streamDefinition);
        DefinitionParserHelper.validateOutputStream(streamDefinition, streamDefinitionMap.get(streamDefinition.getId()));
        StreamJunction outputStreamJunction = streamJunctionMap.get(streamDefinition.getId());
        if (outputStreamJunction == null) {
            outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
            streamJunctionMap.putIfAbsent(streamDefinition.getId(), outputStreamJunction);
        }
        insertIntoStreamCallback.init(streamJunctionMap.get(insertIntoStreamCallback.getOutputStreamDefinition().getId()));
    } else if (outputCallback != null && outputCallback instanceof InsertIntoWindowCallback) {
        InsertIntoWindowCallback insertIntoWindowCallback = (InsertIntoWindowCallback) outputCallback;
        StreamDefinition streamDefinition = insertIntoWindowCallback.getOutputStreamDefinition();
        windowDefinitionMap.putIfAbsent(streamDefinition.getId(), streamDefinition);
        DefinitionParserHelper.validateOutputStream(streamDefinition, windowDefinitionMap.get(streamDefinition.getId()));
        StreamJunction outputStreamJunction = streamJunctionMap.get(streamDefinition.getId());
        if (outputStreamJunction == null) {
            outputStreamJunction = new StreamJunction(streamDefinition, siddhiAppContext.getExecutorService(), siddhiAppContext.getBufferSize(), null, siddhiAppContext);
            streamJunctionMap.putIfAbsent(streamDefinition.getId(), outputStreamJunction);
        }
        insertIntoWindowCallback.getWindow().setPublisher(streamJunctionMap.get(insertIntoWindowCallback.getOutputStreamDefinition().getId()).constructPublisher());
    }
    return queryRuntime.getQueryId();
}
Also used : ProcessStreamReceiver(io.siddhi.core.query.input.ProcessStreamReceiver) StreamDefinition(io.siddhi.query.api.definition.StreamDefinition) InsertIntoWindowCallback(io.siddhi.core.query.output.callback.InsertIntoWindowCallback) QueryRuntime(io.siddhi.core.query.QueryRuntime) SiddhiAppCreationException(io.siddhi.core.exception.SiddhiAppCreationException) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamJunction(io.siddhi.core.stream.StreamJunction) StreamRuntime(io.siddhi.core.query.input.stream.StreamRuntime) SingleStreamRuntime(io.siddhi.core.query.input.stream.single.SingleStreamRuntime) InsertIntoStreamCallback(io.siddhi.core.query.output.callback.InsertIntoStreamCallback) OutputCallback(io.siddhi.core.query.output.callback.OutputCallback)

Aggregations

StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)134 Test (org.testng.annotations.Test)116 SiddhiApp (io.siddhi.query.api.SiddhiApp)88 Event (io.siddhi.core.event.Event)86 Query (io.siddhi.query.api.execution.query.Query)85 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)84 SiddhiManager (io.siddhi.core.SiddhiManager)84 InputHandler (io.siddhi.core.stream.input.InputHandler)81 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)75 Attribute (io.siddhi.query.api.definition.Attribute)12 StreamCallback (io.siddhi.core.stream.output.StreamCallback)10 MetaStreamEvent (io.siddhi.core.event.stream.MetaStreamEvent)9 StreamEvent (io.siddhi.core.event.stream.StreamEvent)8 Partition (io.siddhi.query.api.execution.partition.Partition)7 MetaStateEvent (io.siddhi.core.event.state.MetaStateEvent)5 OutputAttribute (io.siddhi.query.api.execution.query.selection.OutputAttribute)5 StreamEventFactory (io.siddhi.core.event.stream.StreamEventFactory)4 SiddhiAppCreationException (io.siddhi.core.exception.SiddhiAppCreationException)4 VariableExpressionExecutor (io.siddhi.core.executor.VariableExpressionExecutor)4 SelectiveStreamEventConverter (io.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3