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");
}
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);
}
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;
}
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;
}
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);
}
}
Aggregations