io.siddhi.query.api.execution.query.selection.Selector Java Examples

The following examples show how to use io.siddhi.query.api.execution.query.selection.Selector. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppCreationException.class)
public void testFilterQuery48() throws InterruptedException {
    log.info("Filter test48");

    SiddhiManager siddhiManager = new SiddhiManager();

    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("available", Attribute.Type.BOOL);
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").
            filter(Expression.not(Expression.variable("price"))));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("price", Expression.variable("price")).
                    select("available", Expression.variable("available"))
    );
    query.insertInto("StockQuote");

    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.defineStream(cseEventStream);
    siddhiApp.addQuery(query);
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp);

}
 
Example #2
Source File: DefineAggregationTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void test1() throws SiddhiParserException {

    AggregationDefinition aggregationDefinitionQuery = SiddhiCompiler
            .parseAggregationDefinition("define aggregation StockAggregation " + "from StockStream "
                    + "select StockStream.timestamp as timestamp, StockStream.symbol as symbol, "
                    + "       StockStream.price as price " + "   group by StockStream.symbol "
                    + "aggregate by timestamp " + "every seconds ... days ;");

    AggregationDefinition aggregationDefinition = AggregationDefinition.id("StockAggregation")
            .from(InputStream.stream("StockStream"))
            .select(Selector.basicSelector()
                    .select("timestamp", Expression.variable("timestamp").ofStream("StockStream"))
                    .select("symbol", Expression.variable("symbol").ofStream("StockStream"))
                    .select("price", Expression.variable("price").ofStream("StockStream"))
                    .groupBy(Expression.variable("symbol").ofStream("StockStream")))
            .aggregateBy(Expression.variable("timestamp"))
            .every(TimePeriod.range(TimePeriod.Duration.SECONDS, TimePeriod.Duration.DAYS));

    AssertJUnit.assertEquals(aggregationDefinition, aggregationDefinitionQuery);
}
 
Example #3
Source File: DefineAggregationTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefineAggregation6() {
    AggregationDefinition aggregationDefinition = AggregationDefinition.id("StockAggregation")
            .from(InputStream.stream("StockStream"))
            .select(Selector.basicSelector()
                    .select("timestamp", Expression.variable("timestamp").ofStream("StockStream"))
                    .select("symbol", Expression.variable("symbol").ofStream("StockStream"))
                    .select("price", Expression.variable("price").ofStream("StockStream"))
                    .groupBy(Expression.variable("price").ofStream("StockStream")));

    AggregationDefinition aggregationDefinition1 = AggregationDefinition.id("StockAggregation")
            .from(InputStream.stream("StockStream"))
            .select(Selector.basicSelector()
                    .select("timestamp", Expression.variable("timestamp").ofStream("StockStream"))
                    .select("symbol", Expression.variable("symbol").ofStream("StockStream"))
                    .select("price", Expression.variable("price").ofStream("StockStream"))
                    .groupBy(Expression.variable("price").ofStream("StockStream")));


    Assert.assertEquals(aggregationDefinition, aggregationDefinition1);
    Assert.assertEquals(aggregationDefinition.hashCode(), aggregationDefinition1.hashCode());
    Assert.assertTrue(aggregationDefinition.equals(aggregationDefinition1));
}
 
Example #4
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuery9() {
    Query query = Query.query();
    query.from(
            InputStream.faultStream("StockStream").
                    filter(
                            Expression.isNullInnerStream("StockStream")
                    )
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).
                    groupBy(Expression.variable("symbol")).
                    having(Expression.compare(Expression.variable("avgPrice"),
                            Compare.Operator.GREATER_THAN_EQUAL,
                            Expression.value(50)
                    ))
    );
    query.insertIntoFault("OutStockStream");

    SiddhiApp.siddhiApp("test").addQuery(query);
}
 
Example #5
Source File: AbsentPatternTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void test4() throws SiddhiParserException {
    Query query = SiddhiCompiler.parseQuery("from e1=Stream1[price>20] -> not Stream2[price>e1.price] for 2 sec " +
            "select e1.symbol as symbol1 " +
            "insert into OutputStream ;");
    AssertJUnit.assertNotNull(query);

    Query api = Query.query();
    api.from(
            InputStream.patternStream(State.next(
                    State.stream(InputStream.stream("e1", "Stream1")
                            .filter(Expression.compare(Expression.variable("price"),
                                    Compare.Operator.GREATER_THAN,
                                    Expression.value(20)))),
                    State.logicalNot(State.stream(InputStream.stream("Stream2")
                                    .filter(Expression.compare(Expression.variable("price"),
                                            Compare.Operator.GREATER_THAN,
                                            Expression.variable("price").ofStream("e1")))),
                            new TimeConstant(2000)))
            ))
            .select(Selector.selector().select("symbol1", Expression.variable("symbol").ofStream("e1")))
            .insertInto("OutputStream");

    AssertJUnit.assertEquals(api, query);
}
 
