From 170b3778abb58e85c3de99a9b2ed2605b261c45f Mon Sep 17 00:00:00 2001 From: jaystarshot Date: Mon, 2 Dec 2024 15:34:23 -0800 Subject: [PATCH] Add TemporaryTableInfo to tablescan and tablewrite planNodes --- .../optimization/JdbcComputePushdown.java | 3 +- .../ClickHouseComputePushdown.java | 6 ++-- .../presto/druid/DruidPlanOptimizer.java | 3 +- .../presto/druid/TestDruidQueryBase.java | 2 +- .../rule/BaseSubfieldExtractionRewriter.java | 3 +- .../rule/HiveAddRequestedColumnsToLayout.java | 3 +- .../rule/HivePartialAggregationPushdown.java | 3 +- .../IcebergEqualityDeleteAsJoin.java | 6 ++-- .../optimizer/IcebergPlanOptimizer.java | 3 +- .../presto/sql/TemporaryTableUtil.java | 24 ++++++++++----- .../sql/planner/BasePlanFragmenter.java | 3 +- .../sql/planner/CanonicalPlanGenerator.java | 3 +- .../presto/sql/planner/LogicalPlanner.java | 12 +++++--- .../sql/planner/PlanFragmenterUtils.java | 5 ++-- .../presto/sql/planner/PlannerUtils.java | 2 +- .../presto/sql/planner/QueryPlanner.java | 4 +-- .../presto/sql/planner/RelationPlanner.java | 3 +- .../iterative/rule/PickTableLayout.java | 6 ++-- .../iterative/rule/PruneTableScanColumns.java | 2 +- .../rule/RowExpressionRewriteRuleSet.java | 5 ++-- .../iterative/rule/ScaledWriterRule.java | 2 +- .../optimizations/AddLocalExchanges.java | 6 ++-- .../optimizations/PhysicalCteOptimizer.java | 9 ++++-- .../PruneUnreferencedOutputs.java | 8 +++-- .../optimizations/PushdownSubfields.java | 2 +- .../planner/optimizations/SymbolMapper.java | 5 ++-- .../presto/cost/TestCostCalculator.java | 2 +- .../execution/MockRemoteTaskFactory.java | 2 +- .../presto/execution/TaskTestUtils.java | 2 +- .../TestPhasedExecutionSchedule.java | 4 +-- .../TestSourcePartitionedScheduler.java | 3 +- .../facebook/presto/operator/TestDriver.java | 2 +- .../TestEffectivePredicateExtractor.java | 14 ++++----- .../planner/TestLocalExecutionPlanner.java | 2 +- .../presto/sql/planner/TestTypeValidator.java | 2 +- .../iterative/rule/test/PlanBuilder.java | 6 ++-- .../TestConnectorOptimization.java | 2 +- .../presto/util/TestGraphvizPrinter.java | 2 +- .../rule/ParquetDereferencePushDown.java | 3 +- .../presto/pinot/PinotPlanOptimizer.java | 3 +- .../planner/TestIterativePlanFragmenter.java | 2 +- .../presto/spi/plan/TableFinishNode.java | 22 ++++++++++---- .../presto/spi/plan/TableScanNode.java | 22 ++++++++++---- .../presto/spi/plan/TableWriterNode.java | 22 +++++++------- .../presto/spi/plan/TemporaryTableInfo.java | 29 +++++++++++++++++++ 45 files changed, 183 insertions(+), 96 deletions(-) create mode 100644 presto-spi/src/main/java/com/facebook/presto/spi/plan/TemporaryTableInfo.java diff --git a/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/optimization/JdbcComputePushdown.java b/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/optimization/JdbcComputePushdown.java index e0ad9a3282f38..cffe5ab581113 100644 --- a/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/optimization/JdbcComputePushdown.java +++ b/presto-base-jdbc/src/main/java/com/facebook/presto/plugin/jdbc/optimization/JdbcComputePushdown.java @@ -139,7 +139,8 @@ public PlanNode visitFilter(FilterNode node, RewriteContext context) oldTableScanNode.getAssignments(), oldTableScanNode.getTableConstraints(), oldTableScanNode.getCurrentConstraint(), - oldTableScanNode.getEnforcedConstraint()); + oldTableScanNode.getEnforcedConstraint(), + oldTableScanNode.getTemporaryTableInfo()); return new FilterNode(node.getSourceLocation(), idAllocator.getNextId(), newTableScanNode, node.getPredicate()); } diff --git a/presto-clickhouse/src/main/java/com/facebook/presto/plugin/clickhouse/optimization/ClickHouseComputePushdown.java b/presto-clickhouse/src/main/java/com/facebook/presto/plugin/clickhouse/optimization/ClickHouseComputePushdown.java index c025db58fa542..d0caaf14078ca 100755 --- a/presto-clickhouse/src/main/java/com/facebook/presto/plugin/clickhouse/optimization/ClickHouseComputePushdown.java +++ b/presto-clickhouse/src/main/java/com/facebook/presto/plugin/clickhouse/optimization/ClickHouseComputePushdown.java @@ -200,7 +200,8 @@ private Optional tryCreatingNewScanNode(PlanNode plan) ImmutableList.copyOf(assignments.keySet()), assignments.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, (e) -> (ColumnHandle) (e.getValue()))), tableScanNode.getCurrentConstraint(), - tableScanNode.getEnforcedConstraint())); + tableScanNode.getEnforcedConstraint(), + tableScanNode.getTemporaryTableInfo())); } @Override @@ -288,7 +289,8 @@ public PlanNode visitFilter(FilterNode node, Void context) oldTableScanNode.getOutputVariables(), oldTableScanNode.getAssignments(), oldTableScanNode.getCurrentConstraint(), - oldTableScanNode.getEnforcedConstraint()); + oldTableScanNode.getEnforcedConstraint(), + oldTableScanNode.getTemporaryTableInfo()); return new FilterNode(node.getSourceLocation(), idAllocator.getNextId(), newTableScanNode, node.getPredicate()); } diff --git a/presto-druid/src/main/java/com/facebook/presto/druid/DruidPlanOptimizer.java b/presto-druid/src/main/java/com/facebook/presto/druid/DruidPlanOptimizer.java index 81401f78c8c7b..c2c879eb537f8 100644 --- a/presto-druid/src/main/java/com/facebook/presto/druid/DruidPlanOptimizer.java +++ b/presto-druid/src/main/java/com/facebook/presto/druid/DruidPlanOptimizer.java @@ -173,7 +173,8 @@ private Optional tryCreatingNewScanNode(PlanNode plan) assignments.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, (e) -> (ColumnHandle) (e.getValue()))), tableScanNode.getTableConstraints(), tableScanNode.getCurrentConstraint(), - tableScanNode.getEnforcedConstraint())); + tableScanNode.getEnforcedConstraint(), + tableScanNode.getTemporaryTableInfo())); } @Override diff --git a/presto-druid/src/test/java/com/facebook/presto/druid/TestDruidQueryBase.java b/presto-druid/src/test/java/com/facebook/presto/druid/TestDruidQueryBase.java index 428d6d7bf300d..912e970b709f5 100644 --- a/presto-druid/src/test/java/com/facebook/presto/druid/TestDruidQueryBase.java +++ b/presto-druid/src/test/java/com/facebook/presto/druid/TestDruidQueryBase.java @@ -147,7 +147,7 @@ protected TableScanNode tableScan(PlanBuilder planBuilder, DruidTableHandle conn variables, assignments.build(), TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); } protected FilterNode filter(PlanBuilder planBuilder, PlanNode source, RowExpression predicate) diff --git a/presto-hive-common/src/main/java/com/facebook/presto/hive/rule/BaseSubfieldExtractionRewriter.java b/presto-hive-common/src/main/java/com/facebook/presto/hive/rule/BaseSubfieldExtractionRewriter.java index 917760aa090c2..3f459c122d0ed 100644 --- a/presto-hive-common/src/main/java/com/facebook/presto/hive/rule/BaseSubfieldExtractionRewriter.java +++ b/presto-hive-common/src/main/java/com/facebook/presto/hive/rule/BaseSubfieldExtractionRewriter.java @@ -307,7 +307,8 @@ private static TableScanNode getTableScanNode( tableScan.getAssignments(), tableScan.getTableConstraints(), pushdownFilterResult.getLayout().getPredicate(), - TupleDomain.all()); + TupleDomain.all(), + tableScan.getTemporaryTableInfo()); } private static ExtractionResult intersectExtractionResult( diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/rule/HiveAddRequestedColumnsToLayout.java b/presto-hive/src/main/java/com/facebook/presto/hive/rule/HiveAddRequestedColumnsToLayout.java index 2e159874a582f..713f07f1935af 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/rule/HiveAddRequestedColumnsToLayout.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/rule/HiveAddRequestedColumnsToLayout.java @@ -71,7 +71,8 @@ public PlanNode visitTableScan(TableScanNode tableScan, RewriteContext con tableScan.getAssignments(), tableScan.getTableConstraints(), tableScan.getCurrentConstraint(), - tableScan.getEnforcedConstraint()); + tableScan.getEnforcedConstraint(), + tableScan.getTemporaryTableInfo()); } } } diff --git a/presto-hive/src/main/java/com/facebook/presto/hive/rule/HivePartialAggregationPushdown.java b/presto-hive/src/main/java/com/facebook/presto/hive/rule/HivePartialAggregationPushdown.java index d5efb222fd16a..8bec754d5071d 100644 --- a/presto-hive/src/main/java/com/facebook/presto/hive/rule/HivePartialAggregationPushdown.java +++ b/presto-hive/src/main/java/com/facebook/presto/hive/rule/HivePartialAggregationPushdown.java @@ -297,7 +297,8 @@ private Optional tryPartialAggregationPushdown(PlanNode plan) ImmutableMap.copyOf(assignments), oldTableScanNode.getTableConstraints(), oldTableScanNode.getCurrentConstraint(), - oldTableScanNode.getEnforcedConstraint())); + oldTableScanNode.getEnforcedConstraint(), + oldTableScanNode.getTemporaryTableInfo())); } @Override diff --git a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/optimizer/IcebergEqualityDeleteAsJoin.java b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/optimizer/IcebergEqualityDeleteAsJoin.java index d5d8a919c6a3f..aae7d14b708c8 100644 --- a/presto-iceberg/src/main/java/com/facebook/presto/iceberg/optimizer/IcebergEqualityDeleteAsJoin.java +++ b/presto-iceberg/src/main/java/com/facebook/presto/iceberg/optimizer/IcebergEqualityDeleteAsJoin.java @@ -341,7 +341,8 @@ private TableScanNode createDeletesTableScan(ImmutableMap context) .intersect(tableScan.getCurrentConstraint()), predicateNotChangedBySimplification ? identityPartitionColumnPredicate.intersect(tableScan.getEnforcedConstraint()) : - tableScan.getEnforcedConstraint()); + tableScan.getEnforcedConstraint(), + tableScan.getTemporaryTableInfo()); if (TRUE_CONSTANT.equals(remainingFilterExpression) && predicateNotChangedBySimplification) { return newTableScan; diff --git a/presto-main/src/main/java/com/facebook/presto/sql/TemporaryTableUtil.java b/presto-main/src/main/java/com/facebook/presto/sql/TemporaryTableUtil.java index f40bc95a8d0a2..542bf2a05b888 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/TemporaryTableUtil.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/TemporaryTableUtil.java @@ -45,6 +45,7 @@ import com.facebook.presto.spi.plan.TableFinishNode; import com.facebook.presto.spi.plan.TableScanNode; import com.facebook.presto.spi.plan.TableWriterNode; +import com.facebook.presto.spi.plan.TemporaryTableInfo; import com.facebook.presto.spi.relation.CallExpression; import com.facebook.presto.spi.relation.ConstantExpression; import com.facebook.presto.spi.relation.RowExpression; @@ -82,6 +83,7 @@ import static com.google.common.collect.ImmutableSet.toImmutableSet; import static com.google.common.collect.Iterables.concat; import static java.lang.String.format; +import static java.util.Collections.emptyList; import static java.util.function.Function.identity; // Planner Util for creating temporary tables @@ -99,7 +101,8 @@ public static TableScanNode createTemporaryTableScan( TableHandle tableHandle, List outputVariables, Map variableToColumnMap, - Optional expectedPartitioningMetadata) + Optional expectedPartitioningMetadata, + Optional cteId) { Map columnHandles = metadata.getColumnHandles(session, tableHandle); Map outputColumns = outputVariables.stream() @@ -126,11 +129,14 @@ public static TableScanNode createTemporaryTableScan( return new TableScanNode( sourceLocation, idAllocator.getNextId(), + Optional.empty(), selectedLayout.getLayout().getNewTableHandle(), outputVariables, assignments, + emptyList(), + TupleDomain.all(), TupleDomain.all(), - TupleDomain.all()); + cteId.map(TemporaryTableInfo::new)); } public static Map assignTemporaryTableColumnNames(Collection outputVariables, @@ -181,7 +187,8 @@ public static TableFinishNode createTemporaryTableWriteWithoutExchanges( TableHandle tableHandle, List outputs, Map variableToColumnMap, - VariableReferenceExpression outputVar) + VariableReferenceExpression outputVar, + Optional cteId) { SchemaTableName schemaTableName = metadata.getTableMetadata(session, tableHandle).getTable(); TableWriterNode.InsertReference insertReference = new TableWriterNode.InsertReference(tableHandle, schemaTableName); @@ -211,11 +218,12 @@ public static TableFinishNode createTemporaryTableWriteWithoutExchanges( Optional.empty(), Optional.empty(), Optional.empty(), - Optional.of(Boolean.TRUE)), + cteId.map(TemporaryTableInfo::new)), Optional.of(insertReference), outputVar, Optional.empty(), - Optional.empty()); + Optional.empty(), + cteId.map(TemporaryTableInfo::new)); } public static TableFinishNode createTemporaryTableWriteWithExchanges( @@ -347,12 +355,11 @@ public static TableFinishNode createTemporaryTableWriteWithExchanges( Optional.of(partitioningScheme), enableStatsCollectionForTemporaryTable ? Optional.of(localAggregations.getPartialAggregation()) : Optional.empty(), Optional.empty(), - Optional.of(Boolean.TRUE))), + Optional.empty())), variableAllocator.newVariable("intermediaterows", BIGINT), variableAllocator.newVariable("intermediatefragments", VARBINARY), variableAllocator.newVariable("intermediatetablecommitcontext", VARBINARY), enableStatsCollectionForTemporaryTable ? Optional.of(localAggregations.getIntermediateAggregation()) : Optional.empty()); - return new TableFinishNode( sourceLocation, idAllocator.getNextId(), @@ -363,7 +370,8 @@ public static TableFinishNode createTemporaryTableWriteWithExchanges( Optional.of(insertReference), variableAllocator.newVariable("rows", BIGINT), enableStatsCollectionForTemporaryTable ? Optional.of(aggregations.getFinalAggregation()) : Optional.empty(), - enableStatsCollectionForTemporaryTable ? Optional.of(statisticsResult.getDescriptor()) : Optional.empty()); + enableStatsCollectionForTemporaryTable ? Optional.of(statisticsResult.getDescriptor()) : Optional.empty(), + Optional.empty()); } public static StatisticAggregations.Parts splitIntoPartialAndFinal(StatisticAggregations statisticAggregations, VariableAllocator variableAllocator, FunctionAndTypeManager functionAndTypeManager) diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/BasePlanFragmenter.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/BasePlanFragmenter.java index eba7eeb25efd6..f3c44dff50b63 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/BasePlanFragmenter.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/BasePlanFragmenter.java @@ -374,7 +374,8 @@ private PlanNode createRemoteMaterializedExchange(ExchangeNode exchange, Rewrite temporaryTableHandle, exchange.getOutputVariables(), variableToColumnMap, - Optional.of(partitioningMetadata)); + Optional.of(partitioningMetadata), + Optional.empty()); checkArgument( !exchange.getPartitioningScheme().isReplicateNullsAndAny(), diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/CanonicalPlanGenerator.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/CanonicalPlanGenerator.java index 9ffc5fbeda66d..56ae99a63aa6f 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/CanonicalPlanGenerator.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/CanonicalPlanGenerator.java @@ -252,7 +252,8 @@ public Optional visitTableFinish(TableFinishNode node, Context context node.getTarget().map(target -> CanonicalWriterTarget.from(target)), node.getRowCountVariable(), Optional.empty(), - Optional.empty()); + Optional.empty(), + node.getTemporaryTableInfo()); context.addPlan(node, new CanonicalPlan(result, strategy)); return Optional.of(result); } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java index 9d0d1aaaf1804..95f9c1def4da8 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/LogicalPlanner.java @@ -239,7 +239,7 @@ private RelationPlan createAnalyzePlan(Analysis analysis, Analyze analyzeStateme .putAll(tableScanOutputs.stream().collect(toImmutableMap(identity(), identity()))) .putAll(tableStatisticAggregation.getAdditionalVariables()) .build(); - TableScanNode scanNode = new TableScanNode(getSourceLocation(analyzeStatement), idAllocator.getNextId(), targetTable, tableScanOutputs, variableToColumnHandle.build(), TupleDomain.all(), TupleDomain.all()); + TableScanNode scanNode = new TableScanNode(getSourceLocation(analyzeStatement), idAllocator.getNextId(), targetTable, tableScanOutputs, variableToColumnHandle.build(), TupleDomain.all(), TupleDomain.all(), Optional.empty()); PlanNode project = PlannerUtils.addProjections(scanNode, idAllocator, assignments); PlanNode planNode = new StatisticsWriterNode( getSourceLocation(analyzeStatement), @@ -435,13 +435,14 @@ private RelationPlan createTableWriterPlan( // the data consumed by the TableWriteOperator Optional.of(aggregations.getPartialAggregation()), Optional.empty(), - Optional.of(Boolean.FALSE)), + Optional.empty()), Optional.of(target), variableAllocator.newVariable("rows", BIGINT), // final aggregation is run within the TableFinishOperator to summarize collected statistics // by the partial aggregation from all of the writer nodes Optional.of(aggregations.getFinalAggregation()), - Optional.of(result.getDescriptor())); + Optional.of(result.getDescriptor()), + Optional.empty()); return new RelationPlan(commitNode, analysis.getRootScope(), commitNode.getOutputVariables()); } @@ -463,10 +464,11 @@ private RelationPlan createTableWriterPlan( tablePartitioningScheme, Optional.empty(), Optional.empty(), - Optional.of(Boolean.FALSE)), + Optional.empty()), Optional.of(target), variableAllocator.newVariable("rows", BIGINT), Optional.empty(), + Optional.empty(), Optional.empty()); return new RelationPlan(commitNode, analysis.getRootScope(), commitNode.getOutputVariables()); } @@ -486,6 +488,7 @@ private RelationPlan createDeletePlan(Analysis analysis, Delete node) Optional.of(deleteHandle), variableAllocator.newVariable("rows", BIGINT), Optional.empty(), + Optional.empty(), Optional.empty()); return new RelationPlan(commitNode, analysis.getScope(node), commitNode.getOutputVariables()); @@ -527,6 +530,7 @@ private RelationPlan createUpdatePlan(Analysis analysis, Update node) Optional.of(updateTarget), variableAllocator.newVariable("rows", BIGINT), Optional.empty(), + Optional.empty(), Optional.empty()); return new RelationPlan(commitNode, analysis.getScope(node), commitNode.getOutputVariables()); diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/PlanFragmenterUtils.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/PlanFragmenterUtils.java index d93be0f969d4d..263c84a9463d4 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/PlanFragmenterUtils.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/PlanFragmenterUtils.java @@ -254,7 +254,7 @@ public static Set getOutputTableWriterNodeIds(PlanNode plan) return stream(forTree(PlanNode::getSources).depthFirstPreOrder(plan)) .filter(node -> node instanceof TableWriterNode) .map(node -> (TableWriterNode) node) - .filter(tableWriterNode -> !tableWriterNode.getIsTemporaryTableWriter().orElse(false)) + .filter(tableWriterNode -> !tableWriterNode.getTemporaryTableInfo().isPresent()) .map(TableWriterNode::getId) .collect(toImmutableSet()); } @@ -304,7 +304,8 @@ public PlanNode visitTableScan(TableScanNode node, RewriteContext context) node.getOutputVariables(), node.getAssignments(), node.getCurrentConstraint(), - node.getEnforcedConstraint()); + node.getEnforcedConstraint(), + node.getTemporaryTableInfo()); } } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/PlannerUtils.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/PlannerUtils.java index bd21f4234b272..7bd215f6a9fd5 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/PlannerUtils.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/PlannerUtils.java @@ -357,7 +357,7 @@ private static TableScanNode cloneTableScan(TableScanNode scanNode, Session sess newAssignments, scanNode.getTableConstraints(), scanNode.getCurrentConstraint(), - scanNode.getEnforcedConstraint()); + scanNode.getEnforcedConstraint(), scanNode.getTemporaryTableInfo()); } public static PlanNode clonePlanNode(PlanNode planNode, Session session, Metadata metadata, PlanNodeIdAllocator planNodeIdAllocator, List fieldsToKeep, Map varMap) diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/QueryPlanner.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/QueryPlanner.java index 35487e1bf9984..023eb52fe1623 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/QueryPlanner.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/QueryPlanner.java @@ -275,7 +275,7 @@ public DeleteNode plan(Delete node) // create table scan List outputVariables = outputVariablesBuilder.build(); - PlanNode tableScan = new TableScanNode(getSourceLocation(node), idAllocator.getNextId(), handle, outputVariables, columns.build(), TupleDomain.all(), TupleDomain.all()); + PlanNode tableScan = new TableScanNode(getSourceLocation(node), idAllocator.getNextId(), handle, outputVariables, columns.build(), TupleDomain.all(), TupleDomain.all(), Optional.empty()); Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields.build())).build(); RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputVariables); @@ -344,7 +344,7 @@ public UpdateNode plan(Update node) // create table scan List outputVariables = outputVariablesBuilder.build(); - PlanNode tableScan = new TableScanNode(getSourceLocation(node), idAllocator.getNextId(), handle, outputVariables, columns.build(), TupleDomain.all(), TupleDomain.all()); + PlanNode tableScan = new TableScanNode(getSourceLocation(node), idAllocator.getNextId(), handle, outputVariables, columns.build(), TupleDomain.all(), TupleDomain.all(), Optional.empty()); Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields.build())).build(); RelationPlan relationPlan = new RelationPlan(tableScan, scope, outputVariables); diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/RelationPlanner.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/RelationPlanner.java index 1fb46f320c931..e260ea6b98d82 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/RelationPlanner.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/RelationPlanner.java @@ -219,7 +219,8 @@ protected RelationPlan visitTable(Table node, SqlPlannerContext context) List outputVariables = outputVariablesBuilder.build(); List> tableConstraints = metadata.getTableMetadata(session, handle).getMetadata().getTableConstraintsHolder().getTableConstraintsWithColumnHandles(); context.incrementLeafNodes(session); - PlanNode root = new TableScanNode(getSourceLocation(node.getLocation()), idAllocator.getNextId(), handle, outputVariables, columns.build(), tableConstraints, TupleDomain.all(), TupleDomain.all()); + PlanNode root = new TableScanNode(getSourceLocation(node.getLocation()), idAllocator.getNextId(), handle, outputVariables, columns.build(), + tableConstraints, TupleDomain.all(), TupleDomain.all(), Optional.empty()); return new RelationPlan(root, scope, outputVariables); } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PickTableLayout.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PickTableLayout.java index 609b7e740bbcb..ee372d98e88ee 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PickTableLayout.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PickTableLayout.java @@ -228,7 +228,8 @@ public Result apply(TableScanNode tableScanNode, Captures captures, Context cont tableScanNode.getAssignments(), tableScanNode.getTableConstraints(), layout.getLayout().getPredicate(), - TupleDomain.all())); + TupleDomain.all(), + tableScanNode.getTemporaryTableInfo())); } } @@ -324,7 +325,8 @@ private static PlanNode pushPredicateIntoTableScan( node.getAssignments(), node.getTableConstraints(), layout.getLayout().getPredicate(), - computeEnforced(newDomain, layout.getUnenforcedConstraint())); + computeEnforced(newDomain, layout.getUnenforcedConstraint()), + node.getTemporaryTableInfo()); // The order of the arguments to combineConjuncts matters: // * Unenforced constraints go first because they can only be simple column references, diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PruneTableScanColumns.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PruneTableScanColumns.java index 7225e5e183ac9..9eb2d85f757d1 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PruneTableScanColumns.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/PruneTableScanColumns.java @@ -46,6 +46,6 @@ protected Optional pushDownProjectOff(PlanNodeIdAllocator idAllocator, filterKeys(tableScanNode.getAssignments(), referencedOutputs::contains), tableScanNode.getTableConstraints(), tableScanNode.getCurrentConstraint(), - tableScanNode.getEnforcedConstraint())); + tableScanNode.getEnforcedConstraint(), tableScanNode.getTemporaryTableInfo())); } } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RowExpressionRewriteRuleSet.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RowExpressionRewriteRuleSet.java index f448b8024fcb1..50bf3cbd29a6f 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RowExpressionRewriteRuleSet.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/RowExpressionRewriteRuleSet.java @@ -524,7 +524,8 @@ public Result apply(TableFinishNode node, Captures captures, Context context) node.getTarget(), node.getRowCountVariable(), rewrittenStatisticsAggregation, - node.getStatisticsAggregationDescriptor())); + node.getStatisticsAggregationDescriptor(), + node.getTemporaryTableInfo())); } return Result.empty(); } @@ -589,7 +590,7 @@ public Result apply(TableWriterNode node, Captures captures, Context context) node.getTablePartitioningScheme(), rewrittenStatisticsAggregation, node.getTaskCountIfScaledWriter(), - node.getIsTemporaryTableWriter())); + node.getTemporaryTableInfo())); } return Result.empty(); } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/ScaledWriterRule.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/ScaledWriterRule.java index 527242616a3a2..23b3d28592bb6 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/ScaledWriterRule.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/iterative/rule/ScaledWriterRule.java @@ -80,6 +80,6 @@ public Result apply(TableWriterNode node, Captures captures, Context context) node.getTablePartitioningScheme(), node.getStatisticsAggregation(), Optional.of(initialTaskNumber), - node.getIsTemporaryTableWriter())); + node.getTemporaryTableInfo())); } } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AddLocalExchanges.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AddLocalExchanges.java index 432b031f9aa6c..74e7a7671a907 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AddLocalExchanges.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/AddLocalExchanges.java @@ -627,7 +627,7 @@ public PlanWithProperties visitTableWriter(TableWriterNode originalTableWriterNo originalTableWriterNode.getTablePartitioningScheme(), statisticAggregations.map(StatisticAggregations.Parts::getPartialAggregation), originalTableWriterNode.getTaskCountIfScaledWriter(), - originalTableWriterNode.getIsTemporaryTableWriter()), + originalTableWriterNode.getTemporaryTableInfo()), fixedParallelism(), fixedParallelism()); } @@ -652,7 +652,7 @@ public PlanWithProperties visitTableWriter(TableWriterNode originalTableWriterNo originalTableWriterNode.getTablePartitioningScheme(), statisticAggregations.map(StatisticAggregations.Parts::getPartialAggregation), originalTableWriterNode.getTaskCountIfScaledWriter(), - originalTableWriterNode.getIsTemporaryTableWriter()), + originalTableWriterNode.getTemporaryTableInfo()), exchange.getProperties()); } } @@ -681,7 +681,7 @@ public PlanWithProperties visitTableWriter(TableWriterNode originalTableWriterNo originalTableWriterNode.getTablePartitioningScheme(), statisticAggregations.map(StatisticAggregations.Parts::getPartialAggregation), originalTableWriterNode.getTaskCountIfScaledWriter(), - originalTableWriterNode.getIsTemporaryTableWriter()), + originalTableWriterNode.getTemporaryTableInfo()), exchange.getProperties()); } diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/PhysicalCteOptimizer.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/PhysicalCteOptimizer.java index 17a93b627bba0..921d786b584ee 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/PhysicalCteOptimizer.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/PhysicalCteOptimizer.java @@ -138,7 +138,8 @@ public PlanNode visitCteProducer(CteProducerNode node, RewriteContext conte newAssignments.build(), node.getTableConstraints(), node.getCurrentConstraint(), - node.getEnforcedConstraint()); + node.getEnforcedConstraint(), node.getTemporaryTableInfo()); } @Override diff --git a/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/SymbolMapper.java b/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/SymbolMapper.java index 2bab1de7f0cef..450bcc9b6c0a3 100644 --- a/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/SymbolMapper.java +++ b/presto-main/src/main/java/com/facebook/presto/sql/planner/optimizations/SymbolMapper.java @@ -259,7 +259,7 @@ public TableWriterNode map(TableWriterNode node, PlanNode source, PlanNodeId new node.getTablePartitioningScheme().map(partitioningScheme -> canonicalize(partitioningScheme, source)), node.getStatisticsAggregation().map(this::map), node.getTaskCountIfScaledWriter(), - node.getIsTemporaryTableWriter()); + node.getTemporaryTableInfo()); } public StatisticsWriterNode map(StatisticsWriterNode node, PlanNode source) @@ -283,7 +283,8 @@ public TableFinishNode map(TableFinishNode node, PlanNode source) node.getTarget(), map(node.getRowCountVariable()), node.getStatisticsAggregation().map(this::map), - node.getStatisticsAggregationDescriptor().map(descriptor -> descriptor.map(this::map))); + node.getStatisticsAggregationDescriptor().map(descriptor -> descriptor.map(this::map)), + node.getTemporaryTableInfo()); } public TableWriterMergeNode map(TableWriterMergeNode node, PlanNode source) diff --git a/presto-main/src/test/java/com/facebook/presto/cost/TestCostCalculator.java b/presto-main/src/test/java/com/facebook/presto/cost/TestCostCalculator.java index be87bddc7b209..326c79a64469f 100644 --- a/presto-main/src/test/java/com/facebook/presto/cost/TestCostCalculator.java +++ b/presto-main/src/test/java/com/facebook/presto/cost/TestCostCalculator.java @@ -921,7 +921,7 @@ private TableScanNode tableScan(String id, List var variables, assignments.build(), TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); } private PlanNode project(String id, PlanNode source, VariableReferenceExpression variable, RowExpression expression) diff --git a/presto-main/src/test/java/com/facebook/presto/execution/MockRemoteTaskFactory.java b/presto-main/src/test/java/com/facebook/presto/execution/MockRemoteTaskFactory.java index 8731395f010a9..2ae96279b15b7 100644 --- a/presto-main/src/test/java/com/facebook/presto/execution/MockRemoteTaskFactory.java +++ b/presto-main/src/test/java/com/facebook/presto/execution/MockRemoteTaskFactory.java @@ -124,7 +124,7 @@ public MockRemoteTask createTableScanTask(TaskId taskId, InternalNode newNode, L ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), - TupleDomain.all()), + TupleDomain.all(), Optional.empty()), ImmutableSet.of(variable), SOURCE_DISTRIBUTION, ImmutableList.of(sourceId), diff --git a/presto-main/src/test/java/com/facebook/presto/execution/TaskTestUtils.java b/presto-main/src/test/java/com/facebook/presto/execution/TaskTestUtils.java index de23ba82b0236..cdee04d9bdc83 100644 --- a/presto-main/src/test/java/com/facebook/presto/execution/TaskTestUtils.java +++ b/presto-main/src/test/java/com/facebook/presto/execution/TaskTestUtils.java @@ -120,7 +120,7 @@ public static PlanFragment createPlanFragment() ImmutableList.of(VARIABLE), ImmutableMap.of(VARIABLE, new TestingColumnHandle("column", 0, BIGINT)), TupleDomain.all(), - TupleDomain.all()), + TupleDomain.all(), Optional.empty()), ImmutableSet.of(VARIABLE), SOURCE_DISTRIBUTION, ImmutableList.of(TABLE_SCAN_NODE_ID), diff --git a/presto-main/src/test/java/com/facebook/presto/execution/scheduler/TestPhasedExecutionSchedule.java b/presto-main/src/test/java/com/facebook/presto/execution/scheduler/TestPhasedExecutionSchedule.java index 301d6559a1d95..8c932566c4453 100644 --- a/presto-main/src/test/java/com/facebook/presto/execution/scheduler/TestPhasedExecutionSchedule.java +++ b/presto-main/src/test/java/com/facebook/presto/execution/scheduler/TestPhasedExecutionSchedule.java @@ -206,7 +206,7 @@ private static PlanFragment createBroadcastJoinPlanFragment(String name, PlanFra ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); RemoteSourceNode remote = new RemoteSourceNode(Optional.empty(), new PlanNodeId("build_id"), buildFragment.getId(), ImmutableList.of(), false, Optional.empty(), REPLICATE); PlanNode join = new JoinNode( @@ -266,7 +266,7 @@ private static PlanFragment createTableScanPlanFragment(String name) ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); return createFragment(planNode); } diff --git a/presto-main/src/test/java/com/facebook/presto/execution/scheduler/TestSourcePartitionedScheduler.java b/presto-main/src/test/java/com/facebook/presto/execution/scheduler/TestSourcePartitionedScheduler.java index dba204ed39644..00c4483a755c5 100644 --- a/presto-main/src/test/java/com/facebook/presto/execution/scheduler/TestSourcePartitionedScheduler.java +++ b/presto-main/src/test/java/com/facebook/presto/execution/scheduler/TestSourcePartitionedScheduler.java @@ -489,7 +489,8 @@ private static SubPlan createPlan() ImmutableList.of(variable), ImmutableMap.of(variable, new TestingColumnHandle("column")), TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), + Optional.empty()); RemoteSourceNode remote = new RemoteSourceNode(Optional.empty(), new PlanNodeId("remote_id"), new PlanFragmentId(0), ImmutableList.of(), false, Optional.empty(), GATHER); PlanFragment testFragment = new PlanFragment( diff --git a/presto-main/src/test/java/com/facebook/presto/operator/TestDriver.java b/presto-main/src/test/java/com/facebook/presto/operator/TestDriver.java index 6dcf637834938..f1b1256596292 100644 --- a/presto-main/src/test/java/com/facebook/presto/operator/TestDriver.java +++ b/presto-main/src/test/java/com/facebook/presto/operator/TestDriver.java @@ -113,7 +113,7 @@ public class TestDriver ImmutableList.of(), ImmutableMap.of(), TupleDomain.all(), - TupleDomain.all()), + TupleDomain.all(), Optional.empty()), ImmutableMap.of(), singleGroupingSet(ImmutableList.of()), ImmutableList.of(), diff --git a/presto-main/src/test/java/com/facebook/presto/sql/planner/TestEffectivePredicateExtractor.java b/presto-main/src/test/java/com/facebook/presto/sql/planner/TestEffectivePredicateExtractor.java index 0d3954f0ce6aa..46676111a82aa 100644 --- a/presto-main/src/test/java/com/facebook/presto/sql/planner/TestEffectivePredicateExtractor.java +++ b/presto-main/src/test/java/com/facebook/presto/sql/planner/TestEffectivePredicateExtractor.java @@ -144,7 +144,7 @@ public void setUp() ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); } @Test @@ -373,7 +373,7 @@ public void testTableScan() ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); RowExpression effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(effectivePredicate, TRUE_CONSTANT); @@ -384,7 +384,7 @@ public void testTableScan() ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.none(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(effectivePredicate, FALSE_CONSTANT); @@ -395,7 +395,7 @@ public void testTableScan() ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(AV), Domain.singleValue(BIGINT, 1L))), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(1L), AV))); @@ -408,7 +408,7 @@ public void testTableScan() TupleDomain.withColumnDomains(ImmutableMap.of( scanAssignments.get(AV), Domain.singleValue(BIGINT, 1L), scanAssignments.get(BV), Domain.singleValue(BIGINT, 2L))), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(2L), BV), equals(bigintLiteral(1L), AV))); @@ -419,7 +419,7 @@ public void testTableScan() ImmutableList.copyOf(assignments.keySet()), assignments, TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); effectivePredicate = effectivePredicateExtractor.extract(node); assertEquals(effectivePredicate, TRUE_CONSTANT); } @@ -783,7 +783,7 @@ private static TableScanNode tableScanNode(Map context) newAssignments, tableScan.getTableConstraints(), tableScan.getCurrentConstraint(), - tableScan.getEnforcedConstraint()); + tableScan.getEnforcedConstraint(), + tableScan.getTemporaryTableInfo()); Assignments.Builder newProjectAssignmentBuilder = Assignments.builder(); for (Map.Entry entry : project.getAssignments().entrySet()) { diff --git a/presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotPlanOptimizer.java b/presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotPlanOptimizer.java index 46911541b4eee..68214a6d90ec3 100644 --- a/presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotPlanOptimizer.java +++ b/presto-pinot-toolkit/src/main/java/com/facebook/presto/pinot/PinotPlanOptimizer.java @@ -184,7 +184,8 @@ private Optional tryCreatingNewScanNode(PlanNode plan, TableScanNode t ImmutableList.copyOf(assignments.keySet()), assignments.entrySet().stream().collect(toImmutableMap(Map.Entry::getKey, (e) -> (ColumnHandle) (e.getValue()))), tableScanNode.getCurrentConstraint(), - tableScanNode.getEnforcedConstraint())); + tableScanNode.getEnforcedConstraint(), + tableScanNode.getTemporaryTableInfo())); } @Override diff --git a/presto-spark-base/src/test/java/com/facebook/presto/spark/planner/TestIterativePlanFragmenter.java b/presto-spark-base/src/test/java/com/facebook/presto/spark/planner/TestIterativePlanFragmenter.java index 379f912e8cba1..250b970b511ad 100644 --- a/presto-spark-base/src/test/java/com/facebook/presto/spark/planner/TestIterativePlanFragmenter.java +++ b/presto-spark-base/src/test/java/com/facebook/presto/spark/planner/TestIterativePlanFragmenter.java @@ -312,7 +312,7 @@ private TableScanNode tableScan(String id, List var variables, assignments.build(), TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); } private PlanNode project(String id, PlanNode source, VariableReferenceExpression variable, RowExpression expression) diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableFinishNode.java b/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableFinishNode.java index 05f153cdb9e5b..2258241e8934e 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableFinishNode.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableFinishNode.java @@ -38,6 +38,8 @@ public final class TableFinishNode private final Optional statisticsAggregation; private final Optional> statisticsAggregationDescriptor; + private final Optional temporaryTableInfo; + @JsonCreator public TableFinishNode( Optional sourceLocation, @@ -46,9 +48,10 @@ public TableFinishNode( @JsonProperty("target") Optional target, @JsonProperty("rowCountVariable") VariableReferenceExpression rowCountVariable, @JsonProperty("statisticsAggregation") Optional statisticsAggregation, - @JsonProperty("statisticsAggregationDescriptor") Optional> statisticsAggregationDescriptor) + @JsonProperty("statisticsAggregationDescriptor") Optional> statisticsAggregationDescriptor, + @JsonProperty("isTemporaryTableWriter") Optional temporaryTableInfo) { - this(sourceLocation, id, Optional.empty(), source, target, rowCountVariable, statisticsAggregation, statisticsAggregationDescriptor); + this(sourceLocation, id, Optional.empty(), source, target, rowCountVariable, statisticsAggregation, statisticsAggregationDescriptor, temporaryTableInfo); } public TableFinishNode( @@ -59,11 +62,13 @@ public TableFinishNode( Optional target, VariableReferenceExpression rowCountVariable, Optional statisticsAggregation, - Optional> statisticsAggregationDescriptor) + Optional> statisticsAggregationDescriptor, + Optional temporaryTableInfo) { super(sourceLocation, id, statsEquivalentPlanNode); checkArgument(target != null || source instanceof TableWriterNode); + this.temporaryTableInfo = temporaryTableInfo; this.source = requireNonNull(source, "source is null"); this.target = requireNonNull(target, "target is null"); this.rowCountVariable = requireNonNull(rowCountVariable, "rowCountVariable is null"); @@ -120,6 +125,11 @@ public R accept(PlanVisitor visitor, C context) return visitor.visitTableFinish(this, context); } + public Optional getTemporaryTableInfo() + { + return temporaryTableInfo; + } + @Override public PlanNode replaceChildren(List newChildren) { @@ -132,7 +142,8 @@ public PlanNode replaceChildren(List newChildren) target, rowCountVariable, statisticsAggregation, - statisticsAggregationDescriptor); + statisticsAggregationDescriptor, + temporaryTableInfo); } @Override @@ -146,6 +157,7 @@ public PlanNode assignStatsEquivalentPlanNode(Optional statsEquivalent target, rowCountVariable, statisticsAggregation, - statisticsAggregationDescriptor); + statisticsAggregationDescriptor, + temporaryTableInfo); } } diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableScanNode.java b/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableScanNode.java index 17a739f855b14..c4a75be7547d7 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableScanNode.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableScanNode.java @@ -50,6 +50,8 @@ public final class TableScanNode private final TupleDomain enforcedConstraint; private final List> tableConstraints; + private final Optional temporaryTableInfo; + /** * This constructor is for JSON deserialization only. Do not use! */ @@ -69,6 +71,7 @@ public TableScanNode( this.currentConstraint = null; this.enforcedConstraint = null; this.tableConstraints = emptyList(); + this.temporaryTableInfo = Optional.empty(); } public TableScanNode( @@ -78,9 +81,9 @@ public TableScanNode( List outputVariables, Map assignments, TupleDomain currentConstraint, - TupleDomain enforcedConstraint) + TupleDomain enforcedConstraint, Optional temporaryTableInfo) { - this (sourceLocation, id, table, outputVariables, assignments, emptyList(), currentConstraint, enforcedConstraint); + this(sourceLocation, id, table, outputVariables, assignments, emptyList(), currentConstraint, enforcedConstraint, temporaryTableInfo); } public TableScanNode( @@ -91,9 +94,9 @@ public TableScanNode( Map assignments, List> tableConstraints, TupleDomain currentConstraint, - TupleDomain enforcedConstraint) + TupleDomain enforcedConstraint, Optional temporaryTableInfo) { - this (sourceLocation, id, Optional.empty(), table, outputVariables, assignments, tableConstraints, currentConstraint, enforcedConstraint); + this(sourceLocation, id, Optional.empty(), table, outputVariables, assignments, tableConstraints, currentConstraint, enforcedConstraint, temporaryTableInfo); } public TableScanNode( @@ -105,12 +108,14 @@ public TableScanNode( Map assignments, List> tableConstraints, TupleDomain currentConstraint, - TupleDomain enforcedConstraint) + TupleDomain enforcedConstraint, + Optional temporaryTableInfo) { super(sourceLocation, id, statsEquivalentPlanNode); this.table = requireNonNull(table, "table is null"); this.outputVariables = unmodifiableList(requireNonNull(outputVariables, "outputVariables is null")); this.assignments = unmodifiableMap(new HashMap<>(requireNonNull(assignments, "assignments is null"))); + this.temporaryTableInfo = requireNonNull(temporaryTableInfo, "temporaryTableInfo is null"); checkArgument(assignments.keySet().containsAll(outputVariables), "assignments does not cover all of outputs"); this.currentConstraint = requireNonNull(currentConstraint, "currentConstraint is null"); this.enforcedConstraint = requireNonNull(enforcedConstraint, "enforcedConstraint is null"); @@ -120,6 +125,11 @@ public TableScanNode( this.tableConstraints = requireNonNull(tableConstraints, "tableConstraints is null"); } + public Optional getTemporaryTableInfo() + { + return temporaryTableInfo; + } + /** * Get the table handle provided by connector */ @@ -206,7 +216,7 @@ public R accept(PlanVisitor visitor, C context) @Override public PlanNode assignStatsEquivalentPlanNode(Optional statsEquivalentPlanNode) { - return new TableScanNode(getSourceLocation(), getId(), statsEquivalentPlanNode, table, outputVariables, assignments, tableConstraints, currentConstraint, enforcedConstraint); + return new TableScanNode(getSourceLocation(), getId(), statsEquivalentPlanNode, table, outputVariables, assignments, tableConstraints, currentConstraint, enforcedConstraint, temporaryTableInfo); } @Override diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableWriterNode.java b/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableWriterNode.java index a693de9334cc2..9c9704e818649 100644 --- a/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableWriterNode.java +++ b/presto-spi/src/main/java/com/facebook/presto/spi/plan/TableWriterNode.java @@ -54,7 +54,7 @@ public final class TableWriterNode private final Optional statisticsAggregation; private final List outputs; private final Optional taskCountIfScaledWriter; - private final Optional isTemporaryTableWriter; + private final Optional temporaryTableInfo; @JsonCreator public TableWriterNode( @@ -71,10 +71,9 @@ public TableWriterNode( @JsonProperty("partitioningScheme") Optional tablePartitioningScheme, @JsonProperty("statisticsAggregation") Optional statisticsAggregation, @JsonProperty("taskCountIfScaledWriter") Optional taskCountIfScaledWriter, - @JsonProperty("isTemporaryTableWriter") Optional isTemporaryTableWriter) + @JsonProperty("isTemporaryTableWriter") Optional temporaryTableInfo) { - this( - sourceLocation, + this(sourceLocation, id, Optional.empty(), source, @@ -88,7 +87,7 @@ public TableWriterNode( tablePartitioningScheme, statisticsAggregation, taskCountIfScaledWriter, - isTemporaryTableWriter); + temporaryTableInfo); } public TableWriterNode( @@ -106,7 +105,7 @@ public TableWriterNode( Optional tablePartitioningScheme, Optional statisticsAggregation, Optional taskCountIfScaledWriter, - Optional isTemporaryTableWriter) + Optional temporaryTableInfo) { super(sourceLocation, id, statsEquivalentPlanNode); @@ -135,7 +134,7 @@ public TableWriterNode( }); this.outputs = Collections.unmodifiableList(outputsList); this.taskCountIfScaledWriter = requireNonNull(taskCountIfScaledWriter, "taskCountIfScaledWriter is null"); - this.isTemporaryTableWriter = requireNonNull(isTemporaryTableWriter, "isTemporaryTableWriter is null"); + this.temporaryTableInfo = requireNonNull(temporaryTableInfo, "isTemporaryTableWriter is null"); } @JsonProperty @@ -216,10 +215,9 @@ public Optional getTaskCountIfScaledWriter() return taskCountIfScaledWriter; } - @JsonProperty - public Optional getIsTemporaryTableWriter() + public Optional getTemporaryTableInfo() { - return isTemporaryTableWriter; + return temporaryTableInfo; } @Override @@ -246,7 +244,7 @@ public PlanNode replaceChildren(List newChildren) notNullColumnVariables, tablePartitioningScheme, statisticsAggregation, - taskCountIfScaledWriter, isTemporaryTableWriter); + taskCountIfScaledWriter, temporaryTableInfo); } @Override @@ -266,7 +264,7 @@ public PlanNode assignStatsEquivalentPlanNode(Optional statsEquivalent notNullColumnVariables, tablePartitioningScheme, statisticsAggregation, - taskCountIfScaledWriter, isTemporaryTableWriter); + taskCountIfScaledWriter, temporaryTableInfo); } // only used during planning -- will not be serialized diff --git a/presto-spi/src/main/java/com/facebook/presto/spi/plan/TemporaryTableInfo.java b/presto-spi/src/main/java/com/facebook/presto/spi/plan/TemporaryTableInfo.java new file mode 100644 index 0000000000000..8a201b5e38d5f --- /dev/null +++ b/presto-spi/src/main/java/com/facebook/presto/spi/plan/TemporaryTableInfo.java @@ -0,0 +1,29 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.spi.plan; + +public class TemporaryTableInfo +{ + private final String cteId; + + public TemporaryTableInfo(String cteId) + { + this.cteId = cteId; + } + + public String getCteId() + { + return cteId; + } +}