@Override public PlanNode visitValues(ValuesNode node, RewriteContext<Void> context) { List<List<Expression>> canonicalizedRows = node.getRows().stream() .map(this::canonicalize) .collect(toImmutableList()); List<Symbol> canonicalizedOutputSymbols = canonicalizeAndDistinct(node.getOutputSymbols()); checkState(node.getOutputSymbols().size() == canonicalizedOutputSymbols.size(), "Values output symbols were pruned"); return new ValuesNode( node.getId(), canonicalizedOutputSymbols, canonicalizedRows); }
@Override protected Optional<PlanNode> pushDownProjectOff(PlanNodeIdAllocator idAllocator, ValuesNode valuesNode, Set<Symbol> referencedOutputs) { List<Symbol> newOutputs = filteredCopy(valuesNode.getOutputSymbols(), referencedOutputs::contains); // for each output of project, the corresponding column in the values node int[] mapping = new int[newOutputs.size()]; for (int i = 0; i < mapping.length; i++) { mapping[i] = valuesNode.getOutputSymbols().indexOf(newOutputs.get(i)); } ImmutableList.Builder<List<Expression>> rowsBuilder = ImmutableList.builder(); for (List<Expression> row : valuesNode.getRows()) { rowsBuilder.add(Arrays.stream(mapping) .mapToObj(row::get) .collect(Collectors.toList())); } return Optional.of(new ValuesNode(valuesNode.getId(), newOutputs, rowsBuilder.build())); } }
@Override public PlanNode visitValues(ValuesNode node, RewriteContext<Void> context) { List<List<Expression>> canonicalizedRows = node.getRows().stream() .map(this::canonicalize) .collect(toImmutableList()); List<Symbol> canonicalizedOutputSymbols = canonicalizeAndDistinct(node.getOutputSymbols()); checkState(node.getOutputSymbols().size() == canonicalizedOutputSymbols.size(), "Values output symbols were pruned"); return new ValuesNode( node.getId(), canonicalizedOutputSymbols, canonicalizedRows); }
@Override protected Optional<PlanNode> pushDownProjectOff(PlanNodeIdAllocator idAllocator, ValuesNode valuesNode, Set<Symbol> referencedOutputs) { List<Symbol> newOutputs = filteredCopy(valuesNode.getOutputSymbols(), referencedOutputs::contains); // for each output of project, the corresponding column in the values node int[] mapping = new int[newOutputs.size()]; for (int i = 0; i < mapping.length; i++) { mapping[i] = valuesNode.getOutputSymbols().indexOf(newOutputs.get(i)); } ImmutableList.Builder<List<Expression>> rowsBuilder = ImmutableList.builder(); for (List<Expression> row : valuesNode.getRows()) { rowsBuilder.add(Arrays.stream(mapping) .mapToObj(row::get) .collect(Collectors.toList())); } return Optional.of(new ValuesNode(valuesNode.getId(), newOutputs, rowsBuilder.build())); } }
@Override public PlanNode visitValues(ValuesNode node, RewriteContext<Set<Symbol>> context) { ImmutableList.Builder<Symbol> rewrittenOutputSymbolsBuilder = ImmutableList.builder(); ImmutableList.Builder<ImmutableList.Builder<Expression>> rowBuildersBuilder = ImmutableList.builder(); // Initialize builder for each row for (int i = 0; i < node.getRows().size(); i++) { rowBuildersBuilder.add(ImmutableList.builder()); } ImmutableList<ImmutableList.Builder<Expression>> rowBuilders = rowBuildersBuilder.build(); for (int i = 0; i < node.getOutputSymbols().size(); i++) { Symbol outputSymbol = node.getOutputSymbols().get(i); // If output symbol is used if (context.get().contains(outputSymbol)) { rewrittenOutputSymbolsBuilder.add(outputSymbol); // Add the value of the output symbol for each row for (int j = 0; j < node.getRows().size(); j++) { rowBuilders.get(j).add(node.getRows().get(j).get(i)); } } } List<List<Expression>> rewrittenRows = rowBuilders.stream() .map(ImmutableList.Builder::build) .collect(toImmutableList()); return new ValuesNode(node.getId(), rewrittenOutputSymbolsBuilder.build(), rewrittenRows); }
@Override public Void visitValues(ValuesNode node, Integer indent) { print(indent, "- Values => [%s]", formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); for (List<Expression> row : node.getRows()) { print(indent + 2, "(" + Joiner.on(", ").join(row) + ")"); } return null; }
@Override public PlanNode visitValues(ValuesNode node, RewriteContext<Set<Symbol>> context) { ImmutableList.Builder<Symbol> rewrittenOutputSymbolsBuilder = ImmutableList.builder(); ImmutableList.Builder<ImmutableList.Builder<Expression>> rowBuildersBuilder = ImmutableList.builder(); // Initialize builder for each row for (int i = 0; i < node.getRows().size(); i++) { rowBuildersBuilder.add(ImmutableList.builder()); } ImmutableList<ImmutableList.Builder<Expression>> rowBuilders = rowBuildersBuilder.build(); for (int i = 0; i < node.getOutputSymbols().size(); i++) { Symbol outputSymbol = node.getOutputSymbols().get(i); // If output symbol is used if (context.get().contains(outputSymbol)) { rewrittenOutputSymbolsBuilder.add(outputSymbol); // Add the value of the output symbol for each row for (int j = 0; j < node.getRows().size(); j++) { rowBuilders.get(j).add(node.getRows().get(j).get(i)); } } } List<List<Expression>> rewrittenRows = rowBuilders.stream() .map(ImmutableList.Builder::build) .collect(toImmutableList()); return new ValuesNode(node.getId(), rewrittenOutputSymbolsBuilder.build(), rewrittenRows); }
@Override public Void visitValues(ValuesNode node, Integer indent) { print(indent, "- Values => [%s]", formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); for (List<Expression> row : node.getRows()) { print(indent + 2, "(" + Joiner.on(", ").join(row) + ")"); } return null; }
@Override public Optional<PlanNodeStatsEstimate> calculate(ValuesNode node, StatsProvider sourceStats, Lookup lookup, Session session, TypeProvider types) { PlanNodeStatsEstimate.Builder statsBuilder = PlanNodeStatsEstimate.builder(); statsBuilder.setOutputRowCount(node.getRows().size()); for (int symbolId = 0; symbolId < node.getOutputSymbols().size(); ++symbolId) { Symbol symbol = node.getOutputSymbols().get(symbolId); List<Object> symbolValues = getSymbolValues(node, symbolId, session, types.get(symbol)); statsBuilder.addSymbolStatistics(symbol, buildSymbolStatistics(symbolValues, session, types.get(symbol))); } return Optional.of(statsBuilder.build()); }
@Override public Optional<PlanNodeStatsEstimate> calculate(ValuesNode node, StatsProvider sourceStats, Lookup lookup, Session session, TypeProvider types) { PlanNodeStatsEstimate.Builder statsBuilder = PlanNodeStatsEstimate.builder(); statsBuilder.setOutputRowCount(node.getRows().size()); for (int symbolId = 0; symbolId < node.getOutputSymbols().size(); ++symbolId) { Symbol symbol = node.getOutputSymbols().get(symbolId); List<Object> symbolValues = getSymbolValues(node, symbolId, session, types.get(symbol)); statsBuilder.addSymbolStatistics(symbol, buildSymbolStatistics(symbolValues, session, types.get(symbol))); } return Optional.of(statsBuilder.build()); }
@Override public PlanNode visitValues(ValuesNode node, RewriteContext<Void> context) { ValuesNode rewrittenNode = (ValuesNode) context.defaultRewrite(node); List<List<Expression>> rewrittenRows = rewrittenNode.getRows().stream() .map(row -> row.stream() .map(column -> replaceExpression(column, mapping)) .collect(toImmutableList())) .collect(toImmutableList()); return new ValuesNode( idAllocator.getNextId(), rewrittenNode.getOutputSymbols(), rewrittenRows); } }
@Override public PlanNode visitValues(ValuesNode node, RewriteContext<Void> context) { ValuesNode rewrittenNode = (ValuesNode) context.defaultRewrite(node); List<List<Expression>> rewrittenRows = rewrittenNode.getRows().stream() .map(row -> row.stream() .map(column -> replaceExpression(column, mapping)) .collect(toImmutableList())) .collect(toImmutableList()); return new ValuesNode( idAllocator.getNextId(), rewrittenNode.getOutputSymbols(), rewrittenRows); } }
@Override public Result apply(ValuesNode valuesNode, Captures captures, Context context) { boolean anyRewritten = false; ImmutableList.Builder<List<Expression>> rows = ImmutableList.builder(); for (List<Expression> row : valuesNode.getRows()) { ImmutableList.Builder<Expression> newRow = ImmutableList.builder(); for (Expression expression : row) { Expression rewritten = rewriter.rewrite(expression, context); if (!expression.equals(rewritten)) { anyRewritten = true; } newRow.add(rewritten); } rows.add(newRow.build()); } if (anyRewritten) { return Result.ofPlanNode(new ValuesNode(valuesNode.getId(), valuesNode.getOutputSymbols(), rows.build())); } return Result.empty(); } }
@Override public Result apply(ValuesNode valuesNode, Captures captures, Context context) { boolean anyRewritten = false; ImmutableList.Builder<List<Expression>> rows = ImmutableList.builder(); for (List<Expression> row : valuesNode.getRows()) { ImmutableList.Builder<Expression> newRow = ImmutableList.builder(); for (Expression expression : row) { Expression rewritten = rewriter.rewrite(expression, context); if (!expression.equals(rewritten)) { anyRewritten = true; } newRow.add(rewritten); } rows.add(newRow.build()); } if (anyRewritten) { return Result.ofPlanNode(new ValuesNode(valuesNode.getId(), valuesNode.getOutputSymbols(), rows.build())); } return Result.empty(); } }
@Override public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) { checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName()); ValuesNode valuesNode = (ValuesNode) node; if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows())).orElse(true)) { return NO_MATCH; } return match(SymbolAliases.builder() .putAll(Maps.transformValues(outputSymbolAliases, index -> valuesNode.getOutputSymbols().get(index).toSymbolReference())) .build()); }
@Override public MatchResult detailMatches(PlanNode node, StatsProvider stats, Session session, Metadata metadata, SymbolAliases symbolAliases) { checkState(shapeMatches(node), "Plan testing framework error: shapeMatches returned false in detailMatches in %s", this.getClass().getName()); ValuesNode valuesNode = (ValuesNode) node; if (!expectedRows.map(rows -> rows.equals(valuesNode.getRows())).orElse(true)) { return NO_MATCH; } return match(SymbolAliases.builder() .putAll(Maps.transformValues(outputSymbolAliases, index -> valuesNode.getOutputSymbols().get(index).toSymbolReference())) .build()); }
List<Type> outputTypes = getSymbolTypes(node.getOutputSymbols(), context.getTypes()); PageBuilder pageBuilder = new PageBuilder(node.getRows().size(), outputTypes); for (List<Expression> row : node.getRows()) {
List<Type> outputTypes = getSymbolTypes(node.getOutputSymbols(), context.getTypes()); PageBuilder pageBuilder = new PageBuilder(node.getRows().size(), outputTypes); for (List<Expression> row : node.getRows()) {