Example #6
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@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")))
    );

}
 
Example #7
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreatingReturnFilterQueryWithExtension() {
    Query query = Query.query();
    query.from(
            InputStream.stream("StockStream").
                    filter(Expression.and(Expression.compare(Expression.function("ext", "FooBarCond", Expression
                                    .value(7), Expression.value(9.5)),
                            Compare.Operator.GREATER_THAN,
                            Expression.variable("price")),
                            Expression.function("ext", "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("price")))
    );

}
 
Example #8
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@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")))
    );

}
 
Example #9
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreatingReturnFilterQueryLimitOffsetAndSort() {
    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"))).
                    orderBy(Expression.variable("avgPrice"), OrderByAttribute.Order.DESC).
                    limit(Expression.value(5)).offset(Expression.value(2))
    );

}
 
Example #10
Source File: OnDemandQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void test6() {
    StoreQuery storeQuery = StoreQuery.query();
    storeQuery.
            from(
                    InputStore.store("StockTable")).
            select(
                    Selector.selector().
                            select("symbol", Expression.variable("symbol")).
                            select("price", Expression.variable("price"))
            ).
            updateBy("StockTable", UpdateStream.updateSet().
                    set(
                            Expression.variable("symbol").ofStream("StockStream"),
                            Expression.variable("symbol")).
                    set(
                            Expression.variable("price").ofStream("StockStream"),
                            Expression.variable("price")), Expression.compare(
                    Expression.variable("symbol"),
                    Compare.Operator.EQUAL,
                    Expression.variable("symbol")));
}
 
Example #11
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuery6() {
    Query query = Query.query();
    query.from(
            InputStream.faultStream("StockStream").
                    filter(
                            Expression.isNullFaultStream("StockStream")
                    )
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).
                    groupBy(Expression.variable("symbol")).
                    having(Expression.compare(Expression.variable("avgPrice"),
                            Compare.Operator.GREATER_THAN_EQUAL,
                            Expression.value(50)
                    ))
    );
    query.insertIntoFault("OutStockStream");

    SiddhiApp.siddhiApp("test").addQuery(query);
}
 
Example #12
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void test5() throws SiddhiParserException {
    Query query = SiddhiCompiler.parseQuery("from  AllStockQuotes[price==Foo.price and Foo.try<5]  " +
            "select symbol, avg(price) as avgPrice " +
            "return ;"
    );
    AssertJUnit.assertNotNull(query);
    Query api = Query.query().from(InputStream.stream("AllStockQuotes").
            filter(Expression.and(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL,
                    Expression.variable("price").ofStream("Foo")), Expression.compare(Expression.variable("try")
                    .ofStream("Foo"), Compare.Operator.LESS_THAN, Expression.value(5))))).
            select(Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.function("avg", Expression.variable("price"))));
    AssertJUnit.assertEquals(api, query);
}
 
Example #13
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void test4() throws SiddhiParserException {
    Query query = SiddhiCompiler.parseQuery("from  AllStockQuotes#window.lengthBatch(50)  " +
            "select symbol, avg(price) as avgPrice " +
            "return ;"
    );
    AssertJUnit.assertNotNull(query);

    Query api = Query.query().from(InputStream.stream("AllStockQuotes").
            window("lengthBatch", Expression.value(50))).
            select(Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.function("avg", Expression.variable("price")))).
            returns();
    AssertJUnit.assertEquals(api, query);
}
 
Example #14
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testQuery7() {
    Query query = Query.query();
    query.from(
            InputStream.faultStream("StockStream").
                    filter(
                            Expression.isNullFaultStream("StockStream", 1)
                    )
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).
                    groupBy(Expression.variable("symbol")).
                    having(Expression.compare(Expression.variable("avgPrice"),
                            Compare.Operator.GREATER_THAN_EQUAL,
                            Expression.value(50)
                    ))
    );
    query.insertIntoFault("OutStockStream");

    SiddhiApp.siddhiApp("test").addQuery(query);
}
 
