@Override protected RowExpression visitNullIfExpression(NullIfExpression node, Void context) { RowExpression first = process(node.getFirst(), context); RowExpression second = process(node.getSecond(), context); return call( nullIfSignature(types.get(node), first.getType(), second.getType()), types.get(node), first, second); }
@Override protected Type visitNullIfExpression(NullIfExpression node, StackableAstVisitorContext<AnalysisContext> context) { Type firstType = process(node.getFirst(), context); Type secondType = process(node.getSecond(), context); if (!getCommonSuperTypeSignature(firstType.getTypeSignature(), secondType.getTypeSignature()).isPresent()) { throw new SemanticException(TYPE_MISMATCH, node, "Types are not comparable with NULLIF: %s vs %s", firstType, secondType); } expressionTypes.put(node, firstType); return firstType; }
@Override protected String visitNullIfExpression(NullIfExpression node, Void context) { return "NULLIF(" + process(node.getFirst(), null) + ", " + process(node.getSecond(), null) + ')'; }
@Override protected String visitNullIfExpression(NullIfExpression node, StackableAstVisitorContext<Integer> indent) { return "NULLIF(" + process(node.getFirst(), indent) + ", " + process(node.getSecond(), indent) + ')'; }
@Override protected Object visitNullIfExpression(NullIfExpression node, Object context) { Object first = process(node.getFirst(), context); if (first == null) { return null; } Object second = process(node.getSecond(), context); if (second == null) { return first; } Type firstType = expressionTypes.get(node.getFirst()); Type secondType = expressionTypes.get(node.getSecond()); if (hasUnresolvedValue(first, second)) { return new NullIfExpression(toExpression(first, firstType), toExpression(second, secondType)); } Type commonType = metadata.getTypeManager().getCommonSuperType(firstType, secondType).get(); Signature firstCast = metadata.getFunctionRegistry().getCoercion(firstType, commonType); Signature secondCast = metadata.getFunctionRegistry().getCoercion(secondType, commonType); ScalarFunctionImplementation firstCastFunction = metadata.getFunctionRegistry().getScalarFunctionImplementation(firstCast); ScalarFunctionImplementation secondCastFunction = metadata.getFunctionRegistry().getScalarFunctionImplementation(secondCast); // cast(first as <common type>) == cast(second as <common type>) boolean equal = (Boolean) invokeOperator( OperatorType.EQUAL, ImmutableList.of(commonType, commonType), ImmutableList.of( invoke(session, firstCastFunction, ImmutableList.of(first)), invoke(session, secondCastFunction, ImmutableList.of(second)))); if (equal) { return null; } else { return first; } }
@Override protected Boolean visitNullIfExpression(NullIfExpression node, Void context) { return process(node.getFirst(), context) && process(node.getSecond(), context); }
@Override protected String visitNullIfExpression(NullIfExpression node, Boolean unmangleNames) { return "NULLIF(" + process(node.getFirst(), unmangleNames) + ", " + process(node.getSecond(), unmangleNames) + ')'; }