Search in sources :

Example 1 with SiddhiParserException

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

Example 2 with SiddhiParserException

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

Example 3 with SiddhiParserException

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

Example 4 with SiddhiParserException

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

Example 5 with SiddhiParserException

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

Aggregations

Test (org.testng.annotations.Test)21 Query (org.wso2.siddhi.query.api.execution.query.Query)11 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)7 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)7 ParseTree (org.antlr.v4.runtime.tree.ParseTree)7 SiddhiQLBaseVisitorImpl (org.wso2.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl)7 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)5 TableDefinition (org.wso2.siddhi.query.api.definition.TableDefinition)5 AggregationDefinition (org.wso2.siddhi.query.api.definition.AggregationDefinition)3 StoreQuery (org.wso2.siddhi.query.api.execution.query.StoreQuery)3 Partition (org.wso2.siddhi.query.api.execution.partition.Partition)2 TimeConstant (org.wso2.siddhi.query.api.expression.constant.TimeConstant)2 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 ArrayList (java.util.ArrayList)1 SiddhiAppContext (org.wso2.siddhi.core.config.SiddhiAppContext)1 SiddhiAppCreationException (org.wso2.siddhi.core.exception.SiddhiAppCreationException)1 PartitionRuntime (org.wso2.siddhi.core.partition.PartitionRuntime)1 QueryRuntime (org.wso2.siddhi.core.query.QueryRuntime)1 ElementIdGenerator (org.wso2.siddhi.core.util.ElementIdGenerator)1 SiddhiAppRuntimeBuilder (org.wso2.siddhi.core.util.SiddhiAppRuntimeBuilder)1