Example #15
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreatingNestedFilterQuery2() {
    Query query = Query.query();
    query.from(InputStream.stream(
            Query.query().
                    from(InputStream.stream("StockStream").
                            filter(
                                    Expression.compare(
                                            Expression.variable("price").ofStream("StockStream"),
                                            Compare.Operator.GREATER_THAN_EQUAL,
                                            Expression.value(20))
                            ).filter(Expression.isNull(Expression.variable("price").ofStream("StockStream")))).
                    select(
                            Selector.selector().
                                    select("symbol", Expression.variable("symbol")).
                                    select("avgPrice", Expression.function("avg", Expression.variable("price")))
                    ).
                    returns(OutputStream.OutputEventType.CURRENT_EVENTS))
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.variable("avgPrice"))
    );
    query.insertInto("IBMOutStockStream");
}
 
Example #16
Source File: OnDemandQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void test1() {
    StoreQuery.query().
            from(
                    InputStore.store("cseEventTable")).
            select(
                    Selector.selector().
                            select("symbol", Expression.variable("symbol")).
                            select(Expression.variable("price")).
                            groupBy(Expression.variable("symbol")).
                            having(
                                    Expression.compare(
                                            Expression.add(Expression.value(7), Expression.value(9.5)),
                                            Compare.Operator.GREATER_THAN,
                                            Expression.variable("price"))
                            )
            );
}
 
Example #17
Source File: SimpleQueryTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testQuery11() {
    Query query = new Query();
    query.from(InputStream.stream("cseEventStream"));
    query.annotation(Annotation.annotation("info").element("name", "query1"));
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("price", Expression.variable("price"))
    );
    query.insertInto("StockQuote");

    SiddhiApp siddhiApp = new SiddhiApp("ep1");
    siddhiApp.addQuery(query);
    siddhiApp.addQuery(query);
}
 
Example #18
Source File: OutputRateTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatingQuery() {
    Query query = Query.query();
    query.from(
            InputStream.stream("cseEventStream").
                    filter(Expression.and(Expression.compare(Expression.add(Expression.value(7), Expression.value
                                    (9.5)),
                            Compare.Operator.GREATER_THAN,
                            Expression.variable("price")),
                            Expression.compare(Expression.value(100),
                                    Compare.Operator.GREATER_THAN_EQUAL,
                                    Expression.variable("volume")
                            )
                            )
                    ).window("lengthBatch", Expression.value(50))
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).
                    groupBy(Expression.variable("symbol")).
                    having(Expression.compare(Expression.variable("avgPrice"),
                            Compare.Operator.GREATER_THAN_EQUAL,
                            Expression.value(50)
                    ))
    );

    query.output(OutputRate.perEvents(Expression.value(5)).output(OutputRate.Type.ALL));
    query.insertInto("StockQuote");

}
 
Example #19
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery84() throws InterruptedException {
    log.info("Filter test84");

    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.LESS_THAN,
            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.addAndGet(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});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    AssertJUnit.assertEquals(1, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #20
Source File: OutputRateTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatingQuery3() {
    Query query = Query.query();
    query.from(
            InputStream.stream("cseEventStream").
                    filter(Expression.and(Expression.compare(Expression.add(Expression.value(7), Expression.value
                                    (9.5)),
                            Compare.Operator.GREATER_THAN,
                            Expression.variable("price")),
                            Expression.compare(Expression.value(100),
                                    Compare.Operator.GREATER_THAN_EQUAL,
                                    Expression.variable("volume")
                            )
                            )
                    ).window("lengthBatch", Expression.value(50))
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).
                    groupBy(Expression.variable("symbol")).
                    having(Expression.compare(Expression.variable("avgPrice"),
                            Compare.Operator.GREATER_THAN_EQUAL,
                            Expression.value(50)
                    ))
    );

    query.output(OutputRate.perSnapshot(Expression.Time.minute(1)));
    query.insertInto("StockQuote");

}
 
