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 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); }
outputMapping.put(node.getOutputSymbols().get(0), ROW_COUNT_CHANNEL); outputMapping.put(node.getOutputSymbols().get(1), FRAGMENT_CHANNEL); session, statisticsAggregation, getSymbolTypes(node.getOutputSymbols(), context.getTypes()));
@Override public Void visitTableWriter(TableWriterNode node, Void context) { node.getSource().accept(this, context); builder.addAll(node.getOutputSymbols()); return null; }
@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 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 PlanNode visitTableWriter(TableWriterNode node, RewriteContext<Set<Symbol>> context) { ImmutableSet.Builder<Symbol> expectedInputs = ImmutableSet.<Symbol>builder() .addAll(node.getColumns()); if (node.getSampleWeightSymbol().isPresent()) { expectedInputs.add(node.getSampleWeightSymbol().get()); } if (node.getPartitionFunction().isPresent()) { PartitionFunctionBinding functionBinding = node.getPartitionFunction().get(); functionBinding.getPartitionFunctionArguments().stream() .filter(PartitionFunctionArgumentBinding::isVariable) .map(PartitionFunctionArgumentBinding::getColumn) .forEach(expectedInputs::add); functionBinding.getHashColumn().ifPresent(expectedInputs::add); } PlanNode source = context.rewrite(node.getSource(), expectedInputs.build()); return new TableWriterNode( node.getId(), source, node.getTarget(), node.getColumns(), node.getColumnNames(), node.getOutputSymbols(), node.getSampleWeightSymbol(), node.getPartitionFunction()); }
@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()); }
@Override public PlanNode visitTableWriter(TableWriterNode node, RewriteContext<Void> context) { PlanNode source = context.rewrite(node.getSource()); // Intentionally does not use canonicalizeAndDistinct as that would remove columns ImmutableList<Symbol> columns = node.getColumns().stream() .map(this::canonicalize) .collect(toImmutableList()); return new TableWriterNode( node.getId(), source, node.getTarget(), columns, node.getColumnNames(), node.getOutputSymbols(), canonicalize(node.getSampleWeightSymbol()), node.getPartitionFunction().map(this::canonicalizePartitionFunctionBinding)); }
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);
@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()); }