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..7c3e8b0607d01 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.getCteMaterializationInfo()); 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..d6d18093cdb89 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.getCteMaterializationInfo())); } @Override @@ -288,7 +289,8 @@ public PlanNode visitFilter(FilterNode node, Void context) oldTableScanNode.getOutputVariables(), oldTableScanNode.getAssignments(), oldTableScanNode.getCurrentConstraint(), - oldTableScanNode.getEnforcedConstraint()); + oldTableScanNode.getEnforcedConstraint(), + oldTableScanNode.getCteMaterializationInfo()); 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..0259bbc8c2234 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.getCteMaterializationInfo())); } @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..8ff14c755031f 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.getCteMaterializationInfo()); } 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..36b7966641699 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.getCteMaterializationInfo()); } } } 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..cf1ff92e6d50a 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.getCteMaterializationInfo())); } @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..e6598f9630c06 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.getCteMaterializationInfo()); 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..9d6c8a4d16c23 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 @@ -35,6 +35,7 @@ import com.facebook.presto.spi.function.FunctionHandle; import com.facebook.presto.spi.plan.AggregationNode; import com.facebook.presto.spi.plan.Assignments; +import com.facebook.presto.spi.plan.CteMaterializationInfo; import com.facebook.presto.spi.plan.Partitioning; import com.facebook.presto.spi.plan.PartitioningHandle; import com.facebook.presto.spi.plan.PartitioningScheme; @@ -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(CteMaterializationInfo::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); @@ -210,12 +217,12 @@ public static TableFinishNode createTemporaryTableWriteWithoutExchanges( outputNotNullColumnVariables, Optional.empty(), Optional.empty(), - Optional.empty(), - Optional.of(Boolean.TRUE)), + Optional.empty()), Optional.of(insertReference), outputVar, Optional.empty(), - Optional.empty()); + Optional.empty(), + cteId.map(CteMaterializationInfo::new)); } public static TableFinishNode createTemporaryTableWriteWithExchanges( @@ -346,13 +353,11 @@ public static TableFinishNode createTemporaryTableWriteWithExchanges( outputNotNullColumnVariables, 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 +368,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..c47c9a70dbc8e 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 @@ -227,7 +227,6 @@ public Optional visitTableWriter(TableWriterNode node, Context context ImmutableSet.of(), Optional.empty(), Optional.empty(), - Optional.empty(), Optional.empty()); context.addPlan(node, new CanonicalPlan(result, strategy)); return Optional.of(result); @@ -252,7 +251,8 @@ public Optional visitTableFinish(TableFinishNode node, Context context node.getTarget().map(target -> CanonicalWriterTarget.from(target)), node.getRowCountVariable(), Optional.empty(), - Optional.empty()); + Optional.empty(), + node.getCteMaterializationInfo()); 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..d9e4db8e2799f 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), @@ -434,14 +434,14 @@ private RelationPlan createTableWriterPlan( // partial aggregation is run within the TableWriteOperator to calculate the statistics for // 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()); } @@ -462,11 +462,11 @@ private RelationPlan createTableWriterPlan( notNullColumnVariables, 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 +486,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 +528,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..20b6871101967 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,6 @@ 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)) .map(TableWriterNode::getId) .collect(toImmutableSet()); } @@ -304,7 +303,8 @@ public PlanNode visitTableScan(TableScanNode node, RewriteContext context) node.getOutputVariables(), node.getAssignments(), node.getCurrentConstraint(), - node.getEnforcedConstraint()); + node.getEnforcedConstraint(), + node.getCteMaterializationInfo()); } } 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..a4fc4b9f656a5 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.getCteMaterializationInfo()); } 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..faf96d27adabc 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.getCteMaterializationInfo())); } } @@ -324,7 +325,8 @@ private static PlanNode pushPredicateIntoTableScan( node.getAssignments(), node.getTableConstraints(), layout.getLayout().getPredicate(), - computeEnforced(newDomain, layout.getUnenforcedConstraint())); + computeEnforced(newDomain, layout.getUnenforcedConstraint()), + node.getCteMaterializationInfo()); // 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..fef6aac344c20 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.getCteMaterializationInfo())); } } 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..33334b68a5598 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.getCteMaterializationInfo())); } return Result.empty(); } @@ -588,8 +589,7 @@ public Result apply(TableWriterNode node, Captures captures, Context context) node.getNotNullColumnVariables(), node.getTablePartitioningScheme(), rewrittenStatisticsAggregation, - node.getTaskCountIfScaledWriter(), - node.getIsTemporaryTableWriter())); + node.getTaskCountIfScaledWriter())); } 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..f1f3a8fdf7ccc 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 @@ -79,7 +79,6 @@ public Result apply(TableWriterNode node, Captures captures, Context context) node.getNotNullColumnVariables(), node.getTablePartitioningScheme(), node.getStatisticsAggregation(), - Optional.of(initialTaskNumber), - node.getIsTemporaryTableWriter())); + Optional.of(initialTaskNumber))); } } 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..c60b782421396 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 @@ -626,8 +626,7 @@ public PlanWithProperties visitTableWriter(TableWriterNode originalTableWriterNo originalTableWriterNode.getNotNullColumnVariables(), originalTableWriterNode.getTablePartitioningScheme(), statisticAggregations.map(StatisticAggregations.Parts::getPartialAggregation), - originalTableWriterNode.getTaskCountIfScaledWriter(), - originalTableWriterNode.getIsTemporaryTableWriter()), + originalTableWriterNode.getTaskCountIfScaledWriter()), fixedParallelism(), fixedParallelism()); } @@ -651,8 +650,7 @@ public PlanWithProperties visitTableWriter(TableWriterNode originalTableWriterNo originalTableWriterNode.getNotNullColumnVariables(), originalTableWriterNode.getTablePartitioningScheme(), statisticAggregations.map(StatisticAggregations.Parts::getPartialAggregation), - originalTableWriterNode.getTaskCountIfScaledWriter(), - originalTableWriterNode.getIsTemporaryTableWriter()), + originalTableWriterNode.getTaskCountIfScaledWriter()), exchange.getProperties()); } } @@ -680,8 +678,7 @@ public PlanWithProperties visitTableWriter(TableWriterNode originalTableWriterNo originalTableWriterNode.getNotNullColumnVariables(), originalTableWriterNode.getTablePartitioningScheme(), statisticAggregations.map(StatisticAggregations.Parts::getPartialAggregation), - originalTableWriterNode.getTaskCountIfScaledWriter(), - originalTableWriterNode.getIsTemporaryTableWriter()), + originalTableWriterNode.getTaskCountIfScaledWriter()), 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..91f2c36d1099f 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.getCteMaterializationInfo()); } @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..423cf13822a5b 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 @@ -258,8 +258,7 @@ public TableWriterNode map(TableWriterNode node, PlanNode source, PlanNodeId new notNullColumnVariables, node.getTablePartitioningScheme().map(partitioningScheme -> canonicalize(partitioningScheme, source)), node.getStatisticsAggregation().map(this::map), - node.getTaskCountIfScaledWriter(), - node.getIsTemporaryTableWriter()); + node.getTaskCountIfScaledWriter()); } public StatisticsWriterNode map(StatisticsWriterNode node, PlanNode source) @@ -283,7 +282,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.getCteMaterializationInfo()); } 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 columns, Li ImmutableSet.of(), Optional.empty(), Optional.empty(), - Optional.empty(), Optional.empty()); } diff --git a/presto-main/src/test/java/com/facebook/presto/sql/planner/optimizations/TestConnectorOptimization.java b/presto-main/src/test/java/com/facebook/presto/sql/planner/optimizations/TestConnectorOptimization.java index 393d363cc09b1..62b96f0973778 100644 --- a/presto-main/src/test/java/com/facebook/presto/sql/planner/optimizations/TestConnectorOptimization.java +++ b/presto-main/src/test/java/com/facebook/presto/sql/planner/optimizations/TestConnectorOptimization.java @@ -338,7 +338,7 @@ public PlanNode visitFilter(FilterNode node, Void context) tableScanNode.getAssignments(), tableScanNode.getTableConstraints(), TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); } return node; } diff --git a/presto-main/src/test/java/com/facebook/presto/util/TestGraphvizPrinter.java b/presto-main/src/test/java/com/facebook/presto/util/TestGraphvizPrinter.java index 7f496a5e41c92..e04f3a67bdabb 100644 --- a/presto-main/src/test/java/com/facebook/presto/util/TestGraphvizPrinter.java +++ b/presto-main/src/test/java/com/facebook/presto/util/TestGraphvizPrinter.java @@ -67,7 +67,7 @@ public class TestGraphvizPrinter ImmutableList.of(), ImmutableMap.of(), TupleDomain.all(), - TupleDomain.all()); + TupleDomain.all(), Optional.empty()); private static final String TEST_TABLE_SCAN_NODE_INNER_OUTPUT = format( "label=\"{TableScan | [TableHandle \\{connectorId='%s', connectorHandle='%s', layout='Optional.empty'\\}]|Estimates: \\{rows: ? (0B), cpu: ?, memory: ?, network: ?\\}\n" + "}\", style=\"rounded, filled\", shape=record, fillcolor=deepskyblue", diff --git a/presto-parquet/src/main/java/com/facebook/presto/parquet/rule/ParquetDereferencePushDown.java b/presto-parquet/src/main/java/com/facebook/presto/parquet/rule/ParquetDereferencePushDown.java index 17f156cc0fff5..bd4d89c4fb034 100644 --- a/presto-parquet/src/main/java/com/facebook/presto/parquet/rule/ParquetDereferencePushDown.java +++ b/presto-parquet/src/main/java/com/facebook/presto/parquet/rule/ParquetDereferencePushDown.java @@ -371,7 +371,8 @@ public PlanNode visitProject(ProjectNode project, RewriteContext context) newAssignments, tableScan.getTableConstraints(), tableScan.getCurrentConstraint(), - tableScan.getEnforcedConstraint()); + tableScan.getEnforcedConstraint(), + tableScan.getCteMaterializationInfo()); 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..0e437490b26e2 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.getCteMaterializationInfo())); } @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/CteMaterializationInfo.java b/presto-spi/src/main/java/com/facebook/presto/spi/plan/CteMaterializationInfo.java new file mode 100644 index 0000000000000..8954005e35eec --- /dev/null +++ b/presto-spi/src/main/java/com/facebook/presto/spi/plan/CteMaterializationInfo.java @@ -0,0 +1,32 @@ +/* + * 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; + +/* + * Contains information about the identifier (cteId) of the CTE being materialized. This information is stored tablescans and tablefinish plan nodesg + */ +public class CteMaterializationInfo +{ + private final String cteId; + + public CteMaterializationInfo(String cteId) + { + this.cteId = cteId; + } + + public String getCteId() + { + return cteId; + } +} 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..281c6dec7c148 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("cteMaterializationInfo") 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 getCteMaterializationInfo() + { + 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..ef6567103f544 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 cteMaterializationInfo; + /** * 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.cteMaterializationInfo = Optional.empty(); } public TableScanNode( @@ -78,9 +81,9 @@ public TableScanNode( List outputVariables, Map assignments, TupleDomain currentConstraint, - TupleDomain enforcedConstraint) + TupleDomain enforcedConstraint, Optional cteMaterializationInfo) { - this (sourceLocation, id, table, outputVariables, assignments, emptyList(), currentConstraint, enforcedConstraint); + this(sourceLocation, id, table, outputVariables, assignments, emptyList(), currentConstraint, enforcedConstraint, cteMaterializationInfo); } public TableScanNode( @@ -91,9 +94,9 @@ public TableScanNode( Map assignments, List> tableConstraints, TupleDomain currentConstraint, - TupleDomain enforcedConstraint) + TupleDomain enforcedConstraint, Optional cteMaterializationInfo) { - this (sourceLocation, id, Optional.empty(), table, outputVariables, assignments, tableConstraints, currentConstraint, enforcedConstraint); + this(sourceLocation, id, Optional.empty(), table, outputVariables, assignments, tableConstraints, currentConstraint, enforcedConstraint, cteMaterializationInfo); } public TableScanNode( @@ -105,12 +108,14 @@ public TableScanNode( Map assignments, List> tableConstraints, TupleDomain currentConstraint, - TupleDomain enforcedConstraint) + TupleDomain enforcedConstraint, + Optional cteMaterializationInfo) { 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.cteMaterializationInfo = requireNonNull(cteMaterializationInfo, "cteMaterializationInfo 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 getCteMaterializationInfo() + { + return cteMaterializationInfo; + } + /** * 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, cteMaterializationInfo); } @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..c5e090865fb53 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,6 @@ public final class TableWriterNode private final Optional statisticsAggregation; private final List outputs; private final Optional taskCountIfScaledWriter; - private final Optional isTemporaryTableWriter; @JsonCreator public TableWriterNode( @@ -70,11 +69,9 @@ public TableWriterNode( @JsonProperty("notNullColumnVariables") Set notNullColumnVariables, @JsonProperty("partitioningScheme") Optional tablePartitioningScheme, @JsonProperty("statisticsAggregation") Optional statisticsAggregation, - @JsonProperty("taskCountIfScaledWriter") Optional taskCountIfScaledWriter, - @JsonProperty("isTemporaryTableWriter") Optional isTemporaryTableWriter) + @JsonProperty("taskCountIfScaledWriter") Optional taskCountIfScaledWriter) { - this( - sourceLocation, + this(sourceLocation, id, Optional.empty(), source, @@ -87,8 +84,7 @@ public TableWriterNode( notNullColumnVariables, tablePartitioningScheme, statisticsAggregation, - taskCountIfScaledWriter, - isTemporaryTableWriter); + taskCountIfScaledWriter); } public TableWriterNode( @@ -105,8 +101,7 @@ public TableWriterNode( Set notNullColumnVariables, Optional tablePartitioningScheme, Optional statisticsAggregation, - Optional taskCountIfScaledWriter, - Optional isTemporaryTableWriter) + Optional taskCountIfScaledWriter) { super(sourceLocation, id, statsEquivalentPlanNode); @@ -135,7 +130,6 @@ public TableWriterNode( }); this.outputs = Collections.unmodifiableList(outputsList); this.taskCountIfScaledWriter = requireNonNull(taskCountIfScaledWriter, "taskCountIfScaledWriter is null"); - this.isTemporaryTableWriter = requireNonNull(isTemporaryTableWriter, "isTemporaryTableWriter is null"); } @JsonProperty @@ -216,12 +210,6 @@ public Optional getTaskCountIfScaledWriter() return taskCountIfScaledWriter; } - @JsonProperty - public Optional getIsTemporaryTableWriter() - { - return isTemporaryTableWriter; - } - @Override public R accept(PlanVisitor visitor, C context) { @@ -246,7 +234,7 @@ public PlanNode replaceChildren(List newChildren) notNullColumnVariables, tablePartitioningScheme, statisticsAggregation, - taskCountIfScaledWriter, isTemporaryTableWriter); + taskCountIfScaledWriter); } @Override @@ -266,7 +254,7 @@ public PlanNode assignStatsEquivalentPlanNode(Optional statsEquivalent notNullColumnVariables, tablePartitioningScheme, statisticsAggregation, - taskCountIfScaledWriter, isTemporaryTableWriter); + taskCountIfScaledWriter); } // only used during planning -- will not be serialized