Java 类com.facebook.presto.sql.tree.NullIfExpression 实例源码

项目:presto    文件:SqlToRowExpressionTranslator.java   
@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);
}
项目:presto    文件:ExpressionAnalyzer.java   
@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;
}
项目:hue    文件:VeroGenExpFormatter.java   
@Override
protected String visitNullIfExpression(NullIfExpression node, Void context)
{
    return "NULLIF(" + process(node.getFirst(), null) + ", " + process(node.getSecond(), null) + ')';
}
项目:presto-query-formatter    文件:ExpressionFormatter.java   
@Override
protected String visitNullIfExpression(NullIfExpression node, StackableAstVisitorContext<Integer> indent)
{
    return "NULLIF(" + process(node.getFirst(), indent) + ", " + process(node.getSecond(), indent) + ')';
}
项目:presto    文件:ExpressionInterpreter.java   
@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;
    }
}
项目:presto    文件:AggregationAnalyzer.java   
@Override
protected Boolean visitNullIfExpression(NullIfExpression node, Void context)
{
    return process(node.getFirst(), context) && process(node.getSecond(), context);
}
项目:presto    文件:ExpressionFormatter.java   
@Override
protected String visitNullIfExpression(NullIfExpression node, Boolean unmangleNames)
{
    return "NULLIF(" + process(node.getFirst(), unmangleNames) + ", " + process(node.getSecond(), unmangleNames) + ')';
}
项目:EchoQuery    文件:ExpressionFormatter.java   
@Override
protected String visitNullIfExpression(NullIfExpression node, Boolean unmangleNames)
{
    return "NULLIF(" + process(node.getFirst(), unmangleNames) + ", " + process(node.getSecond(), unmangleNames) + ')';
}