MathematicalFunction { private static FunctionResolver sqrt() { return FunctionDSL.define(BuiltinFunctionName.SQRT.getName(), ExprCoreType.numberTypes().stream() .map(type -> FunctionDSL.impl(FunctionDSL.nullMissingHandling( v -> v.doubleValue() < 0 ? ExprNullValue.of() : new ExprDoubleValue(Math.sqrt(v.doubleValue()))), DOUBLE, type)).collect(Collectors.toList())); }  static void register(BuiltinFunctionRepository repository);  }
@Test public void sqrt_null_value() { FunctionExpression sqrt = dsl.sqrt(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, sqrt.type()); assertTrue(sqrt.valueOf(valueEnv()).isNull()); }
@Test public void sqrt_missing_value() { FunctionExpression sqrt = dsl.sqrt(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(DOUBLE, sqrt.type()); assertTrue(sqrt.valueOf(valueEnv()).isMissing()); }