Search in sources :

Example 81 with Filter

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

the class SimpleQueryTestCase method testCreatingReturnFilterQuery.

// from StockStream[win.lengthBatch(50)][price >= 20]
// return symbol, avg(price) as avgPrice
@Test
public void testCreatingReturnFilterQuery() {
    Query query = Query.query();
    query.from(InputStream.stream("StockStream").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("price"))));
    query.returns();
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 82 with Filter

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

the class SimpleQueryTestCase method testCreatingReturnFilterQueryWithExtension.

@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"))));
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 83 with Filter

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

the class SimpleQueryTestCase method testQuery1.

@Test
public void testQuery1() {
    Query query = Query.query();
    query.from(InputStream.stream("StockStream").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("length", Expression.value(50)));
    query.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.GREATER_THAN_EQUAL, Expression.value(50))));
    query.insertInto("OutStockStream");
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 84 with Filter

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

the class SimpleQueryTestCase method testCreatingFilterQuery.

// from StockStream[ 7+9.5>price AND 100>=volume]
// insert into OutStockStream symbol, avg(price) as avgPrice
// group by symbol
// having avgPrice>50
@Test
public void testCreatingFilterQuery() {
    Query query = Query.query();
    query.from(InputStream.stream("StockStream").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")))));
    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.insertInto("OutStockStream");
    SiddhiApp.siddhiApp("test").addQuery(query);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 85 with Filter

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

the class SimpleQueryTestCase method testCreatingReturnFilterQueryLimitAndSort.

@Test
public void testCreatingReturnFilterQueryLimitAndSort() {
    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)));
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) 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