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()); }
public TableWriterNode map(TableWriterNode node, PlanNode source, PlanNodeId newNodeId) { // Intentionally does not use canonicalizeAndDistinct as that would remove columns ImmutableList<Symbol> columns = node.getColumns().stream() .map(this::map) .collect(toImmutableList()); return new TableWriterNode( newNodeId, source, node.getTarget(), map(node.getRowCountSymbol()), map(node.getFragmentSymbol()), columns, node.getColumnNames(), node.getPartitioningScheme().map(partitioningScheme -> canonicalize(partitioningScheme, source)), node.getStatisticsAggregation().map(this::map), node.getStatisticsAggregationDescriptor().map(this::map)); }
@Override public PlanNode visitTableWriter(TableWriterNode node, RewriteContext<Set<Symbol>> context) { ImmutableSet.Builder<Symbol> expectedInputs = ImmutableSet.<Symbol>builder() .addAll(node.getColumns()); if (node.getPartitioningScheme().isPresent()) { PartitioningScheme partitioningScheme = node.getPartitioningScheme().get(); partitioningScheme.getPartitioning().getColumns().forEach(expectedInputs::add); partitioningScheme.getHashColumn().ifPresent(expectedInputs::add); } if (node.getStatisticsAggregation().isPresent()) { StatisticAggregations aggregations = node.getStatisticsAggregation().get(); expectedInputs.addAll(aggregations.getGroupingSymbols()); aggregations.getAggregations().values().forEach(aggregation -> expectedInputs.addAll(SymbolsExtractor.extractUnique(aggregation.getCall()))); } PlanNode source = context.rewrite(node.getSource(), expectedInputs.build()); return new TableWriterNode( node.getId(), source, node.getTarget(), node.getRowCountSymbol(), node.getFragmentSymbol(), node.getColumns(), node.getColumnNames(), node.getPartitioningScheme(), node.getStatisticsAggregation(), node.getStatisticsAggregationDescriptor()); }
node.getId(), pageSinkManager, node.getTarget(), inputChannels, session,
@Override public Void visitTableWriter(TableWriterNode node, Void context) { TableWriterNode.WriterTarget writerTarget = node.getTarget(); if (writerTarget instanceof TableWriterNode.CreateHandle) { connectorId = ((TableWriterNode.CreateHandle) writerTarget).getHandle().getConnectorId(); checkState(schemaTableName == null || schemaTableName.equals(((TableWriterNode.CreateHandle) writerTarget).getSchemaTableName()), "cannot have more than a single create, insert or delete in a query"); schemaTableName = ((TableWriterNode.CreateHandle) writerTarget).getSchemaTableName(); } if (writerTarget instanceof TableWriterNode.InsertHandle) { connectorId = ((TableWriterNode.InsertHandle) writerTarget).getHandle().getConnectorId(); checkState(schemaTableName == null || schemaTableName.equals(((TableWriterNode.InsertHandle) writerTarget).getSchemaTableName()), "cannot have more than a single create, insert or delete in a query"); schemaTableName = ((TableWriterNode.InsertHandle) writerTarget).getSchemaTableName(); } if (writerTarget instanceof TableWriterNode.DeleteHandle) { connectorId = ((TableWriterNode.DeleteHandle) writerTarget).getHandle().getConnectorId(); checkState(schemaTableName == null || schemaTableName.equals(((TableWriterNode.DeleteHandle) writerTarget).getSchemaTableName()), "cannot have more than a single create, insert or delete in a query"); schemaTableName = ((TableWriterNode.DeleteHandle) writerTarget).getSchemaTableName(); } return null; }
@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()); }
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 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)); }
idAllocator.getNextId(), unionOriginalSource, node.getTarget(), unionNode.sourceOutputLayout(i), node.getColumnNames(),
@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()); }