use of io.siddhi.query.api.expression.constant.TimeConstant in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitConstant_value.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public Constant visitConstant_value(@NotNull SiddhiQLParser.Constant_valueContext ctx) {
// constant_value
// :bool_value
// |signed_double_value
// |signed_float_value
// |signed_long_value
// |signed_int_value
// |time_value
// |string_value
// ;
Constant constant;
if (ctx.bool_value() != null) {
constant = Expression.value(((BoolConstant) visit(ctx.bool_value())).getValue());
} else if (ctx.signed_double_value() != null) {
constant = Expression.value(((DoubleConstant) visit(ctx.signed_double_value())).getValue());
} else if (ctx.signed_float_value() != null) {
constant = Expression.value(((FloatConstant) visit(ctx.signed_float_value())).getValue());
} else if (ctx.signed_long_value() != null) {
constant = Expression.value(((LongConstant) visit(ctx.signed_long_value())).getValue());
} else if (ctx.signed_int_value() != null) {
constant = Expression.value(((IntConstant) visit(ctx.signed_int_value())).getValue());
} else if (ctx.time_value() != null) {
constant = (TimeConstant) visit(ctx.time_value());
} else if (ctx.string_value() != null) {
constant = Expression.value(((StringConstant) visit(ctx.string_value())).getValue());
} else {
throw newSiddhiParserException(ctx);
}
populateQueryContext(constant, ctx);
return constant;
}
use of io.siddhi.query.api.expression.constant.TimeConstant in project siddhi by wso2.
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 io.siddhi.query.api.expression.constant.TimeConstant in project siddhi by wso2.
the class PatternQueryTestCase method testPatternQuery17.
@Test(expectedExceptions = SiddhiAppValidationException.class)
public void testPatternQuery17() {
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("e1", "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"))))))));
}
use of io.siddhi.query.api.expression.constant.TimeConstant in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitSecond_value.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public TimeConstant visitSecond_value(@NotNull SiddhiQLParser.Second_valueContext ctx) {
TimeConstant timeConstant = Expression.Time.sec(Long.parseLong(ctx.INT_LITERAL().getText().replaceFirst("[lL]", "")));
populateQueryContext(timeConstant, ctx);
return timeConstant;
}
use of io.siddhi.query.api.expression.constant.TimeConstant in project siddhi by wso2.
the class SiddhiQLBaseVisitorImpl method visitHour_value.
/**
* {@inheritDoc}
* <p>The default implementation returns the result of calling
* {@link #visitChildren} on {@code ctx}.</p>
*
* @param ctx
*/
@Override
public TimeConstant visitHour_value(@NotNull SiddhiQLParser.Hour_valueContext ctx) {
TimeConstant timeConstant = Expression.Time.hour(Long.parseLong(ctx.INT_LITERAL().getText().replaceFirst("[lL]", "")));
populateQueryContext(timeConstant, ctx);
return timeConstant;
}
Aggregations