@Override public Boolean visitValues(ValuesNode node, Void context) { return node.getRows().size() == 1; }
@Override public Boolean visitValues(ValuesNode node, Void context) { return node.getRows().size() == 1; }
@Override public Void visitValues(ValuesNode node, ImmutableList.Builder<Expression> context) { node.getRows().forEach(context::addAll); return super.visitValues(node, context); }
@Override public Void visitValues(ValuesNode node, ImmutableList.Builder<Expression> context) { node.getRows().forEach(context::addAll); return super.visitValues(node, context); }
@Override public Range<Long> visitValues(ValuesNode node, Void context) { return Range.singleton((long) node.getRows().size()); }
@Override public Range<Long> visitValues(ValuesNode node, Void context) { return Range.singleton((long) node.getRows().size()); }
private List<Object> getSymbolValues(ValuesNode valuesNode, int symbolId, Session session, Type symbolType) { if (UNKNOWN.equals(symbolType)) { // special casing for UNKNOWN as evaluateConstantExpression does not handle that return IntStream.range(0, valuesNode.getRows().size()) .mapToObj(rowId -> null) .collect(toList()); } return valuesNode.getRows().stream() .map(row -> row.get(symbolId)) .map(expression -> evaluateConstantExpression(expression, symbolType, metadata, session, ImmutableList.of())) .collect(toList()); }
private List<Object> getSymbolValues(ValuesNode valuesNode, int symbolId, Session session, Type symbolType) { if (UNKNOWN.equals(symbolType)) { // special casing for UNKNOWN as evaluateConstantExpression does not handle that return IntStream.range(0, valuesNode.getRows().size()) .mapToObj(rowId -> null) .collect(toList()); } return valuesNode.getRows().stream() .map(row -> row.get(symbolId)) .map(expression -> evaluateConstantExpression(expression, symbolType, metadata, session, ImmutableList.of())) .collect(toList()); }
@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 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<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 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 Void visitValues(ValuesNode node, Integer indent) { output(indent, "values (%s rows)", node.getRows().size()); return null; }
@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 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 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()); }