示例#1
0
 @Override
 public Void visitUnnest(UnnestNode node, Void context) {
   if (node.getOrdinalitySymbol() == null) {
     printNode(
         node,
         format("Unnest[%s]", node.getUnnestSymbols().keySet()),
         NODE_COLORS.get(NodeType.UNNEST));
   } else {
     printNode(
         node,
         format("Unnest[%s (ordinality)]", node.getUnnestSymbols().keySet()),
         NODE_COLORS.get(NodeType.UNNEST));
   }
   return node.getSource().accept(this, context);
 }
    @Override
    public PlanNode visitUnnest(UnnestNode node, RewriteContext<Set<Symbol>> context) {
      List<Symbol> replicateSymbols =
          node.getReplicateSymbols()
              .stream()
              .filter(context.get()::contains)
              .collect(toImmutableList());

      Optional<Symbol> ordinalitySymbol = node.getOrdinalitySymbol();
      if (ordinalitySymbol.isPresent() && !context.get().contains(ordinalitySymbol.get())) {
        ordinalitySymbol = Optional.empty();
      }
      Map<Symbol, List<Symbol>> unnestSymbols = node.getUnnestSymbols();
      ImmutableSet.Builder<Symbol> expectedInputs =
          ImmutableSet.<Symbol>builder().addAll(replicateSymbols).addAll(unnestSymbols.keySet());

      PlanNode source = context.rewrite(node.getSource(), expectedInputs.build());
      return new UnnestNode(
          node.getId(), source, replicateSymbols, unnestSymbols, ordinalitySymbol);
    }