MathematicalFunction { private static FunctionResolver log() { ImmutableList.Builder<SerializableFunction<FunctionName, Pair<FunctionSignature, FunctionBuilder>>> builder = new ImmutableList.Builder<>(); for (ExprType type : ExprCoreType.numberTypes()) { builder.add(FunctionDSL.impl(FunctionDSL .nullMissingHandling(v -> new ExprDoubleValue(Math.log(v.doubleValue()))), DOUBLE, type)); } for (ExprType baseType : ExprCoreType.numberTypes()) { for (ExprType numberType : ExprCoreType.numberTypes()) { builder.add(FunctionDSL.impl(FunctionDSL .nullMissingHandling((b, x) -> new ExprDoubleValue( Math.log(x.doubleValue()) / Math.log(b.doubleValue()))), DOUBLE, baseType, numberType)); } } return FunctionDSL.define(BuiltinFunctionName.LOG.getName(), builder.build()); }  static void register(BuiltinFunctionRepository repository);  }
@Test public void log_null_value() { FunctionExpression log = dsl.log( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); }
@Test public void log_missing_value() { FunctionExpression log = dsl.log( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); }
@Test public void log_two_null_value() { FunctionExpression log = dsl.log( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.literal(2D)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); log = dsl.log(DSL.literal(2D), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); log = dsl.log( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isNull()); }
@Test public void log_two_missing_value() { FunctionExpression log = dsl.log( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.literal(2D)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); log = dsl.log(DSL.literal(2D), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); log = dsl.log( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); }
@Test public void log_null_missing() { FunctionExpression log = dsl.log( DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); log = dsl.log( DSL.ref(DOUBLE_TYPE_MISSING_VALUE_FIELD, DOUBLE), DSL.ref(DOUBLE_TYPE_NULL_VALUE_FIELD, DOUBLE)); assertEquals(DOUBLE, log.type()); assertTrue(log.valueOf(valueEnv()).isMissing()); }