Search in sources :

Example 6 with SiddhiParserException

use of org.wso2.siddhi.query.compiler.exception.SiddhiParserException 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 7 with SiddhiParserException

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

the class SiddhiCompiler method parseFunctionDefinition.

public static FunctionDefinition parseFunctionDefinition(String source) throws SiddhiParserException {
    ANTLRInputStream input = new ANTLRInputStream(source);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.definition_function_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (FunctionDefinition) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) FunctionDefinition(org.wso2.siddhi.query.api.definition.FunctionDefinition) SiddhiQLBaseVisitorImpl(org.wso2.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 8 with SiddhiParserException

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

the class SiddhiCompiler method parseTimeConstantDefinition.

public static TimeConstant parseTimeConstantDefinition(String source) throws SiddhiParserException {
    ANTLRInputStream input = new ANTLRInputStream(source);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.time_value();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (TimeConstant) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) SiddhiQLBaseVisitorImpl(org.wso2.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree) TimeConstant(org.wso2.siddhi.query.api.expression.constant.TimeConstant)

Example 9 with SiddhiParserException

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

the class SiddhiCompiler method parseStoreQuery.

public static StoreQuery parseStoreQuery(String storeQuery) throws SiddhiParserException {
    ANTLRInputStream input = new ANTLRInputStream(storeQuery);
    SiddhiQLLexer lexer = new SiddhiQLLexer(input);
    lexer.removeErrorListeners();
    lexer.addErrorListener(SiddhiErrorListener.INSTANCE);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    SiddhiQLParser parser = new SiddhiQLParser(tokens);
    parser.removeErrorListeners();
    parser.addErrorListener(SiddhiErrorListener.INSTANCE);
    ParseTree tree = parser.store_query_final();
    SiddhiQLVisitor eval = new SiddhiQLBaseVisitorImpl();
    return (StoreQuery) eval.visit(tree);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) StoreQuery(org.wso2.siddhi.query.api.execution.query.StoreQuery) SiddhiQLBaseVisitorImpl(org.wso2.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree)

Example 10 with SiddhiParserException

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

the class SimpleQueryTestCase method test5.

@Test
public void test5() throws SiddhiParserException {
    Query query = SiddhiCompiler.parseQuery("from  AllStockQuotes[price==Foo.price and Foo.try<5]  " + "select symbol, avg(price) as avgPrice " + "return ;");
    AssertJUnit.assertNotNull(query);
    Query api = Query.query().from(InputStream.stream("AllStockQuotes").filter(Expression.and(Expression.compare(Expression.variable("price"), Compare.Operator.EQUAL, Expression.variable("price").ofStream("Foo")), Expression.compare(Expression.variable("try").ofStream("Foo"), Compare.Operator.LESS_THAN, Expression.value(5))))).select(Selector.selector().select("symbol", Expression.variable("symbol")).select("avgPrice", Expression.function("avg", Expression.variable("price"))));
    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