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

项目:presto    文件:SqlToRowExpressionTranslator.java   
@Override
protected RowExpression visitIfExpression(IfExpression node, Void context)
{
    ImmutableList.Builder<RowExpression> arguments = ImmutableList.builder();

    arguments.add(process(node.getCondition(), context))
            .add(process(node.getTrueValue(), context));

    if (node.getFalseValue().isPresent()) {
        arguments.add(process(node.getFalseValue().get(), context));
    }
    else {
        arguments.add(constantNull(types.get(node)));
    }

    return call(Signatures.ifSignature(types.get(node)), types.get(node), arguments.build());
}
项目:presto    文件:ExpressionAnalyzer.java   
@Override
protected Type visitIfExpression(IfExpression node, StackableAstVisitorContext<AnalysisContext> context)
{
    coerceType(context, node.getCondition(), BOOLEAN, "IF condition");

    Type type;
    if (node.getFalseValue().isPresent()) {
        type = coerceToSingleType(context, node, "Result types for IF must be the same: %s vs %s", node.getTrueValue(), node.getFalseValue().get());
    }
    else {
        type = process(node.getTrueValue(), context);
    }

    expressionTypes.put(node, type);
    return type;
}
项目:hue    文件:VeroGenExpFormatter.java   
@Override
protected String visitIfExpression(IfExpression node, Void context)
{
    StringBuilder builder = new StringBuilder();
    builder.append("IF(")
            .append(process(node.getCondition(), context))
            .append(", ")
            .append(process(node.getTrueValue(), context));
    if (node.getFalseValue().isPresent()) {
        builder.append(", ")
                .append(process(node.getFalseValue().get(), context));
    }
    builder.append(")");
    return builder.toString();
}
项目:presto-query-formatter    文件:ExpressionFormatter.java   
@Override
protected String visitIfExpression(IfExpression node, StackableAstVisitorContext<Integer> indent)
{
    StringBuilder builder = new StringBuilder();
    builder.append("IF(")
            .append(process(node.getCondition(), indent))
            .append(", ")
            .append(process(node.getTrueValue(), indent));
    if (node.getFalseValue().isPresent()) {
        builder.append(", ")
                .append(process(node.getFalseValue().get(), indent));
    }
    builder.append(")");
    return builder.toString();
}
项目:presto    文件:CanonicalizeExpressions.java   
@Override
public Expression rewriteIfExpression(IfExpression node, Void context, ExpressionTreeRewriter<Void> treeRewriter)
{
    Expression condition = treeRewriter.rewrite(node.getCondition(), context);
    Expression trueValue = treeRewriter.rewrite(node.getTrueValue(), context);

    Optional<Expression> falseValue = node.getFalseValue()
            .map((value) -> treeRewriter.rewrite(value, context));

    return new SearchedCaseExpression(ImmutableList.of(new WhenClause(condition, trueValue)), falseValue);
}
项目:presto    文件:AggregationAnalyzer.java   
@Override
protected Boolean visitIfExpression(IfExpression node, Void context)
{
    ImmutableList.Builder<Expression> expressions = ImmutableList.<Expression>builder()
            .add(node.getCondition())
            .add(node.getTrueValue());

    if (node.getFalseValue().isPresent()) {
        expressions.add(node.getFalseValue().get());
    }

    return expressions.build().stream().allMatch(expression -> process(expression, context));
}
项目:presto    文件:ExpressionFormatter.java   
@Override
protected String visitIfExpression(IfExpression node, Boolean unmangleNames)
{
    StringBuilder builder = new StringBuilder();
    builder.append("IF(")
            .append(process(node.getCondition(), unmangleNames))
            .append(", ")
            .append(process(node.getTrueValue(), unmangleNames));
    if (node.getFalseValue().isPresent()) {
        builder.append(", ")
                .append(process(node.getFalseValue().get(), unmangleNames));
    }
    builder.append(")");
    return builder.toString();
}
项目:EchoQuery    文件:ExpressionFormatter.java   
@Override
protected String visitIfExpression(IfExpression node, Boolean unmangleNames)
{
    StringBuilder builder = new StringBuilder();
    builder.append("IF(")
            .append(process(node.getCondition(), unmangleNames))
            .append(", ")
            .append(process(node.getTrueValue(), unmangleNames));
    if (node.getFalseValue().isPresent()) {
        builder.append(", ")
                .append(process(node.getFalseValue().get(), unmangleNames));
    }
    builder.append(")");
    return builder.toString();
}