BinaryPredicateOperator { private static FunctionResolver equal() { return FunctionDSL.define(BuiltinFunctionName.EQUAL.getName(), ExprCoreType.coreTypes().stream() .map(type -> FunctionDSL.impl( FunctionDSL.nullMissingHandling((v1, v2) -> ExprBooleanValue.of(v1.equals(v2))), BOOLEAN, type, type)) .collect( Collectors.toList())); }  static void register(BuiltinFunctionRepository repository);  }
@Test public void test_null_equal_missing() { FunctionExpression equal = dsl.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); equal = dsl.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_NULL, equal.valueOf(valueEnv())); equal = dsl.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); equal = dsl.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); equal = dsl.equal(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); equal = dsl.equal(DSL.literal(LITERAL_TRUE), DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_NULL, equal.valueOf(valueEnv())); equal = dsl.equal(DSL.ref(BOOL_TYPE_MISSING_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_MISSING, equal.valueOf(valueEnv())); equal = dsl.equal(DSL.ref(BOOL_TYPE_NULL_VALUE_FIELD, BOOLEAN), DSL.literal(LITERAL_TRUE)); assertEquals(BOOLEAN, equal.type()); assertEquals(LITERAL_NULL, equal.valueOf(valueEnv())); }
@Test public void serializationTest() throws Exception { Expression expression = dsl.equal(DSL.literal("v1"), DSL.literal("v2")); ByteArrayOutputStream output = new ByteArrayOutputStream(); ObjectOutputStream objectOutput = new ObjectOutputStream(output); objectOutput.writeObject(expression); objectOutput.flush(); String source = Base64.getEncoder().encodeToString(output.toByteArray()); ByteArrayInputStream input = new ByteArrayInputStream(Base64.getDecoder().decode(source)); ObjectInputStream objectInput = new ObjectInputStream(input); Expression e = (Expression) objectInput.readObject(); ExprValue exprValue = e.valueOf(valueEnv()); assertEquals(LITERAL_FALSE, exprValue); }
@Test public void compareNumberValueWithDifferentType() { FunctionExpression equal = dsl.equal(DSL.literal(1), DSL.literal(1L)); assertTrue(equal.valueOf(valueEnv()).booleanValue()); }
@Test public void compare_int_long() { FunctionExpression equal = dsl.equal(DSL.literal(1), DSL.literal(1L)); assertTrue(equal.valueOf(valueEnv()).booleanValue()); }