MathematicalFunction { private static FunctionResolver mod() { return FunctionDSL.define(BuiltinFunctionName.MOD.getName(), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : new ExprShortValue(v1.shortValue() % v2.shortValue())), SHORT, SHORT, SHORT), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : new ExprIntegerValue(Math.floorMod(v1.integerValue(), v2.integerValue()))), INTEGER, INTEGER, INTEGER), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : new ExprLongValue(Math.floorMod(v1.longValue(), v2.longValue()))), LONG, LONG, LONG), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : new ExprFloatValue(v1.floatValue() % v2.floatValue())), FLOAT, FLOAT, FLOAT), FunctionDSL.impl( FunctionDSL.nullMissingHandling( (v1, v2) -> v2.shortValue() == 0 ? ExprNullValue.of() : new ExprDoubleValue(v1.doubleValue() % v2.doubleValue())), DOUBLE, DOUBLE, DOUBLE) ); }  static void register(BuiltinFunctionRepository repository);  }
@Test public void mod_null_value() { FunctionExpression mod = dsl.mod(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); mod = dsl.mod(DSL.literal(1), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); mod = dsl.mod( DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isNull()); }
@Test public void mod_missing_value() { FunctionExpression mod = dsl.mod(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.literal(1)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); mod = dsl.mod(DSL.literal(1), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); mod = dsl.mod( DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); }
@Test public void mod_null_missing() { FunctionExpression mod = dsl.mod(DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); mod = dsl.mod(DSL.ref(INT_TYPE_NULL_VALUE_FIELD, INTEGER), DSL.ref(INT_TYPE_MISSING_VALUE_FIELD, INTEGER)); assertEquals(INTEGER, mod.type()); assertTrue(mod.valueOf(valueEnv()).isMissing()); }