@Override public PlanNode visitTableWriter(TableWriterNode node, RewriteContext<Context> context) { // Part of the plan should be an Optional<StateChangeListener<QueryState>> and this // callback can create the table and abort the table creation if the query fails. TableWriterNode.WriterTarget writerTarget = context.get().getMaterializedHandle(node.getTarget()).get(); return new TableWriterNode( node.getId(), node.getSource().accept(this, context), writerTarget, node.getRowCountSymbol(), node.getFragmentSymbol(), node.getColumns(), node.getColumnNames(), node.getPartitioningScheme(), node.getStatisticsAggregation(), node.getStatisticsAggregationDescriptor()); }
@Override public Void visitTableWriter(TableWriterNode node, Integer indent) { print(indent, "- TableWriter => [%s]", formatOutputs(node.getOutputSymbols())); printPlanNodesStatsAndCost(indent + 2, node); printStats(indent + 2, node.getId()); for (int i = 0; i < node.getColumnNames().size(); i++) { String name = node.getColumnNames().get(i); Symbol symbol = node.getColumns().get(i); print(indent + 2, "%s := %s", name, symbol); } if (node.getStatisticsAggregation().isPresent()) { verify(node.getStatisticsAggregationDescriptor().isPresent(), "statisticsAggregationDescriptor is not present"); printStatisticAggregations(node.getStatisticsAggregation().get(), node.getStatisticsAggregationDescriptor().get(), indent + 2); } return processChildren(node, indent + 1); }
@Override public PlanNode replaceChildren(List<PlanNode> newChildren) { return new TableWriterNode(getId(), Iterables.getOnlyElement(newChildren), target, rowCountSymbol, fragmentSymbol, columns, columnNames, partitioningScheme, statisticsAggregation, statisticsAggregationDescriptor); }
@Override public Void visitTableWriter(TableWriterNode node, Void context) { List<String> columns = new ArrayList<>(); for (int i = 0; i < node.getColumnNames().size(); i++) { columns.add(node.getColumnNames().get(i) + " := " + node.getColumns().get(i)); } printNode(node, format("TableWriter[%s]", Joiner.on(", ").join(columns)), NODE_COLORS.get(NodeType.TABLE_WRITER)); return node.getSource().accept(this, context); }
@Override public PlanNode visitTableWriter(TableWriterNode node, List<PlanNode> newChildren) { return new TableWriterNode( node.getId(), Iterables.getOnlyElement(newChildren), node.getTarget(), node.getColumns(), node.getColumnNames(), node.getOutputSymbols(), node.getSampleWeightSymbol(), node.getPartitionFunction()); }
if (node.getPartitioningScheme().isPresent()) { context.setDriverInstanceCount(1); PhysicalOperation source = node.getSource().accept(this, context); outputMapping.put(node.getOutputSymbols().get(0), ROW_COUNT_CHANNEL); outputMapping.put(node.getOutputSymbols().get(1), FRAGMENT_CHANNEL); OperatorFactory statisticsAggregation = node.getStatisticsAggregation().map(aggregation -> { List<Symbol> groupingSymbols = aggregation.getGroupingSymbols(); if (groupingSymbols.isEmpty()) { return createAggregationOperatorFactory( node.getId(), aggregation.getAggregations(), PARTIAL, node.getId(), aggregation.getAggregations(), ImmutableSet.of(), }).orElse(new DevNullOperatorFactory(context.getNextOperatorId(), node.getId())); List<Integer> inputChannels = node.getColumns().stream() .map(source::symbolToChannel) .collect(toImmutableList()); node.getId(), pageSinkManager, node.getTarget(),
@Override public PlanNode visitTableWriter(TableWriterNode node, RewriteContext<Void> context) PlanNode sourceNode = context.rewrite(node.getSource()); PlanNode unionOriginalSource = unionNode.getSources().get(i); ImmutableList.Builder<Symbol> newSymbols = ImmutableList.builder(); for (Symbol outputSymbol : node.getOutputSymbols()) { Symbol newSymbol = symbolAllocator.newSymbol(outputSymbol.getName(), symbolAllocator.getTypes().get(outputSymbol)); newSymbols.add(newSymbol); rewrittenSources.add(new TableWriterNode( idAllocator.getNextId(), unionOriginalSource, node.getTarget(), unionNode.sourceOutputLayout(i), node.getColumnNames(), newSymbols.build(), node.getSampleWeightSymbol(), node.getPartitionFunction()));
@Override public PhysicalOperation visitTableWriter(TableWriterNode node, LocalExecutionPlanContext context) { // serialize writes by forcing data through a single writer PhysicalOperation exchange = createInMemoryExchange(node.getSource(), context); Optional<Integer> sampleWeightChannel = node.getSampleWeightSymbol().map(exchange::symbolToChannel); // Set table writer count context.setDriverInstanceCount(getTaskWriterCount(session)); List<Integer> inputChannels = node.getColumns().stream() .map(exchange::symbolToChannel) .collect(toImmutableList()); OperatorFactory operatorFactory = new TableWriterOperatorFactory(context.getNextOperatorId(), node.getId(), pageSinkManager, node.getTarget(), inputChannels, sampleWeightChannel, session); Map<Symbol, Integer> layout = ImmutableMap.<Symbol, Integer>builder() .put(node.getOutputSymbols().get(0), 0) .put(node.getOutputSymbols().get(1), 1) .build(); return new PhysicalOperation(operatorFactory, layout, exchange); }
@Override public Void visitTableWriter(TableWriterNode node, Integer indent) { print(indent, "- TableWriter => [%s]", formatOutputs(node.getOutputSymbols())); for (int i = 0; i < node.getColumnNames().size(); i++) { String name = node.getColumnNames().get(i); Symbol symbol = node.getColumns().get(i); print(indent + 2, "%s := %s", name, symbol); } return processChildren(node, indent + 1); }
@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()); TableWriterNode tableWriterNode = (TableWriterNode) node; if (!tableWriterNode.getColumnNames().equals(columnNames)) { return NO_MATCH; } if (!columns.stream() .map(s -> Symbol.from(symbolAliases.get(s))) .collect(toImmutableList()) .equals(tableWriterNode.getColumns())) { return NO_MATCH; } return match(); }
public TableWriterNode tableWriter(List<Symbol> columns, List<String> columnNames, PlanNode source) { return new TableWriterNode( idAllocator.getNextId(), source, new TestingWriterTarget(), symbol("partialrows", BIGINT), symbol("fragment", VARBINARY), columns, columnNames, Optional.empty(), Optional.empty(), Optional.empty()); }
@Override public Void visitTableWriter(TableWriterNode node, Set<Symbol> boundSymbols) { PlanNode source = node.getSource(); source.accept(this, boundSymbols); // visit child return null; }
@Override public Void visitTableWriter(TableWriterNode node, Void context) { node.getSource().accept(this, context); builder.addAll(node.getOutputSymbols()); return null; }
public TableWriterNode.WriterTarget getTarget(PlanNode node) { if (node instanceof TableWriterNode) { return ((TableWriterNode) node).getTarget(); } if (node instanceof DeleteNode) { return ((DeleteNode) node).getTarget(); } if (node instanceof ExchangeNode || node instanceof UnionNode) { Set<TableWriterNode.WriterTarget> writerTargets = node.getSources().stream() .map(this::getTarget) .collect(toSet()); return Iterables.getOnlyElement(writerTargets); } throw new IllegalArgumentException("Invalid child for TableCommitNode: " + node.getClass().getSimpleName()); }
@Override public PlanWithProperties visitTableWriter(TableWriterNode node, PreferredProperties preferredProperties) { PlanWithProperties source = node.getSource().accept(this, preferredProperties); Optional<PartitioningScheme> partitioningScheme = node.getPartitioningScheme(); if (!partitioningScheme.isPresent()) { if (scaleWriters) { partitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(SCALED_WRITER_DISTRIBUTION, ImmutableList.of()), source.getNode().getOutputSymbols())); } else if (redistributeWrites) { partitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(FIXED_ARBITRARY_DISTRIBUTION, ImmutableList.of()), source.getNode().getOutputSymbols())); } } if (partitioningScheme.isPresent() && !source.getProperties().isCompatibleTablePartitioningWith(partitioningScheme.get().getPartitioning(), false, metadata, session)) { source = withDerivedProperties( partitionedExchange( idAllocator.getNextId(), REMOTE, source.getNode(), partitioningScheme.get()), source.getProperties()); } return rebaseAndDeriveProperties(node, source); }
@Override public Void visitTableWriter(TableWriterNode node, Void context) { PlanNode source = node.getSource(); source.accept(this, context); // visit child verifyUniqueId(node); if (node.getSampleWeightSymbol().isPresent()) { checkArgument(source.getOutputSymbols().contains(node.getSampleWeightSymbol().get()), "Invalid node. Sample weight symbol (%s) is not in source plan output (%s)", node.getSampleWeightSymbol().get(), node.getSource().getOutputSymbols()); } return null; }
@Override public PlanWithProperties visitTableWriter(TableWriterNode node, Context context) { PlanWithProperties source = node.getSource().accept(this, context); Optional<PartitionFunctionBinding> partitionFunction = node.getPartitionFunction(); if (!partitionFunction.isPresent() && redistributeWrites) { partitionFunction = Optional.of(new PartitionFunctionBinding(FIXED_RANDOM_DISTRIBUTION, source.getNode().getOutputSymbols(), ImmutableList.of())); } if (partitionFunction.isPresent()) { source = withDerivedProperties( partitionedExchange( idAllocator.getNextId(), source.getNode(), partitionFunction.get()), source.getProperties() ); } return rebaseAndDeriveProperties(node, source); }
public TableWriterNode map(TableWriterNode node, PlanNode source) { return map(node, source, node.getId()); }
private static TableWriterNode rewriteSource( TableWriterNode writerNode, UnionNode unionNode, int source, List<Map<Symbol, Symbol>> sourceMappings, Context context) { Map<Symbol, Symbol> inputMappings = getInputSymbolMapping(unionNode, source); ImmutableMap.Builder<Symbol, Symbol> mappings = ImmutableMap.builder(); mappings.putAll(inputMappings); ImmutableMap.Builder<Symbol, Symbol> outputMappings = ImmutableMap.builder(); for (Symbol outputSymbol : writerNode.getOutputSymbols()) { if (inputMappings.containsKey(outputSymbol)) { outputMappings.put(outputSymbol, inputMappings.get(outputSymbol)); } else { Symbol newSymbol = context.getSymbolAllocator().newSymbol(outputSymbol); outputMappings.put(outputSymbol, newSymbol); mappings.put(outputSymbol, newSymbol); } } sourceMappings.add(outputMappings.build()); SymbolMapper symbolMapper = new SymbolMapper(mappings.build()); return symbolMapper.map(writerNode, unionNode.getSources().get(source), context.getIdAllocator().getNextId()); }
@Override public PlanNode visitTableWriter(TableWriterNode node, RewriteContext<Context> context) { // Part of the plan should be an Optional<StateChangeListener<QueryState>> and this // callback can create the table and abort the table creation if the query fails. TableWriterNode.WriterTarget writerTarget = context.get().getMaterializedHandle(node.getTarget()).get(); return new TableWriterNode( node.getId(), node.getSource().accept(this, context), writerTarget, node.getColumns(), node.getColumnNames(), node.getOutputSymbols(), node.getSampleWeightSymbol(), node.getPartitionFunction()); }