@Override protected Boolean visitCoalesceExpression(CoalesceExpression node, Void context) { return node.getOperands().stream().allMatch(expression -> process(expression, context)); }
@Override protected R visitCoalesceExpression(CoalesceExpression node, C context) { for (Expression operand : node.getOperands()) { process(operand, context); } return null; }
@Override protected Boolean visitCoalesceExpression(CoalesceExpression node, Void context) { return node.getOperands().stream().allMatch(expression -> process(expression, context)); }
@Override protected String visitCoalesceExpression(CoalesceExpression node, Void context) { return "COALESCE(" + joinExpressions(node.getOperands()) + ")"; }
@Override protected R visitCoalesceExpression(CoalesceExpression node, C context) { for (Expression operand : node.getOperands()) { process(operand, context); } return null; }
@Override protected String visitCoalesceExpression(CoalesceExpression node, Void context) { return "COALESCE(" + joinExpressions(node.getOperands()) + ")"; }
public static Optional<Symbol> rewriteExpression(Map<Symbol, Expression> assignments, Expression expression) { checkArgument(expression instanceof CoalesceExpression, "The rewrite can only handle CoalesceExpression"); // We are using the property that the result of coalesce from full outer join keys would not be null despite of the order // of the arguments. Thus we extract and compare the symbols of the CoalesceExpression as a set rather than compare the // CoalesceExpression directly. for (Map.Entry<Symbol, Expression> entry : assignments.entrySet()) { if (entry.getValue() instanceof CoalesceExpression) { Set<Symbol> symbolsInAssignment = ((CoalesceExpression) entry.getValue()).getOperands().stream() .filter(SymbolReference.class::isInstance) .map(Symbol::from) .collect(toImmutableSet()); Set<Symbol> symbolInExpression = ((CoalesceExpression) expression).getOperands().stream() .filter(SymbolReference.class::isInstance) .map(Symbol::from) .collect(toImmutableSet()); if (symbolsInAssignment.containsAll(symbolInExpression)) { return Optional.of(entry.getKey()); } } } return Optional.empty(); } }
@Override protected SymbolStatsEstimate visitCoalesceExpression(CoalesceExpression node, Void context) { requireNonNull(node, "node is null"); SymbolStatsEstimate result = null; for (Expression operand : node.getOperands()) { SymbolStatsEstimate operandEstimates = process(operand); if (result != null) { result = estimateCoalesce(result, operandEstimates); } else { result = operandEstimates; } } return requireNonNull(result, "result is null"); }
@Override protected Type visitCoalesceExpression(CoalesceExpression node, StackableAstVisitorContext<Context> context) { Type type = coerceToSingleType(context, "All COALESCE operands must be the same type: %s", node.getOperands()); return setExpressionType(node, type); }
@Override protected SymbolStatsEstimate visitCoalesceExpression(CoalesceExpression node, Void context) { requireNonNull(node, "node is null"); SymbolStatsEstimate result = null; for (Expression operand : node.getOperands()) { SymbolStatsEstimate operandEstimates = process(operand); if (result != null) { result = estimateCoalesce(result, operandEstimates); } else { result = operandEstimates; } } return requireNonNull(result, "result is null"); }
@Override protected Type visitCoalesceExpression(CoalesceExpression node, StackableAstVisitorContext<Context> context) { Type type = coerceToSingleType(context, "All COALESCE operands must be the same type: %s", node.getOperands()); return setExpressionType(node, type); }
@Override protected Boolean visitCoalesceExpression(CoalesceExpression actual, Node expected) { if (!(expected instanceof CoalesceExpression)) { return false; } CoalesceExpression expectedCoalesce = (CoalesceExpression) expected; if (actual.getOperands().size() == expectedCoalesce.getOperands().size()) { boolean verified = true; for (int i = 0; i < actual.getOperands().size(); i++) { verified &= process(actual.getOperands().get(i), expectedCoalesce.getOperands().get(i)); } return verified; } return false; }
@Override protected Boolean visitCoalesceExpression(CoalesceExpression actual, Node expected) { if (!(expected instanceof CoalesceExpression)) { return false; } CoalesceExpression expectedCoalesce = (CoalesceExpression) expected; if (actual.getOperands().size() == expectedCoalesce.getOperands().size()) { boolean verified = true; for (int i = 0; i < actual.getOperands().size(); i++) { verified &= process(actual.getOperands().get(i), expectedCoalesce.getOperands().get(i)); } return verified; } return false; }
@Override protected RowExpression visitCoalesceExpression(CoalesceExpression node, Void context) { List<RowExpression> arguments = node.getOperands().stream() .map(value -> process(value, context)) .collect(toImmutableList()); List<Type> argumentTypes = arguments.stream().map(RowExpression::getType).collect(toImmutableList()); return call(coalesceSignature(getType(node), argumentTypes), getType(node), arguments); }
List<Object> values = node.getOperands().stream() .map(value -> processWithExceptionHandling(value, context)) .filter(Objects::nonNull) .flatMap(expression -> { if (expression instanceof CoalesceExpression) { return ((CoalesceExpression) expression).getOperands().stream();
@Override protected RowExpression visitCoalesceExpression(CoalesceExpression node, Void context) { List<RowExpression> arguments = node.getOperands().stream() .map(value -> process(value, context)) .collect(toImmutableList()); List<Type> argumentTypes = arguments.stream().map(RowExpression::getType).collect(toImmutableList()); return call(coalesceSignature(getType(node), argumentTypes), getType(node), arguments); }
List<Object> values = node.getOperands().stream() .map(value -> processWithExceptionHandling(value, context)) .filter(Objects::nonNull) .flatMap(expression -> { if (expression instanceof CoalesceExpression) { return ((CoalesceExpression) expression).getOperands().stream();