use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.
the class DefineAggregationTestCase method test2.
@Test
public void test2() throws SiddhiParserException {
AggregationDefinition aggregationDefinitionQuery = SiddhiCompiler.parseAggregationDefinition("define aggregation StockAggregationDefinition " + "from StockStream " + "select StockStream.timestamp, StockStream.symbol as symbol, " + " StockStream.price as price " + " group by StockStream.symbol " + "aggregate by timestamp " + "every seconds, minutes, hours ;");
AggregationDefinition aggregationDefinition = AggregationDefinition.id("StockAggregationDefinition").from(InputStream.stream("StockStream")).select(Selector.basicSelector().select(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.interval(TimePeriod.Duration.SECONDS, TimePeriod.Duration.MINUTES, TimePeriod.Duration.HOURS));
AssertJUnit.assertEquals(aggregationDefinition, aggregationDefinitionQuery);
}
use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.
the class DefineTableTestCase method test4.
@Test
public void test4() throws SiddhiParserException {
TableDefinition streamDefinition = SiddhiCompiler.parseTableDefinition("" + " @from(datasource='MyDatabase','CUSTOM')" + " define table cseStream ( symbol string, price int, volume float )");
AssertJUnit.assertEquals(TableDefinition.id("cseStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).annotation(Annotation.annotation("from").element("datasource", "MyDatabase").element("CUSTOM")).toString(), streamDefinition.toString());
}
use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.
the class DefineTableTestCase method test2.
@Test
public void test2() throws SiddhiParserException {
TableDefinition streamDefinition = SiddhiCompiler.parseTableDefinition("define table `define` ( `string` " + "string, price int, volume float );");
AssertJUnit.assertEquals(TableDefinition.id("define").attribute("string", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).toString(), streamDefinition.toString());
}
use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.
the class DefineTableTestCase method test1.
@Test
public void test1() throws SiddhiParserException {
TableDefinition streamDefinition = SiddhiCompiler.parseTableDefinition("define table cseStream ( symbol " + "string, price int, volume float )");
AssertJUnit.assertEquals(TableDefinition.id("cseStream").attribute("symbol", Attribute.Type.STRING).attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT).toString(), streamDefinition.toString());
}
use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException 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);
}
Aggregations