Example #21
Source File: OutputRateTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatingQuery4() {
    Query query = Query.query();
    query.from(
            InputStream.stream("cseEventStream").
                    filter(Expression.and(Expression.compare(Expression.add(Expression.value(7),
                            Expression.value(9.5)),
                            Compare.Operator.GREATER_THAN,
                            Expression.variable("price")),
                            Expression.compare(Expression.value(100),
                                    Compare.Operator.GREATER_THAN_EQUAL,
                                    Expression.variable("volume")
                            )
                            )
                    ).window("lengthBatch", Expression.value(50))
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol")).
                    select("avgPrice", Expression.function("avg", Expression.variable("symbol"))).
                    groupBy(Expression.variable("symbol")).
                    having(Expression.compare(Expression.variable("avgPrice"),
                            Compare.Operator.GREATER_THAN_EQUAL,
                            Expression.value(50)
                    ))
    );
    query.output(OutputRate.perSnapshot(Expression.value(1000L)));
    query.insertInto("StockQuote");
}
 
Example #22
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery90() throws InterruptedException {
    log.info("Filter test90");

    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, Expression.value(10f))));
    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.addAndGet(inEvents.length);
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"WSO2", 50f, 60d, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40d, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200d, 56});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    AssertJUnit.assertEquals(1, count.get());
    siddhiAppRuntime.shutdown();
}
 
Example #23
Source File: PatternQueryTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testPatternQuery12() {
    Query query = Query.query();
    query.from(
            InputStream.patternStream(
                    State.next(
                            State.stream(InputStream.stream("e1", "Stream1").filter(Expression.compare(Expression
                                            .variable("price"),
                                    Compare.Operator.GREATER_THAN_EQUAL,
                                    Expression.value(30)))),
                            State.next(
                                    State.stream(InputStream.stream("e2", "Stream1").filter(Expression.compare
                                            (Expression.variable("price").ofFunction("e1", 1),
                                                    Compare.Operator.GREATER_THAN_EQUAL,
                                                    Expression.value(20)))),
                                    State.stream(InputStream.stream("e3", "Stream2").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN_EQUAL,
                                                    Expression.variable("price").ofInnerStream("e1"))))
                            )
                    )
            )
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol").ofInnerStream("e1")).
                    select("avgPrice", Expression.function("avg",
                            Expression.variable("price").ofInnerStream("e2"))).
                    groupBy(Expression.variable("symbol").ofInnerStream("e1")).
                    having(Expression.compare(Expression.variable("avgPrice"),
                            Compare.Operator.GREATER_THAN,
                            Expression.value(50)))
    );
    query.insertInto("OutputStream");
}
 
Example #24
Source File: PatternQueryTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testPatternQuery10() {
    Query query = Query.query();
    query.from(
            InputStream.patternStream(
                    State.next(
                            State.every(
                                    State.stream(InputStream.stream("e1", "Stream1").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN_EQUAL,
                                                    Expression.value(30))))),
                            State.next(
                                    State.next(
                                            State.stream(InputStream.stream("e2", "Stream1").filter(Expression
                                                    .compare(Expression.variable("price").ofStream("e2", Variable
                                                                    .LAST),
                                                            Compare.Operator.GREATER_THAN_EQUAL,
                                                            Expression.value(20)))),
                                            State.stream(InputStream.stream("e3", "Stream2").filter(Expression
                                                    .compare(Expression.variable("price"),
                                                            Compare.Operator.GREATER_THAN_EQUAL,
                                                            Expression.variable("price").ofStream("e1"))))),
                                    State.stream(InputStream.stream("e4", "Stream3").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN,
                                                    Expression.value(74))))
                            )
                    ), Expression.Time.minute(4)
            )
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol").ofStream("e1")).
                    select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2")))

    );
    query.insertInto("OutputStream");

}
 
Example #25
Source File: FilterTestCase1.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery79() throws InterruptedException {
    log.info("Filter test79");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute
            ("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.LESS_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.addAndGet(inEvents.length);
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"WSO2", 500f, 60L, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 60L, 2});
    inputHandler.send(new Object[]{"WSO2", 60f, 300L, 4});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    siddhiAppRuntime.shutdown();
}
 
Example #26
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery107() throws InterruptedException {
    log.info("Filter test107");

    SiddhiManager siddhiManager = new SiddhiManager();
    StreamDefinition cseEventStream = StreamDefinition.id("cseEventStream").attribute("symbol", Attribute.Type
            .STRING).attribute("price", Attribute.Type.FLOAT).attribute("volume", Attribute.Type.LONG).attribute
            ("quantity", Attribute.Type.INT);

    Query query = new Query();
    query.from(InputStream.stream("cseEventStream").filter(Expression.compare(Expression.variable("volume"),
            Compare.Operator.GREATER_THAN_EQUAL, Expression.value(100f))));
    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.addAndGet(inEvents.length);
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"WSO2", 50f, 60L, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40L, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200L, 56});
    SiddhiTestHelper.waitForEvents(10, 1, count, 100);
    AssertJUnit.assertEquals(1, count.get());
    siddhiAppRuntime.shutdown();

}
 
