Search in sources :

Example 71 with StreamDefinition

use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.

the class FilterTestCase1 method testFilterQuery74.

@Test
public void testFilterQuery74() throws InterruptedException {
    log.info("Filter test74");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.DOUBLE).attribute("quantity", Attribute.Type.INT);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("quantity"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(5f))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("quantity", Expression.variable("quantity")));
    query.insertInto("outputStream");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 500f, 60d, 6 });
    inputHandler.send(new Object[] { "WSO2", 70f, 60d, 2 });
    inputHandler.send(new Object[] { "WSO2", 60f, 300d, 4 });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) SiddhiApp(org.ballerinalang.siddhi.query.api.SiddhiApp) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Query(org.ballerinalang.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 72 with StreamDefinition

use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.

the class FilterTestCase1 method testFilterQuery82.

@Test
public void testFilterQuery82() throws InterruptedException {
    log.info("Filter test82");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.DOUBLE);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN, Expression.value(50))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
    query.insertInto("outputStream");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50d, 60d });
    inputHandler.send(new Object[] { "WSO2", 70d, 40d });
    inputHandler.send(new Object[] { "WSO2", 44d, 200d });
    Thread.sleep(100);
    AssertJUnit.assertEquals(1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) SiddhiApp(org.ballerinalang.siddhi.query.api.SiddhiApp) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Query(org.ballerinalang.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 73 with StreamDefinition

use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.

the class FilterTestCase1 method testFilterQuery17.

@Test
public void testFilterQuery17() throws InterruptedException {
    log.info("Filter test17");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.GREATER_THAN, Expression.value(45))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")).select("volume", Expression.variable("volume")));
    query.insertInto("outputStream");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60L });
    inputHandler.send(new Object[] { "WSO2", 70f, 40L });
    inputHandler.send(new Object[] { "WSO2", 44f, 200L });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) SiddhiApp(org.ballerinalang.siddhi.query.api.SiddhiApp) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Query(org.ballerinalang.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 74 with StreamDefinition

use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.

the class FilterTestCase1 method testFilterQuery77.

@Test
public void testFilterQuery77() throws InterruptedException {
    log.info("Filter test77");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(50f))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
    query.insertInto("outputStream");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60L });
    inputHandler.send(new Object[] { "WSO2", 70f, 40L });
    inputHandler.send(new Object[] { "WSO2", 44f, 200L });
    Thread.sleep(100);
    AssertJUnit.assertEquals(1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) SiddhiApp(org.ballerinalang.siddhi.query.api.SiddhiApp) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Query(org.ballerinalang.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 75 with StreamDefinition

use of org.ballerinalang.siddhi.query.api.definition.StreamDefinition in project ballerina by ballerina-lang.

the class FilterTestCase1 method testFilterQuery69.

@Test
public void testFilterQuery69() throws InterruptedException {
    log.info("Filter test69");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.DOUBLE).attribute("volume", Attribute.Type.LONG);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.LESS_THAN_EQUAL, Expression.value(50))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price", Expression.variable("price")));
    query.insertInto("outputStream");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count = count + inEvents.length;
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50d, 60L });
    inputHandler.send(new Object[] { "WSO2", 70d, 40L });
    inputHandler.send(new Object[] { "WSO2", 44d, 200L });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.ballerinalang.siddhi.core.stream.input.InputHandler) SiddhiApp(org.ballerinalang.siddhi.query.api.SiddhiApp) StreamDefinition(org.ballerinalang.siddhi.query.api.definition.StreamDefinition) Query(org.ballerinalang.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.ballerinalang.siddhi.core.SiddhiAppRuntime) Event(org.ballerinalang.siddhi.core.event.Event) SiddhiManager(org.ballerinalang.siddhi.core.SiddhiManager) QueryCallback(org.ballerinalang.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

StreamDefinition (org.ballerinalang.siddhi.query.api.definition.StreamDefinition)110 Test (org.testng.annotations.Test)98 Event (org.ballerinalang.siddhi.core.event.Event)83 Query (org.ballerinalang.siddhi.query.api.execution.query.Query)82 SiddhiAppRuntime (org.ballerinalang.siddhi.core.SiddhiAppRuntime)80 SiddhiManager (org.ballerinalang.siddhi.core.SiddhiManager)80 SiddhiApp (org.ballerinalang.siddhi.query.api.SiddhiApp)80 InputHandler (org.ballerinalang.siddhi.core.stream.input.InputHandler)77 QueryCallback (org.ballerinalang.siddhi.core.query.output.callback.QueryCallback)73 StreamCallback (org.ballerinalang.siddhi.core.stream.output.StreamCallback)9 MetaStreamEvent (org.ballerinalang.siddhi.core.event.stream.MetaStreamEvent)8 StreamEvent (org.ballerinalang.siddhi.core.event.stream.StreamEvent)8 Attribute (org.ballerinalang.siddhi.query.api.definition.Attribute)8 MetaStateEvent (org.ballerinalang.siddhi.core.event.state.MetaStateEvent)5 StreamEventPool (org.ballerinalang.siddhi.core.event.stream.StreamEventPool)5 ArrayList (java.util.ArrayList)3 SelectiveStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SelectiveStreamEventConverter)3 SimpleStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.SimpleStreamEventConverter)3 StreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.StreamEventConverter)3 ZeroStreamEventConverter (org.ballerinalang.siddhi.core.event.stream.converter.ZeroStreamEventConverter)3