Search in sources :

Example 36 with Query

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

Example 37 with Query

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

the class SimpleQueryTestCase method testCreatingReturnFilterQueryLimitAndSortError.

@Test(expectedExceptions = UnsupportedAttributeTypeException.class)
public void testCreatingReturnFilterQueryLimitAndSortError() {
    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(5.0)));
}
Also used : Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 38 with Query

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

the class SimpleQueryTestCase method testCreatingFilterQueryWithFaultStream.

@Test
public void testCreatingFilterQueryWithFaultStream() {
    Query query = Query.query();
    query.from(InputStream.faultStream("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.insertIntoFault("OutStockStream");
    SiddhiApp.siddhiApp("test").addQuery(query);
}
Also used : Query(io.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 39 with Query

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

the class SimpleQueryTestCase method testCreatingNestedFilterQuery2.

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

Example 40 with Query

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

the class SimpleQueryTestCase method testCreatingReturnFilterQueryLimitAndSortError4.

@Test(expectedExceptions = UnsupportedAttributeTypeException.class)
public void testCreatingReturnFilterQueryLimitAndSortError4() {
    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("Test")));
}
Also used : 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