Search in sources :

Example 66 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class SimpleQueryTestCase method testQuery4.

@Test
public void testQuery4() {
    StreamFunction streamFunction = new StreamFunction("function1");
    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")))).function(streamFunction).window("length", Expression.value(50)).function("foo", Expression.value(67), Expression.value(89)).filter(Expression.compare(Expression.value(10), Compare.Operator.LESS_THAN_EQUAL, Expression.variable("price"))));
    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(io.siddhi.query.api.execution.query.Query) StreamFunction(io.siddhi.query.api.execution.query.input.handler.StreamFunction) Test(org.testng.annotations.Test)

Example 67 with Query

use of io.siddhi.query.api.execution.query.Query 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(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 68 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class SimpleQueryTestCase method testCreatingReturnFilterQueryWithExtension3.

@Test
public void testCreatingReturnFilterQueryWithExtension3() {
    Query query = Query.query();
    Window window1 = new Window("Foo");
    AssertJUnit.assertFalse(window1.equals("falsewindow"));
    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(window1));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("ext", "avg", Expression.variable("price"))));
}
Also used : Window(io.siddhi.query.api.execution.query.input.handler.Window) Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 69 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class SimpleQueryTestCase method testCreatingReturnFilterQueryLimitAndSortError3.

@Test(expectedExceptions = UnsupportedAttributeTypeException.class)
public void testCreatingReturnFilterQueryLimitAndSortError3() {
    Query query = Query.query();
    query.from(InputStream.stream("StockStream"));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).orderBy(Expression.variable("avgPrice")).limit(Expression.value(true)));
}
Also used : Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 70 with Query

use of io.siddhi.query.api.execution.query.Query in project siddhi by wso2.

the class SimpleQueryTestCase method testCreatingReturnFilterQueryWithExtension2.

@Test
public void testCreatingReturnFilterQueryWithExtension2() {
    Query query = Query.query();
    Window window1 = new Window("ext", "Foo");
    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(window1));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("ext", "avg", Expression.variable("price"))));
}
Also used : Window(io.siddhi.query.api.execution.query.input.handler.Window) Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Aggregations

Query (io.siddhi.query.api.execution.query.Query)192 Test (org.testng.annotations.Test)181 SiddhiApp (io.siddhi.query.api.SiddhiApp)86 SiddhiAppRuntime (io.siddhi.core.SiddhiAppRuntime)85 SiddhiManager (io.siddhi.core.SiddhiManager)85 StreamDefinition (io.siddhi.query.api.definition.StreamDefinition)85 InputHandler (io.siddhi.core.stream.input.InputHandler)82 Event (io.siddhi.core.event.Event)81 QueryCallback (io.siddhi.core.query.output.callback.QueryCallback)74 Partition (io.siddhi.query.api.execution.partition.Partition)14 StreamCallback (io.siddhi.core.stream.output.StreamCallback)8 ArrayList (java.util.ArrayList)7 QueryRuntimeImpl (io.siddhi.core.query.QueryRuntimeImpl)4 OnDemandQuery (io.siddhi.query.api.execution.query.OnDemandQuery)4 SiddhiAppContext (io.siddhi.core.config.SiddhiAppContext)3 SingleStreamRuntime (io.siddhi.core.query.input.stream.single.SingleStreamRuntime)3 Window (io.siddhi.core.window.Window)3 AbstractDefinition (io.siddhi.query.api.definition.AbstractDefinition)3 ExecutionElement (io.siddhi.query.api.execution.ExecutionElement)3 JoinInputStream (io.siddhi.query.api.execution.query.input.stream.JoinInputStream)3