Search in sources :

Example 6 with TimeConstant

use of org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant in project ballerina by ballerina-lang.

the class PatternQueryTestCase method testPatternQuery11.

// from e1=Stream1[price >= 30] -> not Stream1[ price >= 20] for 1 sec -> e3=Stream2[ price >= e1.price]
// select e1.symbol, avg(e2.price ) as avgPrice
// group by e1.symbol
// having avgPrice>50;
// insert into OutputStream
@Test
public void testPatternQuery11() {
    Query query = Query.query();
    query.from(InputStream.patternStream(State.next(State.stream(InputStream.stream("e1", "Stream1").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(30)))), State.next(State.logicalNot(State.stream(InputStream.stream("Stream1").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.value(20)))), new TimeConstant(1000)), State.stream(InputStream.stream("e3", "Stream2").filter(Expression.compare(Expression.variable("price"), Compare.Operator.GREATER_THAN_EQUAL, Expression.variable("price").ofStream("e1"))))))));
    query.select(Selector.selector().select("symbol", Expression.variable("symbol").ofStream("e1")).select("avgPrice", Expression.function("avg", Expression.variable("price").ofStream("e2"))).groupBy(Expression.variable("symbol").ofStream("e1")).having(Expression.compare(Expression.variable("avgPrice"), Compare.Operator.GREATER_THAN, Expression.value(50))));
    query.insertInto("OutputStream");
}
Also used : Query(org.ballerinalang.siddhi.query.api.execution.query.Query) TimeConstant(org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant) Test(org.testng.annotations.Test)

Example 7 with TimeConstant

use of org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant in project ballerina by ballerina-lang.

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.ballerinalang.siddhi.query.compiler.internal.SiddhiQLBaseVisitorImpl) ANTLRInputStream(org.antlr.v4.runtime.ANTLRInputStream) ParseTree(org.antlr.v4.runtime.tree.ParseTree) TimeConstant(org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant)

Example 8 with TimeConstant

use of org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitMillisecond_value.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public TimeConstant visitMillisecond_value(@NotNull SiddhiQLParser.Millisecond_valueContext ctx) {
    TimeConstant timeConstant = Expression.Time.milliSec(Long.parseLong(ctx.INT_LITERAL().getText().replaceFirst("[lL]", "")));
    populateQueryContext(timeConstant, ctx);
    return timeConstant;
}
Also used : TimeConstant(org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant)

Example 9 with TimeConstant

use of org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitDay_value.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public TimeConstant visitDay_value(@NotNull SiddhiQLParser.Day_valueContext ctx) {
    TimeConstant timeConstant = Expression.Time.day(Long.parseLong(ctx.INT_LITERAL().getText().replaceFirst("[lL]", "")));
    populateQueryContext(timeConstant, ctx);
    return timeConstant;
}
Also used : TimeConstant(org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant)

Example 10 with TimeConstant

use of org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant in project ballerina by ballerina-lang.

the class SiddhiQLBaseVisitorImpl method visitEvery_pattern_source_chain.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public Object visitEvery_pattern_source_chain(@NotNull SiddhiQLParser.Every_pattern_source_chainContext ctx) {
    if (ctx.every_pattern_source_chain().size() == 1) {
        // '('every_pattern_source_chain')' within_time?
        StateElement stateElement = ((StateElement) visit(ctx.every_pattern_source_chain(0)));
        if (ctx.within_time() != null) {
            stateElement.setWithin((TimeConstant) visit(ctx.within_time()));
        }
        populateQueryContext(stateElement, ctx);
        return stateElement;
    } else if (ctx.every_pattern_source_chain().size() == 2) {
        // every_pattern_source_chain  '->'
        // every_pattern_source_chain
        NextStateElement nextStateElement = new NextStateElement(((StateElement) visit(ctx.every_pattern_source_chain(0))), ((StateElement) visit(ctx.every_pattern_source_chain(1))));
        populateQueryContext(nextStateElement, ctx);
        return nextStateElement;
    } else if (ctx.EVERY() != null) {
        if (ctx.pattern_source_chain() != null) {
            // EVERY '('pattern_source_chain ')' within_time?
            EveryStateElement everyStateElement = new EveryStateElement((StateElement) visit(ctx.pattern_source_chain()));
            if (ctx.within_time() != null) {
                everyStateElement.setWithin((TimeConstant) visit(ctx.within_time()));
            }
            populateQueryContext(everyStateElement, ctx);
            return everyStateElement;
        } else if (ctx.pattern_source() != null) {
            // EVERY pattern_source within_time?
            EveryStateElement everyStateElement = new EveryStateElement((StateElement) visit(ctx.pattern_source()));
            if (ctx.within_time() != null) {
                everyStateElement.setWithin((TimeConstant) visit(ctx.within_time()));
            }
            populateQueryContext(everyStateElement, ctx);
            return everyStateElement;
        } else {
            throw newSiddhiParserException(ctx);
        }
    } else if (ctx.pattern_source_chain() != null) {
        // pattern_source_chain
        StateElement stateElement = ((StateElement) visit(ctx.pattern_source_chain()));
        if (ctx.within_time() != null) {
            stateElement.setWithin((TimeConstant) visit(ctx.within_time()));
        }
        populateQueryContext(stateElement, ctx);
        return stateElement;
    } else {
        throw newSiddhiParserException(ctx);
    }
}
Also used : NextStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.NextStateElement) EveryStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.EveryStateElement) StateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StateElement) AbsentStreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement) NextStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.NextStateElement) CountStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement) StreamStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement) EveryStateElement(org.ballerinalang.siddhi.query.api.execution.query.input.state.EveryStateElement) TimeConstant(org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant)

Aggregations

TimeConstant (org.ballerinalang.siddhi.query.api.expression.constant.TimeConstant)15 Query (org.ballerinalang.siddhi.query.api.execution.query.Query)2 Test (org.testng.annotations.Test)2 ANTLRInputStream (org.antlr.v4.runtime.ANTLRInputStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTree (org.antlr.v4.runtime.tree.ParseTree)1 PartitionType (org.ballerinalang.siddhi.query.api.execution.partition.PartitionType)1 RangePartitionType (org.ballerinalang.siddhi.query.api.execution.partition.RangePartitionType)1 ValuePartitionType (org.ballerinalang.siddhi.query.api.execution.partition.ValuePartitionType)1 AbsentStreamStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.AbsentStreamStateElement)1 CountStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.CountStateElement)1 EveryStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.EveryStateElement)1 NextStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.NextStateElement)1 StateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.StateElement)1 StreamStateElement (org.ballerinalang.siddhi.query.api.execution.query.input.state.StreamStateElement)1 EventOutputRate (org.ballerinalang.siddhi.query.api.execution.query.output.ratelimit.EventOutputRate)1 OutputRate (org.ballerinalang.siddhi.query.api.execution.query.output.ratelimit.OutputRate)1 SnapshotOutputRate (org.ballerinalang.siddhi.query.api.execution.query.output.ratelimit.SnapshotOutputRate)1 TimeOutputRate (org.ballerinalang.siddhi.query.api.execution.query.output.ratelimit.TimeOutputRate)1 BoolConstant (org.ballerinalang.siddhi.query.api.expression.constant.BoolConstant)1