Java Code Examples for io.siddhi.query.api.expression.Expression#value()
The following examples show how to use
io.siddhi.query.api.expression.Expression#value() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SimpleQueryTestCase.java From siddhi with Apache License 2.0 | 6 votes |
@Test public void test1() throws InterruptedException { String modString = "Mod{leftValue=IntConstant{value=1}, rightValue=IntConstant{value=2}}"; String addString = "Add{leftValue=IntConstant{value=1}, rightValue=IntConstant{value=2}}"; String dividString = "Divide{leftValue=IntConstant{value=1}, rightValue=IntConstant{value=2}}"; String multiplyString = "Multiply{leftValue=IntConstant{value=1}, rightValue=IntConstant{value=2}}"; String subtractString = "Minus{leftValue=IntConstant{value=1}, rightValue=IntConstant{value=2}}"; Mod mod = new Mod(Expression.value(1), Expression.value(2)); Add add = new Add(Expression.value(1), Expression.value(2)); Divide divide = new Divide(Expression.value(1), Expression.value(2)); Multiply multiply = new Multiply(Expression.value(1), Expression.value(2)); Subtract subtract = new Subtract(Expression.value(1), Expression.value(2)); AssertJUnit.assertEquals(mod.toString(), modString); AssertJUnit.assertEquals(add.toString(), addString); AssertJUnit.assertEquals(divide.toString(), dividString); AssertJUnit.assertEquals(multiply.toString(), multiplyString); AssertJUnit.assertEquals(subtract.toString(), subtractString); }
Example 2
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 5 votes |
/** * {@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; }
Example 3
Source File: AggregationExpressionVisitor.java From siddhi with Apache License 2.0 | 5 votes |
public Expression getReducedExpression() { Object pop = this.conditionOperands.pop(); if (pop instanceof String) { return Expression.value(true); } return ((Expression) pop); }
Example 4
Source File: AggregationParser.java From siddhi with Apache License 2.0 | 4 votes |
private static List<ExpressionExecutor> constructProcessExpressionExecutors( SiddhiQueryContext siddhiQueryContext, Map<String, Table> tableMap, int baseAggregatorBeginIndex, List<Expression> finalBaseExpressions, StreamDefinition incomingOutputStreamDefinition, MetaStreamEvent processedMetaStreamEvent, List<VariableExpressionExecutor> processVariableExpressionExecutors, boolean isProcessingOnExternalTime, TimePeriod.Duration duration, boolean isDistributed, String shardId, boolean isLatestEventColAdded) { List<ExpressionExecutor> processExpressionExecutors = new ArrayList<>(); List<Attribute> attributeList = incomingOutputStreamDefinition.getAttributeList(); int i = 1; //Add timestamp executor Attribute attribute = attributeList.get(0); VariableExpressionExecutor variableExpressionExecutor = (VariableExpressionExecutor) ExpressionParser .parseExpression(new Variable(attribute.getName()), processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext); processExpressionExecutors.add(variableExpressionExecutor); if (isDistributed) { Expression shardIdExpression = Expression.value(shardId); ExpressionExecutor shardIdExpressionExecutor = ExpressionParser.parseExpression(shardIdExpression, processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext); processExpressionExecutors.add(shardIdExpressionExecutor); i++; } if (isProcessingOnExternalTime) { Expression externalTimestampExpression = AttributeFunction.function("incrementalAggregator", "getAggregationStartTime", new Variable(AGG_EXTERNAL_TIMESTAMP_COL), new StringConstant(duration.name())); ExpressionExecutor externalTimestampExecutor = ExpressionParser.parseExpression( externalTimestampExpression, processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext); processExpressionExecutors.add(externalTimestampExecutor); i++; } if (isLatestEventColAdded) { baseAggregatorBeginIndex = baseAggregatorBeginIndex - 1; } for (; i < baseAggregatorBeginIndex; i++) { attribute = attributeList.get(i); variableExpressionExecutor = (VariableExpressionExecutor) ExpressionParser.parseExpression( new Variable(attribute.getName()), processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext); processExpressionExecutors.add(variableExpressionExecutor); } if (isLatestEventColAdded) { Expression lastTimestampExpression = AttributeFunction.function("max", new Variable(AGG_LAST_TIMESTAMP_COL)); ExpressionExecutor latestTimestampExecutor = ExpressionParser.parseExpression(lastTimestampExpression, processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext); processExpressionExecutors.add(latestTimestampExecutor); } for (Expression expression : finalBaseExpressions) { ExpressionExecutor expressionExecutor = ExpressionParser.parseExpression(expression, processedMetaStreamEvent, 0, tableMap, processVariableExpressionExecutors, true, 0, ProcessingMode.BATCH, false, siddhiQueryContext); processExpressionExecutors.add(expressionExecutor); } return processExpressionExecutors; }
Example 5
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 3 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public DoubleConstant visitSigned_double_value(@NotNull SiddhiQLParser.Signed_double_valueContext ctx) { DoubleConstant doubleConstant = Expression.value(Double.parseDouble(ctx.getText())); populateQueryContext(doubleConstant, ctx); return doubleConstant; }
Example 6
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 3 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public LongConstant visitSigned_long_value(@NotNull SiddhiQLParser.Signed_long_valueContext ctx) { LongConstant longConstant = Expression.value(Long.parseLong(ctx.getText().replaceFirst("[lL]", ""))); populateQueryContext(longConstant, ctx); return longConstant; }
Example 7
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 3 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public FloatConstant visitSigned_float_value(@NotNull SiddhiQLParser.Signed_float_valueContext ctx) { FloatConstant floatConstant = Expression.value(Float.parseFloat(ctx.getText())); populateQueryContext(floatConstant, ctx); return floatConstant; }
Example 8
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 3 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public IntConstant visitSigned_int_value(@NotNull SiddhiQLParser.Signed_int_valueContext ctx) { IntConstant intConstant = Expression.value(Integer.parseInt(ctx.getText())); populateQueryContext(intConstant, ctx); return intConstant; }
Example 9
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 3 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public BoolConstant visitBool_value(@NotNull SiddhiQLParser.Bool_valueContext ctx) { BoolConstant boolConstant = Expression.value("true".equalsIgnoreCase(ctx.getText())); populateQueryContext(boolConstant, ctx); return boolConstant; }
Example 10
Source File: SiddhiQLBaseVisitorImpl.java From siddhi with Apache License 2.0 | 3 votes |
/** * {@inheritDoc} * <p>The default implementation returns the result of calling * {@link #visitChildren} on {@code ctx}.</p> * * @param ctx */ @Override public StringConstant visitString_value(@NotNull SiddhiQLParser.String_valueContext ctx) { StringConstant stringConstant = Expression.value(ctx.STRING_LITERAL().getText()); populateQueryContext(stringConstant, ctx); return stringConstant; }