Example #27
Source File: PatternQueryTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testPatternQuery6() {
    Query query = Query.query();
    query.from(
            InputStream.patternStream(
                    State.next(
                            State.every(
                                    State.stream(InputStream.stream("e1", "Stream1").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN_EQUAL,
                                                    Expression.value(30))))),
                            State.next(
                                    State.logicalOr(
                                            State.stream(InputStream.stream("e2", "Stream1").filter(Expression
                                                    .compare(Expression.variable("price"),
                                                            Compare.Operator.GREATER_THAN_EQUAL,
                                                            Expression.value(20)))),
                                            State.stream(InputStream.stream("e3", "Stream2").filter(Expression
                                                    .compare(Expression.variable("price"),
                                                            Compare.Operator.GREATER_THAN_EQUAL,
                                                            Expression.variable("price").ofStream("e1")))))
                                    ,
                                    State.stream(InputStream.stream("e4", "Stream3").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN,
                                                    Expression.value(74)))))

                    ), Expression.Time.minute(3)
            )
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol").ofStream("e1")).
                    select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2")))

    );
    query.insertInto("OutputStream");

}
 
Example #28
Source File: PatternQueryTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testPatternQuery5() {
    Query query = Query.query();
    query.from(
            InputStream.patternStream(
                    State.next(
                            State.every(
                                    State.stream(InputStream.stream("e1", "Stream1").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN_EQUAL,
                                                    Expression.value(30))))),
                            State.next(
                                    State.logicalAnd(
                                            State.stream(InputStream.stream("e2", "Stream1").filter(Expression
                                                    .compare(Expression.variable("price"),
                                                            Compare.Operator.GREATER_THAN_EQUAL,
                                                            Expression.value(20)))),
                                            State.stream(InputStream.stream("e3", "Stream2").filter(Expression
                                                    .compare(Expression.variable("price"),
                                                            Compare.Operator.GREATER_THAN_EQUAL,
                                                            Expression.variable("price").ofStream("e1")))))
                                    ,
                                    State.stream(InputStream.stream("e4", "Stream3").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN,
                                                    Expression.value(74)))))
                    )
            )
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol").ofStream("e1")).
                    select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2")))

    );
    query.insertInto("OutputStream");

}
 
Example #29
Source File: PatternQueryTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testPatternQuery4() {
    Query query = Query.query();
    query.from(
            InputStream.patternStream(
                    State.next(
                            State.every(
                                    State.next(
                                            State.stream(InputStream.stream("e1", "Stream1").filter(Expression
                                                    .compare(Expression.variable("price"),
                                                            Compare.Operator.GREATER_THAN_EQUAL,
                                                            Expression.value(30)))),
                                            State.stream(InputStream.stream("e2", "Stream1").filter(Expression
                                                    .compare(Expression.variable("price"),
                                                            Compare.Operator.GREATER_THAN_EQUAL,
                                                            Expression.value(20)))))),
                            State.next(
                                    State.stream(InputStream.stream("e3", "Stream2").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN_EQUAL,
                                                    Expression.variable("price").ofStream("e1")))),

                                    State.stream(InputStream.stream("e4", "Stream3").filter(Expression.compare
                                            (Expression.variable("price"),
                                                    Compare.Operator.GREATER_THAN,
                                                    Expression.value(74)))))

                    )
            )
    );
    query.select(
            Selector.selector().
                    select("symbol", Expression.variable("symbol").ofStream("e1")).
                    select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2")))

    );
    query.insertInto("OutputStream");


}
 
Example #30
Source File: FilterTestCase2.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testFilterQuery89() throws InterruptedException {
    log.info("Filter test89");

    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, Expression.value(50d))));
    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.addAndGet(inEvents.length);
        }
    });

    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("cseEventStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[]{"WSO2", 50f, 60d, 6});
    inputHandler.send(new Object[]{"WSO2", 70f, 40d, 10});
    inputHandler.send(new Object[]{"WSO2", 44f, 200d, 56});
    SiddhiTestHelper.waitForEvents(10, 2, count, 100);
    AssertJUnit.assertEquals(2, count.get());
    siddhiAppRuntime.shutdown();
}