Search in sources :

Example 56 with Group

use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.

the class QueryStoreTestCase method test3.

@Test
public void test3() {
    StoreQuery query = SiddhiCompiler.parseStoreQuery("" + "from StockTable " + "on price > 40 " + "select symbol, price " + "group by symbol " + "having (7 > price) ;");
    AssertJUnit.assertNotNull(query);
    StoreQuery api = StoreQuery.query().from(InputStore.store("StockTable").on(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(40)))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select(Expression.variable("price")).groupBy(Expression.variable("symbol")).having(Expression.compare(Expression.value(7), Compare.Operator.GREATER_THAN, Expression.variable("price"))));
    AssertJUnit.assertEquals(api, query);
}
Also used : StoreQuery(org.wso2.siddhi.query.api.execution.query.StoreQuery) Test(org.testng.annotations.Test)

Example 57 with Group

use of org.wso2.charon3.core.objects.Group 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 58 with Group

use of org.wso2.charon3.core.objects.Group 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 59 with Group

use of org.wso2.charon3.core.objects.Group 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 60 with Group

use of org.wso2.charon3.core.objects.Group in project siddhi by wso2.

the class SimpleQueryTestCase method testCreatingNestedFilterQuery.

// from (from StockStream[win.length(50)][ price >= 20]
// return symbol, avg(price) as avgPrice
// group by symbol) [symbol=="IBM"]
// insert into IBMOutStockStream symbol, avgPrice
@Test
public void testCreatingNestedFilterQuery() {
    Query query1 = SiddhiCompiler.parseQuery("from  from StockStream[StockStream.price >= 20][ StockStream.price " + "is null]  " + "select symbol, avg(price) as avgPrice " + "return " + "select symbol, avgPrice " + "insert into OutStockStream ;");
    AssertJUnit.assertNotNull(query1);
    Query query2 = SiddhiCompiler.parseQuery("from  ( from StockStream[StockStream.price >= 20][ StockStream" + ".price is null]  " + "select symbol, avg(price) as avgPrice " + "return ) " + "select symbol, avgPrice " + "insert into OutStockStream ;");
    AssertJUnit.assertNotNull(query2);
    Query api = Query.query();
    api.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()));
    api.select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.variable("avgPrice")));
    api.insertInto("OutStockStream");
    AssertJUnit.assertEquals(api, query1);
    AssertJUnit.assertEquals(api, query2);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)128 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)97 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)94 Event (org.wso2.siddhi.core.event.Event)87 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)78 QueryCallback (org.wso2.siddhi.core.query.output.callback.QueryCallback)51 Query (org.wso2.siddhi.query.api.execution.query.Query)17 ArrayList (java.util.ArrayList)16 CharonException (org.wso2.charon3.core.exceptions.CharonException)15 SCIMResponse (org.wso2.charon3.core.protocol.SCIMResponse)13 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)12 HashMap (java.util.HashMap)8 BadRequestException (org.wso2.charon3.core.exceptions.BadRequestException)8 SCIMResourceTypeSchema (org.wso2.charon3.core.schema.SCIMResourceTypeSchema)8 InternalErrorException (org.wso2.charon3.core.exceptions.InternalErrorException)7 UserManager (org.wso2.charon3.core.extensions.UserManager)7 Group (org.wso2.charon3.core.objects.Group)7 ApiOperation (io.swagger.annotations.ApiOperation)6 ApiResponses (io.swagger.annotations.ApiResponses)6 Produces (javax.ws.rs.Produces)6