Search in sources :

Example 21 with SiddhiParserException

use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.

the class DefineTableTestCase method test3.

@Test
public void test3() 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 22 with SiddhiParserException

use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.

the class QueryStoreTestCase method test1.

@Test
public void test1() throws SiddhiParserException {
    StoreQuery query = SiddhiCompiler.parseStoreQuery("" + "from StockTable " + "on price>3 " + "select symbol, avg(price) as avgPrice " + "group by symbol " + "having (price >= 20) ;");
    AssertJUnit.assertNotNull(query);
    StoreQuery api = StoreQuery.query().from(InputStore.store("StockTable").on(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN, Expression.value(3)))).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))));
    AssertJUnit.assertEquals(api, query);
}
Also used : StoreQuery(org.wso2.siddhi.query.api.execution.query.StoreQuery) Test(org.testng.annotations.Test)

Example 23 with SiddhiParserException

use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.

the class SimpleQueryTestCase method test4.

@Test
public void test4() throws SiddhiParserException {
    Query query = SiddhiCompiler.parseQuery("from  AllStockQuotes#window.lenghtBatch(50)  " + "select symbol, avg(price) as avgPrice " + "return ;");
    AssertJUnit.assertNotNull(query);
    Query api = Query.query().from(InputStream.stream("AllStockQuotes").window("lenghtBatch", Expression.value(50))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price")))).returns();
    AssertJUnit.assertEquals(api, query);
}
Also used : Query(org.wso2.siddhi.query.api.execution.query.Query) Test(org.testng.annotations.Test)

Example 24 with SiddhiParserException

use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.

the class SimpleQueryTestCase method test11.

@Test
public void test11() 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 " + "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")).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 25 with SiddhiParserException

use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException in project siddhi by wso2.

the class SimpleQueryTestCase method test1.

@Test
public void test1() 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) " + "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)))).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