@Test public void testNoValueAvailableLeavesEmptyAverage() { ExpressionResult actual = testSubject.apply(expressionContext, emptyMapValue()); assertTrue(actual.isNumeric()); assertNull(actual.getValue()); }
@Override public ExpressionResult apply(ExpressionContext expressionContext, ExpressionResult input) { ExpressionContext scopedContext = expressionContext.scoped(this); ExpressionResult result = expression.apply(scopedContext, input); AtomicReference<AvgValue> initialSum = scopedContext.computeIfAbsent(alias, () -> new AtomicReference<>(new AvgValue())); if (result == null || !result.isNumeric() || result.getValue() == null) { return new NumericExpressionResult(initialSum.get().getAverage()); } AvgValue newAvg = initialSum.accumulateAndGet(new AvgValue(1, result.getNumericValue()), AvgValue::add); return new NumericExpressionResult(newAvg.getAverage()); }
AvgExpression extends AbstractAggregationFunction { @Override public ExpressionResult apply(ExpressionContext expressionContext, ExpressionResult input) { ExpressionContext scopedContext = expressionContext.scoped(this); ExpressionResult result = expression.apply(scopedContext, input); AtomicReference<AvgValue> initialSum = scopedContext.computeIfAbsent(alias, () -> new AtomicReference<>(new AvgValue())); if (result == null || !result.isNumeric() || result.getValue() == null) { return new NumericExpressionResult(initialSum.get().getAverage()); } AvgValue newAvg = initialSum.accumulateAndGet(new AvgValue(1, result.getNumericValue()), AvgValue::add); return new NumericExpressionResult(newAvg.getAverage()); } }
AvgExpression extends AbstractAggregationFunction { @Override public ExpressionResult apply(ExpressionContext expressionContext, ExpressionResult input) { ExpressionContext scopedContext = expressionContext.scoped(this); ExpressionResult result = expression.apply(scopedContext, input); AtomicReference<AvgValue> initialSum = scopedContext.computeIfAbsent(alias, () -> new AtomicReference<>(new AvgValue())); if (result == null || !result.isNumeric() || result.getValue() == null) { return new NumericExpressionResult(initialSum.get().getAverage()); } AvgValue newAvg = initialSum.accumulateAndGet(new AvgValue(1, result.getNumericValue()), AvgValue::add); return new NumericExpressionResult(newAvg.getAverage()); } AvgExpression(String alias, Expression expression); }
AvgExpression extends AbstractAggregationFunction { @Override public ExpressionResult apply(ExpressionContext expressionContext, ExpressionResult input) { ExpressionContext scopedContext = expressionContext.scoped(this); ExpressionResult result = expression.apply(scopedContext, input); AtomicReference<AvgValue> initialSum = scopedContext.computeIfAbsent(alias, () -> new AtomicReference<>(new AvgValue())); if (result == null || !result.isNumeric() || result.getValue() == null) { return new NumericExpressionResult(initialSum.get().getAverage()); } AvgValue newAvg = initialSum.accumulateAndGet(new AvgValue(1, result.getNumericValue()), AvgValue::add); return new NumericExpressionResult(newAvg.getAverage()); } AvgExpression(String alias, Expression expression); @Override ExpressionResult apply(ExpressionContext expressionContext, ExpressionResult input); }
AvgExpression extends AbstractAggregationFunction { @Override public ExpressionResult apply(ExpressionContext expressionContext, ExpressionResult input) { ExpressionContext scopedContext = expressionContext.scoped(this); ExpressionResult result = expression.apply(scopedContext, input); AtomicReference<AvgValue> initialSum = scopedContext.computeIfAbsent(alias, () -> new AtomicReference<>(new AvgValue())); if (result == null || !result.isNumeric() || result.getValue() == null) { return new NumericExpressionResult(initialSum.get().getAverage()); } AvgValue newAvg = initialSum.accumulateAndGet(new AvgValue(1, result.getNumericValue()), AvgValue::add); return new NumericExpressionResult(newAvg.getAverage()); } AvgExpression(String alias, Expression expression); @Override ExpressionResult apply(ExpressionContext expressionContext, ExpressionResult input);  }