Search in sources :

Example 21 with Filter

use of org.wso2.siddhi.query.api.execution.query.input.handler.Filter in project siddhi by wso2.

the class FilterTestCase2 method testFilterQuery96.

@Test
public void testFilterQuery96() throws InterruptedException {
    log.info("Filter test96");
    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.GREATER_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, 60d });
    inputHandler.send(new Object[] { "WSO2", 70d, 40d });
    inputHandler.send(new Object[] { "WSO2", 44d, 200d });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 22 with Filter

use of org.wso2.siddhi.query.api.execution.query.input.handler.Filter in project siddhi by wso2.

the class FilterTestCase2 method testFilterQuery108.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testFilterQuery108() throws InterruptedException {
    log.info("Filter test108");
    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("price"), Compare.Operator.EQUAL, Expression.value("WS"))));
    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("StockQuote");
    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);
}
Also used : SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 23 with Filter

use of org.wso2.siddhi.query.api.execution.query.input.handler.Filter in project siddhi by wso2.

the class FilterTestCase2 method testFilterQuery98.

@Test
public void testFilterQuery98() throws InterruptedException {
    log.info("Filter test98");
    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("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(60L))));
    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, 50d, 6 });
    inputHandler.send(new Object[] { "WSO2", 70f, 60d, 2 });
    inputHandler.send(new Object[] { "WSO2", 50f, 300d, 4 });
    Thread.sleep(100);
    AssertJUnit.assertEquals(2, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 24 with Filter

use of org.wso2.siddhi.query.api.execution.query.input.handler.Filter in project siddhi by wso2.

the class FilterTestCase2 method testFilterQuery114.

// true check
@Test
public void testFilterQuery114() throws InterruptedException {
    log.info("Filter test114");
    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type.STRING).attribute("price1", Attribute.Type.FLOAT).attribute("price2", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute("quantity", Attribute.Type.INT);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.value(true)));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("price1", Expression.variable("price1")).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;
            if (count == 1) {
                AssertJUnit.assertEquals(50.0f, inEvents[0].getData()[1]);
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 50f, 60f, 60L, 6 });
    Thread.sleep(100);
    AssertJUnit.assertEquals(1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StreamDefinition(org.wso2.siddhi.query.api.definition.StreamDefinition) Query(org.wso2.siddhi.query.api.execution.query.Query) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Example 25 with Filter

use of org.wso2.siddhi.query.api.execution.query.input.handler.Filter in project siddhi by wso2.

the class FilterTestCase2 method filterTest117.

@Test
public void filterTest117() throws InterruptedException {
    log.info("filter test116");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream cseEventStream (symbol string, price float, volume long);";
    String query = "@info(name = 'query1') from cseEventStream#window.timeBatch(500) select symbol,sum(price)+5 " + "as price insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timeStamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timeStamp, inEvents, removeEvents);
            count = count + inEvents.length;
            eventArrived = true;
            if (count == 1) {
                AssertJUnit.assertEquals(1465.5, inEvents[0].getData()[1]);
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "IBM", 700f, 100L });
    inputHandler.send(new Object[] { "WSO2", 60.5f, 200L });
    inputHandler.send(new Object[] { "IBM", 700f, 100L });
    Thread.sleep(1000);
    AssertJUnit.assertEquals(1, count);
    AssertJUnit.assertTrue(eventArrived);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)180 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)128 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)128 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)119 Query (org.wso2.siddhi.query.api.execution.query.Query)119 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)112 Event (org.wso2.siddhi.core.event.Event)111 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)73 SiddhiApp (org.wso2.siddhi.query.api.SiddhiApp)72 ArrayList (java.util.ArrayList)36 List (java.util.List)34 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)26 Collectors (java.util.stream.Collectors)21 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)21 CompilerContext (org.wso2.ballerinalang.compiler.util.CompilerContext)20 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)19 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)19 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)19 Map (java.util.Map)18 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)18