Search in sources :

Example 81 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitStandard_stream.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public SingleInputStream visitStandard_stream(@NotNull SiddhiQLParser.Standard_streamContext ctx) {
    // standard_stream
    // : io (basic_source_stream_handler)* window? (basic_source_stream_handler)*
    // ;
    Source source = (Source) visit(ctx.source());
    BasicSingleInputStream basicSingleInputStream = new BasicSingleInputStream(null, source.streamId, source.isInnerStream);
    if (ctx.pre_window_handlers != null) {
        basicSingleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.pre_window_handlers));
    }
    if (ctx.window() == null && ctx.post_window_handlers == null) {
        populateQueryContext(basicSingleInputStream, ctx);
        return basicSingleInputStream;
    } else if (ctx.window() != null) {
        SingleInputStream singleInputStream = new SingleInputStream(basicSingleInputStream, (Window) visit(ctx.window()));
        if (ctx.post_window_handlers != null) {
            singleInputStream.addStreamHandlers((List<StreamHandler>) visit(ctx.post_window_handlers));
        }
        populateQueryContext(singleInputStream, ctx);
        return singleInputStream;
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : Window(org.wso2.siddhi.query.api.execution.query.input.handler.Window) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) BasicSingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.BasicSingleInputStream) StreamHandler(org.wso2.siddhi.query.api.execution.query.input.handler.StreamHandler) List(java.util.List) ArrayList(java.util.ArrayList)

Example 82 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class SimpleQueryTestCase method test12.

@Test
public void test12() throws SiddhiParserException {
    Query query = SiddhiCompiler.parseQuery("from  StockStream[price>3]#window.length(50) " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having (price >= 20)" + "order by avgPrice desc " + "limit 5 " + "insert all events into StockQuote; ");
    AssertJUnit.assertNotNull(query);
    Query api = Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(3))).window("length", Expression.value(50))).select(Selector.selector().select(Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))).orderBy(Expression.variable("avgPrice"), OrderByAttribute.Order.DESC).limit(Expression.value(5))).insertInto("StockQuote", OutputStream.OutputEventType.ALL_EVENTS);
    AssertJUnit.assertEquals(api, query);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 83 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class SimpleQueryTestCase method test7.

@Test
public void test7() {
    Query query = SiddhiCompiler.parseQuery("from  StockStream[7+9.5 < price or 100 <= volume]#window.length(50) " + " " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having avgPrice!= 50 " + "insert into OutStockStream ;");
    AssertJUnit.assertNotNull(query);
    Query api = Query.query();
    api.from(InputStream.stream("StockStream").filter(Expression.or(Expression.compare(Expression.add(Expression.value(7), Expression.value(9.5)), Compare.Operator.LESS_THAN, Expression.variable("price")), Expression.compare(Expression.value(100), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("volume")))).window("length", Expression.value(50)));
    api.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.NOT_EQUAL, Expression.value(50))));
    api.insertInto("OutStockStream");
    AssertJUnit.assertEquals(api, query);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 84 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class SimpleQueryTestCase method test2.

@Test
public void test2() throws SiddhiParserException {
    Query query = SiddhiCompiler.parseQuery("from  StockStream [price >= 20]#window.lengthBatch(50) " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having avgPrice>50 " + "insert into StockQuote; ");
    AssertJUnit.assertNotNull(query);
    Query api = Query.query().from(InputStream.stream("StockStream").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20))).window("lengthBatch", Expression.value(50))).select(Selector.selector().select(Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.GREATER_THAN, Expression.value(50)))).insertInto("StockQuote");
    AssertJUnit.assertEquals(api, query);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 85 with Window

use of org.wso2.siddhi.core.window.Window in project siddhi by wso2.

the class SimpleQueryTestCase method testCreatingReturnFilterQueryWithFunction.

@Test
public void testCreatingReturnFilterQueryWithFunction() {
    Query query = Query.query();
    query.from(InputStream.stream("StockStream").filter(Expression.and(Expression.compare(Expression.function("FooBarCond", Expression.value(7), Expression.value(9.5)), Compare.Operator.GREATER_THAN, Expression.variable("price")), Expression.function("BarCond", Expression.value(100), Expression.variable("volume")))).function("ext", "Foo", Expression.value(67), Expression.value(89)).window("ext", "lengthFirst10", Expression.value(50)));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("ext", "avg", Expression.variable("symbol"))));
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)161 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)130 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)130 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)118 Event (org.wso2.siddhi.core.event.Event)117 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)82 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)35 Query (org.wso2.siddhi.query.api.execution.query.Query)32 StreamEvent (org.wso2.siddhi.core.event.stream.StreamEvent)14 MetaStreamEvent (org.wso2.siddhi.core.event.stream.MetaStreamEvent)12 ArrayList (java.util.ArrayList)10 InMemoryPersistenceStore (org.wso2.siddhi.core.util.persistence.InMemoryPersistenceStore)10 PersistenceStore (org.wso2.siddhi.core.util.persistence.PersistenceStore)10 ComplexEvent (org.wso2.siddhi.core.event.ComplexEvent)9 CannotRestoreSiddhiAppStateException (org.wso2.siddhi.core.exception.CannotRestoreSiddhiAppStateException)9 VariableExpressionExecutor (org.wso2.siddhi.core.executor.VariableExpressionExecutor)8 SiddhiAppValidationException (org.wso2.siddhi.query.api.exception.SiddhiAppValidationException)8 Window (org.wso2.siddhi.core.window.Window)7 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)6 ConstantExpressionExecutor (org.wso2.siddhi.core.executor.ConstantExpressionExecutor)6