@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()); }
@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; }
@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(); }
@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(); }
@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); }
@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)); }
@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(); }