MathematicalFunction { private static FunctionResolver round() { return FunctionDSL.define(BuiltinFunctionName.ROUND.getName(), FunctionDSL.impl( FunctionDSL.nullMissingHandling( v -> new ExprLongValue((long) Math.round(v.integerValue()))), LONG, INTEGER), FunctionDSL.impl( FunctionDSL.nullMissingHandling( v -> new ExprLongValue((long) Math.round(v.longValue()))), LONG, LONG), FunctionDSL.impl( FunctionDSL.nullMissingHandling( v -> new ExprDoubleValue((double) Math.round(v.floatValue()))), DOUBLE, FLOAT), FunctionDSL.impl( FunctionDSL.nullMissingHandling( v -> new ExprDoubleValue((double) Math.round(v.doubleValue()))), DOUBLE, DOUBLE), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (x, d) -> new ExprLongValue( new BigDecimal(x.integerValue()).setScale(d.integerValue(), RoundingMode.HALF_UP).longValue())), LONG, INTEGER, INTEGER), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (x, d) -> new ExprLongValue(new BigDecimal(x.longValue()).setScale(d.integerValue(), RoundingMode.HALF_UP).longValue())), LONG, LONG, INTEGER), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (x, d) -> new ExprDoubleValue(new BigDecimal(x.floatValue()) .setScale(d.integerValue(), RoundingMode.HALF_UP).doubleValue())), DOUBLE, FLOAT, INTEGER), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (x, d) -> new ExprDoubleValue(new BigDecimal(x.doubleValue()) .setScale(d.integerValue(), RoundingMode.HALF_UP).doubleValue())), DOUBLE, DOUBLE, INTEGER)); }  static void register(BuiltinFunctionRepository repository);  }
@Test public void round_null_value() { FunctionExpression round = dsl.round(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isNull()); round = dsl.round(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isNull()); round = dsl.round(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isNull()); }
@Test public void round_missing_value() { FunctionExpression round = dsl.round(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); round = dsl.round(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); round = dsl.round(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); }
@Test public void round_null_missing() { FunctionExpression round = dsl.round( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); round = dsl.round( DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(LONG, round.type()); assertTrue(round.valueOf(valueEnv()).isMissing()); }