@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) { 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); } }
public ValuesNode values(PlanNodeId id, List<Symbol> columns, List<List<Expression>> rows) { return new ValuesNode(id, columns, rows); }
@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 Boolean visitValues(ValuesNode node, Void context) { return node.getRows().size() == 1; }
public ValuesNode values(PlanNodeId id, List<Symbol> columns, List<List<Expression>> rows) { return new ValuesNode(id, columns, rows); }
@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 Boolean visitValues(ValuesNode node, Void context) { return node.getRows().size() == 1; }
@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) { 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); }
private RelationPlan planImplicitTable() { List<Expression> emptyRow = ImmutableList.of(); Scope scope = Scope.create(); return new RelationPlan( new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of(emptyRow)), scope, ImmutableList.of()); }
if (node.getRows().isEmpty()) { OperatorFactory operatorFactory = new ValuesOperatorFactory(context.getNextOperatorId(), node.getId(), ImmutableList.of()); return new PhysicalOperation(operatorFactory, makeLayout(node), context, UNGROUPED_EXECUTION); List<Type> outputTypes = getSymbolTypes(node.getOutputSymbols(), context.getTypes()); PageBuilder pageBuilder = new PageBuilder(node.getRows().size(), outputTypes); for (List<Expression> row : node.getRows()) { pageBuilder.declarePosition(); Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes( OperatorFactory operatorFactory = new ValuesOperatorFactory(context.getNextOperatorId(), node.getId(), ImmutableList.of(pageBuilder.build())); return new PhysicalOperation(operatorFactory, makeLayout(node), context, UNGROUPED_EXECUTION);
@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 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())); } }
private RelationPlan planImplicitTable() { List<Expression> emptyRow = ImmutableList.of(); Scope scope = Scope.create(); return new RelationPlan( new ValuesNode(idAllocator.getNextId(), ImmutableList.of(), ImmutableList.of(emptyRow)), scope, ImmutableList.of()); }
if (node.getRows().isEmpty()) { OperatorFactory operatorFactory = new ValuesOperatorFactory(context.getNextOperatorId(), node.getId(), ImmutableList.of()); return new PhysicalOperation(operatorFactory, makeLayout(node), context, UNGROUPED_EXECUTION); List<Type> outputTypes = getSymbolTypes(node.getOutputSymbols(), context.getTypes()); PageBuilder pageBuilder = new PageBuilder(node.getRows().size(), outputTypes); for (List<Expression> row : node.getRows()) { pageBuilder.declarePosition(); Map<NodeRef<Expression>, Type> expressionTypes = getExpressionTypes( OperatorFactory operatorFactory = new ValuesOperatorFactory(context.getNextOperatorId(), node.getId(), ImmutableList.of(pageBuilder.build())); return new PhysicalOperation(operatorFactory, makeLayout(node), context, UNGROUPED_EXECUTION);
@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()); }