Search in sources :

Example 1 with WriterTarget

use of io.trino.sql.planner.plan.TableWriterNode.WriterTarget in project trino by trinodb.

the class LocalExecutionPlanner method createTableFinisher.

private static TableFinisher createTableFinisher(Session session, TableFinishNode node, Metadata metadata) {
    WriterTarget target = node.getTarget();
    return (fragments, statistics, tableExecuteContext) -> {
        if (target instanceof CreateTarget) {
            return metadata.finishCreateTable(session, ((CreateTarget) target).getHandle(), fragments, statistics);
        } else if (target instanceof InsertTarget) {
            return metadata.finishInsert(session, ((InsertTarget) target).getHandle(), fragments, statistics);
        } else if (target instanceof TableWriterNode.RefreshMaterializedViewTarget) {
            TableWriterNode.RefreshMaterializedViewTarget refreshTarget = (TableWriterNode.RefreshMaterializedViewTarget) target;
            return metadata.finishRefreshMaterializedView(session, refreshTarget.getTableHandle(), refreshTarget.getInsertHandle(), fragments, statistics, refreshTarget.getSourceTableHandles());
        } else if (target instanceof DeleteTarget) {
            metadata.finishDelete(session, ((DeleteTarget) target).getHandleOrElseThrow(), fragments);
            return Optional.empty();
        } else if (target instanceof UpdateTarget) {
            metadata.finishUpdate(session, ((UpdateTarget) target).getHandleOrElseThrow(), fragments);
            return Optional.empty();
        } else if (target instanceof TableExecuteTarget) {
            TableExecuteHandle tableExecuteHandle = ((TableExecuteTarget) target).getExecuteHandle();
            metadata.finishTableExecute(session, tableExecuteHandle, fragments, tableExecuteContext.getSplitsInfo());
            return Optional.empty();
        } else {
            throw new AssertionError("Unhandled target type: " + target.getClass().getName());
        }
    };
}
Also used : RefreshMaterializedViewOperatorFactory(io.trino.operator.RefreshMaterializedViewOperator.RefreshMaterializedViewOperatorFactory) ArgumentComputationSupplier(io.trino.operator.window.pattern.ArgumentComputation.ArgumentComputationSupplier) SetSupplier(io.trino.operator.SetBuilderOperator.SetSupplier) RemoteSourceNode(io.trino.sql.planner.plan.RemoteSourceNode) ONE(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch.ONE) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) PhysicalValueAccessor(io.trino.operator.window.pattern.PhysicalValueAccessor) SystemSessionProperties.isEnableCoordinatorDynamicFiltersDistribution(io.trino.SystemSessionProperties.isEnableCoordinatorDynamicFiltersDistribution) CursorProcessor(io.trino.operator.project.CursorProcessor) Map(java.util.Map) LOCAL(io.trino.sql.planner.plan.ExchangeNode.Scope.LOCAL) PartitionedOutputFactory(io.trino.operator.output.PartitionedOutputOperator.PartitionedOutputFactory) DistinctAccumulatorFactory(io.trino.operator.aggregation.DistinctAccumulatorFactory) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ExplainAnalyzeNode(io.trino.sql.planner.plan.ExplainAnalyzeNode) SystemSessionProperties.isAdaptivePartialAggregationEnabled(io.trino.SystemSessionProperties.isAdaptivePartialAggregationEnabled) FIXED_BROADCAST_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.FIXED_BROADCAST_DISTRIBUTION) Domain(io.trino.spi.predicate.Domain) SpatialPredicate(io.trino.operator.SpatialIndexBuilderOperator.SpatialPredicate) SemiJoinNode(io.trino.sql.planner.plan.SemiJoinNode) ST_CONTAINS(io.trino.util.SpatialJoinUtils.ST_CONTAINS) PageProjection(io.trino.operator.project.PageProjection) AggregationWindowFunctionSupplier(io.trino.operator.window.AggregationWindowFunctionSupplier) FIXED_ARBITRARY_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.FIXED_ARBITRARY_DISTRIBUTION) DeleteTarget(io.trino.sql.planner.plan.TableWriterNode.DeleteTarget) TableExecuteTarget(io.trino.sql.planner.plan.TableWriterNode.TableExecuteTarget) SymbolReference(io.trino.sql.tree.SymbolReference) LocalMergeSourceOperatorFactory(io.trino.operator.exchange.LocalMergeSourceOperator.LocalMergeSourceOperatorFactory) TopNRankingNode(io.trino.sql.planner.plan.TopNRankingNode) ExpressionNodeInliner.replaceExpression(io.trino.sql.planner.ExpressionNodeInliner.replaceExpression) ValuesNode(io.trino.sql.planner.plan.ValuesNode) CLASSIFIER(io.trino.operator.window.pattern.PhysicalValuePointer.CLASSIFIER) LAST(io.trino.sql.tree.SkipTo.Position.LAST) Session(io.trino.Session) OrderedAccumulatorFactory(io.trino.operator.aggregation.OrderedAccumulatorFactory) SystemSessionProperties.isSpillEnabled(io.trino.SystemSessionProperties.isSpillEnabled) RegularPartitionerSupplier(io.trino.operator.window.RegularPartitionerSupplier) StageId(io.trino.execution.StageId) PageBuilder(io.trino.spi.PageBuilder) PagesSpatialIndexFactory(io.trino.operator.PagesSpatialIndexFactory) LimitNode(io.trino.sql.planner.plan.LimitNode) NestedLoopJoinOperatorFactory(io.trino.operator.join.NestedLoopJoinOperator.NestedLoopJoinOperatorFactory) UpdateOperatorFactory(io.trino.operator.UpdateOperator.UpdateOperatorFactory) LookupSourceFactory(io.trino.operator.join.LookupSourceFactory) TableFinishOperatorFactory(io.trino.operator.TableFinishOperator.TableFinishOperatorFactory) Supplier(java.util.function.Supplier) LinkedHashMap(java.util.LinkedHashMap) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) Lists(com.google.common.collect.Lists) FunctionKind(io.trino.metadata.FunctionKind) SetBuilderOperatorFactory(io.trino.operator.SetBuilderOperator.SetBuilderOperatorFactory) RowNumberNode(io.trino.sql.planner.plan.RowNumberNode) SCALED_WRITER_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SCALED_WRITER_DISTRIBUTION) NodeRef(io.trino.sql.tree.NodeRef) JoinUtils.isBuildSideReplicated(io.trino.operator.join.JoinUtils.isBuildSideReplicated) AggregationNode(io.trino.sql.planner.plan.AggregationNode) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) WindowFunctionDefinition(io.trino.operator.WindowFunctionDefinition) DynamicFilterSourceOperatorFactory(io.trino.operator.DynamicFilterSourceOperator.DynamicFilterSourceOperatorFactory) JoinFilterFunctionFactory(io.trino.sql.gen.JoinFilterFunctionCompiler.JoinFilterFunctionFactory) EvaluationSupplier(io.trino.operator.window.pattern.LabelEvaluator.EvaluationSupplier) StageExecutionDescriptor(io.trino.operator.StageExecutionDescriptor) InsertTarget(io.trino.sql.planner.plan.TableWriterNode.InsertTarget) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) ROW_COUNT_CHANNEL(io.trino.operator.TableWriterOperator.ROW_COUNT_CHANNEL) AggregationMetadata(io.trino.operator.aggregation.AggregationMetadata) SortOrder(io.trino.spi.connector.SortOrder) OuterOperatorFactoryResult(io.trino.operator.join.JoinOperatorFactory.OuterOperatorFactoryResult) IndexBuildDriverFactoryProvider(io.trino.operator.index.IndexBuildDriverFactoryProvider) TableHandle(io.trino.metadata.TableHandle) GroupIdNode(io.trino.sql.planner.plan.GroupIdNode) MarkDistinctOperatorFactory(io.trino.operator.MarkDistinctOperator.MarkDistinctOperatorFactory) TableFinishNode(io.trino.sql.planner.plan.TableFinishNode) HOURS(java.util.concurrent.TimeUnit.HOURS) ROWS(io.trino.sql.tree.WindowFrame.Type.ROWS) TopNRankingOperator(io.trino.operator.TopNRankingOperator) IndexLookupSourceFactory(io.trino.operator.index.IndexLookupSourceFactory) IndexSourceNode(io.trino.sql.planner.plan.IndexSourceNode) DiscreteDomain.integers(com.google.common.collect.DiscreteDomain.integers) IntStream.range(java.util.stream.IntStream.range) JoinFilterFunctionCompiler(io.trino.sql.gen.JoinFilterFunctionCompiler) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode) LocalPlannerAware(io.trino.operator.LocalPlannerAware) SystemSessionProperties.isLateMaterializationEnabled(io.trino.SystemSessionProperties.isLateMaterializationEnabled) LambdaArgumentDeclaration(io.trino.sql.tree.LambdaArgumentDeclaration) SortExpressionExtractor.extractSortExpression(io.trino.sql.planner.SortExpressionExtractor.extractSortExpression) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) HashMultimap(com.google.common.collect.HashMultimap) PagesSerdeFactory(io.trino.execution.buffer.PagesSerdeFactory) MatchAggregationInstantiator(io.trino.operator.window.pattern.MatchAggregation.MatchAggregationInstantiator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) SpatialJoinNode(io.trino.sql.planner.plan.SpatialJoinNode) LocalExchangeSinkOperatorFactory(io.trino.operator.exchange.LocalExchangeSinkOperator.LocalExchangeSinkOperatorFactory) DeleteNode(io.trino.sql.planner.plan.DeleteNode) LogicalIndexPointer(io.trino.sql.planner.rowpattern.LogicalIndexPointer) CreateTarget(io.trino.sql.planner.plan.TableWriterNode.CreateTarget) ASCENDING(io.trino.sql.tree.SortItem.Ordering.ASCENDING) ImmutableSetMultimap(com.google.common.collect.ImmutableSetMultimap) MarkDistinctNode(io.trino.sql.planner.plan.MarkDistinctNode) ImmutableSet(com.google.common.collect.ImmutableSet) ResolvedFunction(io.trino.metadata.ResolvedFunction) Collection(java.util.Collection) JoinOperatorFactory(io.trino.operator.join.JoinOperatorFactory) TableExecuteHandle(io.trino.metadata.TableExecuteHandle) PatternRecognitionNode(io.trino.sql.planner.plan.PatternRecognitionNode) Collectors(java.util.stream.Collectors) DynamicTupleFilterFactory(io.trino.operator.index.DynamicTupleFilterFactory) Objects(java.util.Objects) SafeCaches.buildNonEvictableCache(io.trino.collect.cache.SafeCaches.buildNonEvictableCache) COMPILER_ERROR(io.trino.spi.StandardErrorCode.COMPILER_ERROR) HashAggregationOperatorFactory(io.trino.operator.HashAggregationOperator.HashAggregationOperatorFactory) StatisticAggregationsDescriptor(io.trino.sql.planner.plan.StatisticAggregationsDescriptor) FieldSetFilteringRecordSet(io.trino.operator.index.FieldSetFilteringRecordSet) TableWriterOperatorFactory(io.trino.operator.TableWriterOperator.TableWriterOperatorFactory) BIGINT(io.trino.spi.type.BigintType.BIGINT) RIGHT(io.trino.sql.planner.plan.JoinNode.Type.RIGHT) NestedLoopJoinBridge(io.trino.operator.join.NestedLoopJoinBridge) Matcher(io.trino.operator.window.matcher.Matcher) COORDINATOR_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.COORDINATOR_DISTRIBUTION) ExplainAnalyzeOperatorFactory(io.trino.operator.ExplainAnalyzeOperator.ExplainAnalyzeOperatorFactory) Range.closedOpen(com.google.common.collect.Range.closedOpen) ExchangeNode(io.trino.sql.planner.plan.ExchangeNode) PageSourceProvider(io.trino.split.PageSourceProvider) ExpressionUtils.combineConjuncts(io.trino.sql.ExpressionUtils.combineConjuncts) PlannerContext(io.trino.sql.PlannerContext) IntStream(java.util.stream.IntStream) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) UnionNode(io.trino.sql.planner.plan.UnionNode) TaskOutputFactory(io.trino.operator.output.TaskOutputOperator.TaskOutputFactory) INNER(io.trino.sql.planner.plan.JoinNode.Type.INNER) OrderingCompiler(io.trino.sql.gen.OrderingCompiler) LambdaExpression(io.trino.sql.tree.LambdaExpression) TopNOperator(io.trino.operator.TopNOperator) Measure(io.trino.sql.planner.plan.PatternRecognitionNode.Measure) RetryPolicy(io.trino.operator.RetryPolicy) PartitionerSupplier(io.trino.operator.window.PartitionerSupplier) SortNode(io.trino.sql.planner.plan.SortNode) OptionalInt(java.util.OptionalInt) Function(java.util.function.Function) ExpressionCompiler(io.trino.sql.gen.ExpressionCompiler) Inject(javax.inject.Inject) DistinctLimitOperatorFactory(io.trino.operator.DistinctLimitOperator.DistinctLimitOperatorFactory) LookupOuterOperatorFactory(io.trino.operator.join.LookupOuterOperator.LookupOuterOperatorFactory) OutputBuffer(io.trino.execution.buffer.OutputBuffer) ImmutableList(com.google.common.collect.ImmutableList) GROUPED_EXECUTION(io.trino.operator.PipelineExecutionStrategy.GROUPED_EXECUTION) SystemSessionProperties(io.trino.SystemSessionProperties) RefreshMaterializedViewNode(io.trino.sql.planner.plan.RefreshMaterializedViewNode) Frame(io.trino.sql.planner.plan.WindowNode.Frame) TableFinisher(io.trino.operator.TableFinishOperator.TableFinisher) TaskContext(io.trino.operator.TaskContext) ST_INTERSECTS(io.trino.util.SpatialJoinUtils.ST_INTERSECTS) PipelineExecutionStrategy(io.trino.operator.PipelineExecutionStrategy) DynamicFilterConfig(io.trino.execution.DynamicFilterConfig) IndexManager(io.trino.index.IndexManager) EnforceSingleRowOperator(io.trino.operator.EnforceSingleRowOperator) SimpleEntry(java.util.AbstractMap.SimpleEntry) CacheUtils.uncheckedCacheGet(io.trino.collect.cache.CacheUtils.uncheckedCacheGet) ProjectNode(io.trino.sql.planner.plan.ProjectNode) PagesIndex(io.trino.operator.PagesIndex) TableExecuteContextManager(io.trino.execution.TableExecuteContextManager) UNGROUPED_EXECUTION(io.trino.operator.PipelineExecutionStrategy.UNGROUPED_EXECUTION) ScanFilterAndProjectOperatorFactory(io.trino.operator.ScanFilterAndProjectOperator.ScanFilterAndProjectOperatorFactory) SingleStreamSpillerFactory(io.trino.spiller.SingleStreamSpillerFactory) FULL(io.trino.sql.planner.plan.JoinNode.Type.FULL) WriterTarget(io.trino.sql.planner.plan.TableWriterNode.WriterTarget) LogicalIndexNavigation(io.trino.operator.window.pattern.LogicalIndexNavigation) FilterAndProjectOperator(io.trino.operator.FilterAndProjectOperator) LocalExchangeSourceOperatorFactory(io.trino.operator.exchange.LocalExchangeSourceOperator.LocalExchangeSourceOperatorFactory) DistinctLimitNode(io.trino.sql.planner.plan.DistinctLimitNode) AccumulatorFactory(io.trino.operator.aggregation.AccumulatorFactory) FINAL(io.trino.sql.planner.plan.AggregationNode.Step.FINAL) SystemSessionProperties.getAdaptivePartialAggregationMinRows(io.trino.SystemSessionProperties.getAdaptivePartialAggregationMinRows) ExchangeManagerRegistry(io.trino.exchange.ExchangeManagerRegistry) MeasureComputationSupplier(io.trino.operator.window.pattern.MeasureComputation.MeasureComputationSupplier) WindowFunctionDefinition.window(io.trino.operator.WindowFunctionDefinition.window) Arrays(java.util.Arrays) SpatialJoinUtils.extractSupportedSpatialComparisons(io.trino.util.SpatialJoinUtils.extractSupportedSpatialComparisons) Ordering(io.trino.sql.tree.SortItem.Ordering) AggregationOperatorFactory(io.trino.operator.AggregationOperator.AggregationOperatorFactory) AggregationValuePointer(io.trino.sql.planner.rowpattern.AggregationValuePointer) LambdaDefinitionExpression(io.trino.sql.relational.LambdaDefinitionExpression) PlanNode(io.trino.sql.planner.plan.PlanNode) LEFT(io.trino.sql.planner.plan.JoinNode.Type.LEFT) HashBuilderOperatorFactory(io.trino.operator.join.HashBuilderOperator.HashBuilderOperatorFactory) Sets.difference(com.google.common.collect.Sets.difference) TableScanOperatorFactory(io.trino.operator.TableScanOperator.TableScanOperatorFactory) PhysicalValuePointer(io.trino.operator.window.pattern.PhysicalValuePointer) DynamicFilters(io.trino.sql.DynamicFilters) FunctionType(io.trino.type.FunctionType) TableDeleteOperatorFactory(io.trino.operator.TableDeleteOperator.TableDeleteOperatorFactory) ExpressionExtractor.extractExpressions(io.trino.sql.planner.ExpressionExtractor.extractExpressions) OutputNode(io.trino.sql.planner.plan.OutputNode) SystemSessionProperties.getAdaptivePartialAggregationUniqueRowsRatioThreshold(io.trino.SystemSessionProperties.getAdaptivePartialAggregationUniqueRowsRatioThreshold) FrameInfo(io.trino.operator.window.FrameInfo) UnnestOperatorFactory(io.trino.operator.unnest.UnnestOperator.UnnestOperatorFactory) FRAGMENT_CHANNEL(io.trino.operator.TableWriterOperator.FRAGMENT_CHANNEL) IndexSourceOperator(io.trino.operator.index.IndexSourceOperator) StreamingAggregationOperator(io.trino.operator.StreamingAggregationOperator) PageSinkManager(io.trino.split.PageSinkManager) StatisticsWriterNode(io.trino.sql.planner.plan.StatisticsWriterNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assignments(io.trino.sql.planner.plan.Assignments) Set(java.util.Set) TypeUtils.writeNativeValue(io.trino.spi.type.TypeUtils.writeNativeValue) HashArraySizeSupplier.incrementalLoadFactorHashArraySizeSupplier(io.trino.operator.HashArraySizeSupplier.incrementalLoadFactorHashArraySizeSupplier) IndexJoinLookupStats(io.trino.operator.index.IndexJoinLookupStats) TaskManagerConfig(io.trino.execution.TaskManagerConfig) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) LambdaBytecodeGenerator.compileLambdaProvider(io.trino.sql.gen.LambdaBytecodeGenerator.compileLambdaProvider) RecordSet(io.trino.spi.connector.RecordSet) SpillerFactory(io.trino.spiller.SpillerFactory) SystemSessionProperties.getFilterAndProjectMinOutputPageSize(io.trino.SystemSessionProperties.getFilterAndProjectMinOutputPageSize) ST_WITHIN(io.trino.util.SpatialJoinUtils.ST_WITHIN) ExplainAnalyzeContext(io.trino.execution.ExplainAnalyzeContext) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) ValuesOperatorFactory(io.trino.operator.ValuesOperator.ValuesOperatorFactory) TableExecuteNode(io.trino.sql.planner.plan.TableExecuteNode) Iterables(com.google.common.collect.Iterables) SqlToRowExpressionTranslator(io.trino.sql.relational.SqlToRowExpressionTranslator) Collectors.partitioningBy(java.util.stream.Collectors.partitioningBy) ContiguousSet(com.google.common.collect.ContiguousSet) OrderByOperatorFactory(io.trino.operator.OrderByOperator.OrderByOperatorFactory) NullableValue(io.trino.spi.predicate.NullableValue) Page(io.trino.spi.Page) IndexJoinOptimizer(io.trino.sql.planner.optimizations.IndexJoinOptimizer) JoinCompiler(io.trino.sql.gen.JoinCompiler) IrRowPatternToProgramRewriter(io.trino.operator.window.matcher.IrRowPatternToProgramRewriter) SetEvaluatorSupplier(io.trino.operator.window.pattern.SetEvaluator.SetEvaluatorSupplier) JoinBridgeManager(io.trino.operator.join.JoinBridgeManager) DynamicFilterId(io.trino.sql.planner.plan.DynamicFilterId) ArrayList(java.util.ArrayList) LocalExchangeFactory(io.trino.operator.exchange.LocalExchange.LocalExchangeFactory) UpdateTarget(io.trino.sql.planner.plan.TableWriterNode.UpdateTarget) STATS_START_CHANNEL(io.trino.operator.TableWriterOperator.STATS_START_CHANNEL) ST_DISTANCE(io.trino.util.SpatialJoinUtils.ST_DISTANCE) NestedLoopJoinPagesSupplier(io.trino.operator.join.NestedLoopJoinPagesSupplier) PageChannelSelector(io.trino.operator.exchange.PageChannelSelector) ColumnHandle(io.trino.spi.connector.ColumnHandle) StatisticsWriterOperatorFactory(io.trino.operator.StatisticsWriterOperator.StatisticsWriterOperatorFactory) PartitioningSpillerFactory.unsupportedPartitioningSpillerFactory(io.trino.spiller.PartitioningSpillerFactory.unsupportedPartitioningSpillerFactory) SourceOperatorFactory(io.trino.operator.SourceOperatorFactory) BlockTypeOperators(io.trino.type.BlockTypeOperators) MatchAggregationPointer(io.trino.operator.window.pattern.MatchAggregationPointer) IrLabel(io.trino.sql.planner.rowpattern.ir.IrLabel) ConnectorSession(io.trino.spi.connector.ConnectorSession) LESS_THAN(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN) DevNullOperatorFactory(io.trino.operator.DevNullOperator.DevNullOperatorFactory) UnnestNode(io.trino.sql.planner.plan.UnnestNode) WorkProcessorPipelineSourceOperator.toOperatorFactories(io.trino.operator.WorkProcessorPipelineSourceOperator.toOperatorFactories) NestedLoopBuildOperatorFactory(io.trino.operator.join.NestedLoopBuildOperator.NestedLoopBuildOperatorFactory) MoreFutures.addSuccessCallback(io.airlift.concurrent.MoreFutures.addSuccessCallback) SampleNode(io.trino.sql.planner.plan.SampleNode) PartitionedLookupSourceFactory(io.trino.operator.join.PartitionedLookupSourceFactory) SpatialJoinOperatorFactory(io.trino.operator.SpatialJoinOperator.SpatialJoinOperatorFactory) MappedRecordSet(io.trino.split.MappedRecordSet) SystemSessionProperties.getTaskWriterCount(io.trino.SystemSessionProperties.getTaskWriterCount) DriverFactory(io.trino.operator.DriverFactory) MergeOperatorFactory(io.trino.operator.MergeOperator.MergeOperatorFactory) RowNumberOperator(io.trino.operator.RowNumberOperator) Aggregation(io.trino.sql.planner.plan.AggregationNode.Aggregation) Step(io.trino.sql.planner.plan.AggregationNode.Step) CURRENT_ROW(io.trino.sql.tree.FrameBound.Type.CURRENT_ROW) DynamicFilters.extractDynamicFilters(io.trino.sql.DynamicFilters.extractDynamicFilters) PartialAggregationController(io.trino.operator.aggregation.partial.PartialAggregationController) WindowFunctionSupplier(io.trino.operator.window.WindowFunctionSupplier) FilterNode(io.trino.sql.planner.plan.FilterNode) TableDeleteNode(io.trino.sql.planner.plan.TableDeleteNode) Iterables.concat(com.google.common.collect.Iterables.concat) SINGLE_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.SINGLE_DISTRIBUTION) JoinNode(io.trino.sql.planner.plan.JoinNode) AssignUniqueId(io.trino.sql.planner.plan.AssignUniqueId) FunctionCall(io.trino.sql.tree.FunctionCall) RowType(io.trino.spi.type.RowType) ImmutableMap(com.google.common.collect.ImmutableMap) PatternRecognitionPartitionerSupplier(io.trino.operator.window.PatternRecognitionPartitionerSupplier) Collections.nCopies(java.util.Collections.nCopies) EnforceSingleRowNode(io.trino.sql.planner.plan.EnforceSingleRowNode) PageFunctionCompiler(io.trino.sql.gen.PageFunctionCompiler) IndexJoinNode(io.trino.sql.planner.plan.IndexJoinNode) TrinoException(io.trino.spi.TrinoException) OutputFactory(io.trino.operator.OutputFactory) SystemSessionProperties.getTaskConcurrency(io.trino.SystemSessionProperties.getTaskConcurrency) TaskId(io.trino.execution.TaskId) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) SystemSessionProperties.getAggregationOperatorUnspillMemoryLimit(io.trino.SystemSessionProperties.getAggregationOperatorUnspillMemoryLimit) Preconditions.checkState(com.google.common.base.Preconditions.checkState) LESS_THAN_OR_EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN_OR_EQUAL) DirectExchangeClientSupplier(io.trino.operator.DirectExchangeClientSupplier) SystemSessionProperties.isExchangeCompressionEnabled(io.trino.SystemSessionProperties.isExchangeCompressionEnabled) DataSize(io.airlift.units.DataSize) AggregatorFactory(io.trino.operator.aggregation.AggregatorFactory) List(java.util.List) DynamicFilter(io.trino.spi.connector.DynamicFilter) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) CacheBuilder(com.google.common.cache.CacheBuilder) WindowNode(io.trino.sql.planner.plan.WindowNode) ConnectorIndex(io.trino.spi.connector.ConnectorIndex) DynamicFilterSourceOperator(io.trino.operator.DynamicFilterSourceOperator) DESCENDING(io.trino.sql.tree.SortItem.Ordering.DESCENDING) OperatorFactories(io.trino.operator.OperatorFactories) Functions.forMap(com.google.common.base.Functions.forMap) Logger(io.airlift.log.Logger) SystemSessionProperties.isEnableLargeDynamicFilters(io.trino.SystemSessionProperties.isEnableLargeDynamicFilters) PositionsAppenderFactory(io.trino.operator.output.PositionsAppenderFactory) Type(io.trino.spi.type.Type) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) SystemSessionProperties.getFilterAndProjectMinOutputPageRowCount(io.trino.SystemSessionProperties.getFilterAndProjectMinOutputPageRowCount) ImmutableBiMap(com.google.common.collect.ImmutableBiMap) WindowOperatorFactory(io.trino.operator.WindowOperator.WindowOperatorFactory) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) GroupIdOperator(io.trino.operator.GroupIdOperator) PageProcessor(io.trino.operator.project.PageProcessor) ExchangeOperatorFactory(io.trino.operator.ExchangeOperator.ExchangeOperatorFactory) AssignUniqueIdOperator(io.trino.operator.AssignUniqueIdOperator) NonEvictableCache(io.trino.collect.cache.NonEvictableCache) ExpressionAndValuePointers(io.trino.sql.planner.rowpattern.LogicalIndexExtractor.ExpressionAndValuePointers) OperatorFactory(io.trino.operator.OperatorFactory) VerifyException(com.google.common.base.VerifyException) PARTIAL(io.trino.sql.planner.plan.AggregationNode.Step.PARTIAL) FunctionId(io.trino.metadata.FunctionId) HashSemiJoinOperator(io.trino.operator.HashSemiJoinOperator) PartitionFunction(io.trino.operator.PartitionFunction) PlanVisitor(io.trino.sql.planner.plan.PlanVisitor) TopNNode(io.trino.sql.planner.plan.TopNNode) ScalarValuePointer(io.trino.sql.planner.rowpattern.ScalarValuePointer) LimitOperatorFactory(io.trino.operator.LimitOperator.LimitOperatorFactory) SingleRowBlock(io.trino.spi.block.SingleRowBlock) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) Ints(com.google.common.primitives.Ints) SetMultimap(com.google.common.collect.SetMultimap) AccumulatorCompiler.generateAccumulatorFactory(io.trino.operator.aggregation.AccumulatorCompiler.generateAccumulatorFactory) UpdateNode(io.trino.sql.planner.plan.UpdateNode) MATCH_NUMBER(io.trino.operator.window.pattern.PhysicalValuePointer.MATCH_NUMBER) DeleteOperatorFactory(io.trino.operator.DeleteOperator.DeleteOperatorFactory) WorkProcessorPipelineSourceOperator(io.trino.operator.WorkProcessorPipelineSourceOperator) PartitioningSpillerFactory(io.trino.spiller.PartitioningSpillerFactory) RowExpression(io.trino.sql.relational.RowExpression) Program(io.trino.operator.window.matcher.Program) BoundSignature(io.trino.metadata.BoundSignature) SpatialIndexBuilderOperatorFactory(io.trino.operator.SpatialIndexBuilderOperator.SpatialIndexBuilderOperatorFactory) ValuePointer(io.trino.sql.planner.rowpattern.ValuePointer) Metadata(io.trino.metadata.Metadata) TypeUtils.readNativeValue(io.trino.spi.type.TypeUtils.readNativeValue) SpatialJoinUtils.extractSupportedSpatialFunctions(io.trino.util.SpatialJoinUtils.extractSupportedSpatialFunctions) CreateTarget(io.trino.sql.planner.plan.TableWriterNode.CreateTarget) UpdateTarget(io.trino.sql.planner.plan.TableWriterNode.UpdateTarget) TableExecuteHandle(io.trino.metadata.TableExecuteHandle) TableExecuteTarget(io.trino.sql.planner.plan.TableWriterNode.TableExecuteTarget) DeleteTarget(io.trino.sql.planner.plan.TableWriterNode.DeleteTarget) WriterTarget(io.trino.sql.planner.plan.TableWriterNode.WriterTarget) InsertTarget(io.trino.sql.planner.plan.TableWriterNode.InsertTarget) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode)

Example 2 with WriterTarget

use of io.trino.sql.planner.plan.TableWriterNode.WriterTarget in project trino by trinodb.

the class LogicalPlanner method getInsertPlan.

private RelationPlan getInsertPlan(Analysis analysis, Table table, Query query, TableHandle tableHandle, List<ColumnHandle> insertColumns, Optional<TableLayout> newTableLayout, Optional<WriterTarget> materializedViewRefreshWriterTarget) {
    TableMetadata tableMetadata = metadata.getTableMetadata(session, tableHandle);
    Map<NodeRef<LambdaArgumentDeclaration>, Symbol> lambdaDeclarationToSymbolMap = buildLambdaDeclarationToSymbolMap(analysis, symbolAllocator);
    RelationPlanner planner = new RelationPlanner(analysis, symbolAllocator, idAllocator, lambdaDeclarationToSymbolMap, plannerContext, Optional.empty(), session, ImmutableMap.of());
    RelationPlan plan = planner.process(query, null);
    ImmutableList.Builder<Symbol> builder = ImmutableList.builder();
    for (int i = 0; i < plan.getFieldMappings().size(); i++) {
        if (!plan.getDescriptor().getFieldByIndex(i).isHidden()) {
            builder.add(plan.getFieldMappings().get(i));
        }
    }
    List<Symbol> visibleFieldMappings = builder.build();
    Map<String, ColumnHandle> columns = metadata.getColumnHandles(session, tableHandle);
    Assignments.Builder assignments = Assignments.builder();
    boolean supportsMissingColumnsOnInsert = metadata.supportsMissingColumnsOnInsert(session, tableHandle);
    ImmutableList.Builder<ColumnMetadata> insertedColumnsBuilder = ImmutableList.builder();
    for (ColumnMetadata column : tableMetadata.getColumns()) {
        if (column.isHidden()) {
            continue;
        }
        Symbol output = symbolAllocator.newSymbol(column.getName(), column.getType());
        int index = insertColumns.indexOf(columns.get(column.getName()));
        if (index < 0) {
            if (supportsMissingColumnsOnInsert) {
                continue;
            }
            Expression cast = new Cast(new NullLiteral(), toSqlType(column.getType()));
            assignments.put(output, cast);
            insertedColumnsBuilder.add(column);
        } else {
            Symbol input = visibleFieldMappings.get(index);
            Type tableType = column.getType();
            Type queryType = symbolAllocator.getTypes().get(input);
            if (queryType.equals(tableType) || typeCoercion.isTypeOnlyCoercion(queryType, tableType)) {
                assignments.put(output, input.toSymbolReference());
            } else {
                Expression cast = noTruncationCast(input.toSymbolReference(), queryType, tableType);
                assignments.put(output, cast);
            }
            insertedColumnsBuilder.add(column);
        }
    }
    ProjectNode projectNode = new ProjectNode(idAllocator.getNextId(), plan.getRoot(), assignments.build());
    List<ColumnMetadata> insertedColumns = insertedColumnsBuilder.build();
    List<Field> fields = insertedColumns.stream().map(column -> Field.newUnqualified(column.getName(), column.getType())).collect(toImmutableList());
    Scope scope = Scope.builder().withRelationType(RelationId.anonymous(), new RelationType(fields)).build();
    plan = new RelationPlan(projectNode, scope, projectNode.getOutputSymbols(), Optional.empty());
    plan = planner.addRowFilters(table, plan, failIfPredicateIsNotMeet(metadata, session, PERMISSION_DENIED, AccessDeniedException.PREFIX + "Cannot insert row that does not match to a row filter"), node -> {
        Scope accessControlScope = analysis.getAccessControlScope(table);
        // hidden fields are not accessible in insert
        return Scope.builder().like(accessControlScope).withRelationType(accessControlScope.getRelationId(), accessControlScope.getRelationType().withOnlyVisibleFields()).build();
    });
    List<String> insertedTableColumnNames = insertedColumns.stream().map(ColumnMetadata::getName).collect(toImmutableList());
    String catalogName = tableHandle.getCatalogName().getCatalogName();
    TableStatisticsMetadata statisticsMetadata = metadata.getStatisticsCollectionMetadataForWrite(session, catalogName, tableMetadata.getMetadata());
    if (materializedViewRefreshWriterTarget.isPresent()) {
        return createTableWriterPlan(analysis, plan.getRoot(), plan.getFieldMappings(), materializedViewRefreshWriterTarget.get(), insertedTableColumnNames, insertedColumns, newTableLayout, statisticsMetadata);
    }
    InsertReference insertTarget = new InsertReference(tableHandle, insertedTableColumnNames.stream().map(columns::get).collect(toImmutableList()));
    return createTableWriterPlan(analysis, plan.getRoot(), plan.getFieldMappings(), insertTarget, insertedTableColumnNames, insertedColumns, newTableLayout, statisticsMetadata);
}
Also used : Cast(io.trino.sql.tree.Cast) FIXED_HASH_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.FIXED_HASH_DISTRIBUTION) CostProvider(io.trino.cost.CostProvider) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Delete(io.trino.sql.tree.Delete) InsertReference(io.trino.sql.planner.plan.TableWriterNode.InsertReference) PlanNode(io.trino.sql.planner.plan.PlanNode) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) LongLiteral(io.trino.sql.tree.LongLiteral) Map(java.util.Map) OutputNode(io.trino.sql.planner.plan.OutputNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ExplainAnalyzeNode(io.trino.sql.planner.plan.ExplainAnalyzeNode) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) Statement(io.trino.sql.tree.Statement) SystemSessionProperties.isCollectPlanStatisticsForAllQueries(io.trino.SystemSessionProperties.isCollectPlanStatisticsForAllQueries) StatisticsWriterNode(io.trino.sql.planner.plan.StatisticsWriterNode) TableExecute(io.trino.sql.tree.TableExecute) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assignments(io.trino.sql.planner.plan.Assignments) Set(java.util.Set) PlanSanityChecker(io.trino.sql.planner.sanity.PlanSanityChecker) RelationType(io.trino.sql.analyzer.RelationType) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) PlanBuilder.newPlanBuilder(io.trino.sql.planner.PlanBuilder.newPlanBuilder) CachingStatsProvider(io.trino.cost.CachingStatsProvider) ValuesNode(io.trino.sql.planner.plan.ValuesNode) Session(io.trino.Session) AccessDeniedException(io.trino.spi.security.AccessDeniedException) TableExecuteNode(io.trino.sql.planner.plan.TableExecuteNode) PlanPrinter(io.trino.sql.planner.planprinter.PlanPrinter) QueryPlanner.visibleFields(io.trino.sql.planner.QueryPlanner.visibleFields) CreateReference(io.trino.sql.planner.plan.TableWriterNode.CreateReference) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) LimitNode(io.trino.sql.planner.plan.LimitNode) TableLayout(io.trino.metadata.TableLayout) TypeCoercion(io.trino.type.TypeCoercion) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) StatsAndCosts(io.trino.cost.StatsAndCosts) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) NodeRef(io.trino.sql.tree.NodeRef) ColumnHandle(io.trino.spi.connector.ColumnHandle) AggregationNode(io.trino.sql.planner.plan.AggregationNode) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) VARBINARY(io.trino.spi.type.VarbinaryType.VARBINARY) Query(io.trino.sql.tree.Query) StringLiteral(io.trino.sql.tree.StringLiteral) TableStatisticAggregation(io.trino.sql.planner.StatisticsAggregationPlanner.TableStatisticAggregation) AggregationNode.singleGroupingSet(io.trino.sql.planner.plan.AggregationNode.singleGroupingSet) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) CharType(io.trino.spi.type.CharType) Table(io.trino.sql.tree.Table) TableFinishNode(io.trino.sql.planner.plan.TableFinishNode) TableStatisticsMetadata(io.trino.spi.statistics.TableStatisticsMetadata) UnknownType(io.trino.type.UnknownType) RefreshMaterializedView(io.trino.sql.tree.RefreshMaterializedView) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode) OPTIMIZED_AND_VALIDATED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED) Scope(io.trino.sql.analyzer.Scope) FilterNode(io.trino.sql.planner.plan.FilterNode) StatsCalculator(io.trino.cost.StatsCalculator) LambdaArgumentDeclaration(io.trino.sql.tree.LambdaArgumentDeclaration) RelationId(io.trino.sql.analyzer.RelationId) DeleteNode(io.trino.sql.planner.plan.DeleteNode) Update(io.trino.sql.tree.Update) INTEGER(io.trino.spi.type.IntegerType.INTEGER) FunctionCall(io.trino.sql.tree.FunctionCall) ImmutableMap(com.google.common.collect.ImmutableMap) ResolvedFunction(io.trino.metadata.ResolvedFunction) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) TrinoException(io.trino.spi.TrinoException) ROW_COUNT(io.trino.spi.statistics.TableStatisticType.ROW_COUNT) TableExecuteHandle(io.trino.metadata.TableExecuteHandle) StatsProvider(io.trino.cost.StatsProvider) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) GenericLiteral(io.trino.sql.tree.GenericLiteral) Objects(java.util.Objects) TableMetadata(io.trino.metadata.TableMetadata) List(java.util.List) IfExpression(io.trino.sql.tree.IfExpression) BIGINT(io.trino.spi.type.BigintType.BIGINT) StandardErrorCode(io.trino.spi.StandardErrorCode) Analyze(io.trino.sql.tree.Analyze) Entry(java.util.Map.Entry) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) PlannerContext(io.trino.sql.PlannerContext) Analysis(io.trino.sql.analyzer.Analysis) PERMISSION_DENIED(io.trino.spi.StandardErrorCode.PERMISSION_DENIED) Logger(io.airlift.log.Logger) Type(io.trino.spi.type.Type) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) HashMap(java.util.HashMap) StatisticAggregations(io.trino.sql.planner.plan.StatisticAggregations) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) OPTIMIZED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED) Function(java.util.function.Function) Cast(io.trino.sql.tree.Cast) VarcharType(io.trino.spi.type.VarcharType) CachingCostProvider(io.trino.cost.CachingCostProvider) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) RefreshMaterializedViewNode(io.trino.sql.planner.plan.RefreshMaterializedViewNode) NullLiteral(io.trino.sql.tree.NullLiteral) Field(io.trino.sql.analyzer.Field) GREATER_THAN_OR_EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) ProjectNode(io.trino.sql.planner.plan.ProjectNode) DISTRIBUTED_PLAN_SANITY_CHECKER(io.trino.sql.planner.sanity.PlanSanityChecker.DISTRIBUTED_PLAN_SANITY_CHECKER) WriterTarget(io.trino.sql.planner.plan.TableWriterNode.WriterTarget) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) UpdateNode(io.trino.sql.planner.plan.UpdateNode) QualifiedName(io.trino.sql.tree.QualifiedName) CostCalculator(io.trino.cost.CostCalculator) WarningCollector(io.trino.execution.warnings.WarningCollector) Row(io.trino.sql.tree.Row) Metadata(io.trino.metadata.Metadata) Insert(io.trino.sql.tree.Insert) Streams.zip(com.google.common.collect.Streams.zip) TableStatisticsMetadata(io.trino.spi.statistics.TableStatisticsMetadata) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) Assignments(io.trino.sql.planner.plan.Assignments) InsertReference(io.trino.sql.planner.plan.TableWriterNode.InsertReference) NodeRef(io.trino.sql.tree.NodeRef) Field(io.trino.sql.analyzer.Field) RelationType(io.trino.sql.analyzer.RelationType) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) TableMetadata(io.trino.metadata.TableMetadata) ColumnHandle(io.trino.spi.connector.ColumnHandle) RelationType(io.trino.sql.analyzer.RelationType) CharType(io.trino.spi.type.CharType) UnknownType(io.trino.type.UnknownType) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) Type(io.trino.spi.type.Type) VarcharType(io.trino.spi.type.VarcharType) Scope(io.trino.sql.analyzer.Scope) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) ProjectNode(io.trino.sql.planner.plan.ProjectNode) NullLiteral(io.trino.sql.tree.NullLiteral)

Example 3 with WriterTarget

use of io.trino.sql.planner.plan.TableWriterNode.WriterTarget in project trino by trinodb.

the class LogicalPlanner method createTableWriterPlan.

private RelationPlan createTableWriterPlan(Analysis analysis, PlanNode source, List<Symbol> symbols, WriterTarget target, List<String> columnNames, List<ColumnMetadata> columnMetadataList, Optional<TableLayout> writeTableLayout, TableStatisticsMetadata statisticsMetadata) {
    Optional<PartitioningScheme> partitioningScheme = Optional.empty();
    Optional<PartitioningScheme> preferredPartitioningScheme = Optional.empty();
    if (writeTableLayout.isPresent()) {
        List<Symbol> partitionFunctionArguments = new ArrayList<>();
        writeTableLayout.get().getPartitionColumns().stream().mapToInt(columnNames::indexOf).mapToObj(symbols::get).forEach(partitionFunctionArguments::add);
        List<Symbol> outputLayout = new ArrayList<>(symbols);
        Optional<PartitioningHandle> partitioningHandle = writeTableLayout.get().getPartitioning();
        if (partitioningHandle.isPresent()) {
            partitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(partitioningHandle.get(), partitionFunctionArguments), outputLayout));
        } else {
            // empty connector partitioning handle means evenly partitioning on partitioning columns
            preferredPartitioningScheme = Optional.of(new PartitioningScheme(Partitioning.create(FIXED_HASH_DISTRIBUTION, partitionFunctionArguments), outputLayout));
        }
    }
    verify(columnNames.size() == symbols.size(), "columnNames.size() != symbols.size(): %s and %s", columnNames, symbols);
    Map<String, Symbol> columnToSymbolMap = zip(columnNames.stream(), symbols.stream(), SimpleImmutableEntry::new).collect(toImmutableMap(Entry::getKey, Entry::getValue));
    Set<Symbol> notNullColumnSymbols = columnMetadataList.stream().filter(column -> !column.isNullable()).map(ColumnMetadata::getName).map(columnToSymbolMap::get).collect(toImmutableSet());
    if (!statisticsMetadata.isEmpty()) {
        TableStatisticAggregation result = statisticsAggregationPlanner.createStatisticsAggregation(statisticsMetadata, columnToSymbolMap);
        StatisticAggregations.Parts aggregations = result.getAggregations().createPartialAggregations(symbolAllocator, plannerContext);
        // partial aggregation is run within the TableWriteOperator to calculate the statistics for
        // the data consumed by the TableWriteOperator
        // final aggregation is run within the TableFinishOperator to summarize collected statistics
        // by the partial aggregation from all of the writer nodes
        StatisticAggregations partialAggregation = aggregations.getPartialAggregation();
        TableFinishNode commitNode = new TableFinishNode(idAllocator.getNextId(), new TableWriterNode(idAllocator.getNextId(), source, target, symbolAllocator.newSymbol("partialrows", BIGINT), symbolAllocator.newSymbol("fragment", VARBINARY), symbols, columnNames, notNullColumnSymbols, partitioningScheme, preferredPartitioningScheme, Optional.of(partialAggregation), Optional.of(result.getDescriptor().map(aggregations.getMappings()::get))), target, symbolAllocator.newSymbol("rows", BIGINT), Optional.of(aggregations.getFinalAggregation()), Optional.of(result.getDescriptor()));
        return new RelationPlan(commitNode, analysis.getRootScope(), commitNode.getOutputSymbols(), Optional.empty());
    }
    TableFinishNode commitNode = new TableFinishNode(idAllocator.getNextId(), new TableWriterNode(idAllocator.getNextId(), source, target, symbolAllocator.newSymbol("partialrows", BIGINT), symbolAllocator.newSymbol("fragment", VARBINARY), symbols, columnNames, notNullColumnSymbols, partitioningScheme, preferredPartitioningScheme, Optional.empty(), Optional.empty()), target, symbolAllocator.newSymbol("rows", BIGINT), Optional.empty(), Optional.empty());
    return new RelationPlan(commitNode, analysis.getRootScope(), commitNode.getOutputSymbols(), Optional.empty());
}
Also used : FIXED_HASH_DISTRIBUTION(io.trino.sql.planner.SystemPartitioningHandle.FIXED_HASH_DISTRIBUTION) CostProvider(io.trino.cost.CostProvider) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Delete(io.trino.sql.tree.Delete) InsertReference(io.trino.sql.planner.plan.TableWriterNode.InsertReference) PlanNode(io.trino.sql.planner.plan.PlanNode) NOT_SUPPORTED(io.trino.spi.StandardErrorCode.NOT_SUPPORTED) LongLiteral(io.trino.sql.tree.LongLiteral) Map(java.util.Map) OutputNode(io.trino.sql.planner.plan.OutputNode) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ExplainAnalyzeNode(io.trino.sql.planner.plan.ExplainAnalyzeNode) ExplainAnalyze(io.trino.sql.tree.ExplainAnalyze) Statement(io.trino.sql.tree.Statement) SystemSessionProperties.isCollectPlanStatisticsForAllQueries(io.trino.SystemSessionProperties.isCollectPlanStatisticsForAllQueries) StatisticsWriterNode(io.trino.sql.planner.plan.StatisticsWriterNode) TableExecute(io.trino.sql.tree.TableExecute) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assignments(io.trino.sql.planner.plan.Assignments) Set(java.util.Set) PlanSanityChecker(io.trino.sql.planner.sanity.PlanSanityChecker) RelationType(io.trino.sql.analyzer.RelationType) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) PlanBuilder.newPlanBuilder(io.trino.sql.planner.PlanBuilder.newPlanBuilder) CachingStatsProvider(io.trino.cost.CachingStatsProvider) ValuesNode(io.trino.sql.planner.plan.ValuesNode) Session(io.trino.Session) AccessDeniedException(io.trino.spi.security.AccessDeniedException) TableExecuteNode(io.trino.sql.planner.plan.TableExecuteNode) PlanPrinter(io.trino.sql.planner.planprinter.PlanPrinter) QueryPlanner.visibleFields(io.trino.sql.planner.QueryPlanner.visibleFields) CreateReference(io.trino.sql.planner.plan.TableWriterNode.CreateReference) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) LimitNode(io.trino.sql.planner.plan.LimitNode) TableLayout(io.trino.metadata.TableLayout) TypeCoercion(io.trino.type.TypeCoercion) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) ConnectorTableMetadata(io.trino.spi.connector.ConnectorTableMetadata) StatsAndCosts(io.trino.cost.StatsAndCosts) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) MetadataUtil.createQualifiedObjectName(io.trino.metadata.MetadataUtil.createQualifiedObjectName) PlanOptimizer(io.trino.sql.planner.optimizations.PlanOptimizer) NodeRef(io.trino.sql.tree.NodeRef) ColumnHandle(io.trino.spi.connector.ColumnHandle) AggregationNode(io.trino.sql.planner.plan.AggregationNode) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) VARBINARY(io.trino.spi.type.VarbinaryType.VARBINARY) Query(io.trino.sql.tree.Query) StringLiteral(io.trino.sql.tree.StringLiteral) TableStatisticAggregation(io.trino.sql.planner.StatisticsAggregationPlanner.TableStatisticAggregation) AggregationNode.singleGroupingSet(io.trino.sql.planner.plan.AggregationNode.singleGroupingSet) TableHandle(io.trino.metadata.TableHandle) QualifiedObjectName(io.trino.metadata.QualifiedObjectName) CharType(io.trino.spi.type.CharType) Table(io.trino.sql.tree.Table) TableFinishNode(io.trino.sql.planner.plan.TableFinishNode) TableStatisticsMetadata(io.trino.spi.statistics.TableStatisticsMetadata) UnknownType(io.trino.type.UnknownType) RefreshMaterializedView(io.trino.sql.tree.RefreshMaterializedView) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode) OPTIMIZED_AND_VALIDATED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED_AND_VALIDATED) Scope(io.trino.sql.analyzer.Scope) FilterNode(io.trino.sql.planner.plan.FilterNode) StatsCalculator(io.trino.cost.StatsCalculator) LambdaArgumentDeclaration(io.trino.sql.tree.LambdaArgumentDeclaration) RelationId(io.trino.sql.analyzer.RelationId) DeleteNode(io.trino.sql.planner.plan.DeleteNode) Update(io.trino.sql.tree.Update) INTEGER(io.trino.spi.type.IntegerType.INTEGER) FunctionCall(io.trino.sql.tree.FunctionCall) ImmutableMap(com.google.common.collect.ImmutableMap) ResolvedFunction(io.trino.metadata.ResolvedFunction) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) TrinoException(io.trino.spi.TrinoException) ROW_COUNT(io.trino.spi.statistics.TableStatisticType.ROW_COUNT) TableExecuteHandle(io.trino.metadata.TableExecuteHandle) StatsProvider(io.trino.cost.StatsProvider) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) CoalesceExpression(io.trino.sql.tree.CoalesceExpression) GenericLiteral(io.trino.sql.tree.GenericLiteral) Objects(java.util.Objects) TableMetadata(io.trino.metadata.TableMetadata) List(java.util.List) IfExpression(io.trino.sql.tree.IfExpression) BIGINT(io.trino.spi.type.BigintType.BIGINT) StandardErrorCode(io.trino.spi.StandardErrorCode) Analyze(io.trino.sql.tree.Analyze) Entry(java.util.Map.Entry) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) PlannerContext(io.trino.sql.PlannerContext) Analysis(io.trino.sql.analyzer.Analysis) PERMISSION_DENIED(io.trino.spi.StandardErrorCode.PERMISSION_DENIED) Logger(io.airlift.log.Logger) Type(io.trino.spi.type.Type) CreateTableAsSelect(io.trino.sql.tree.CreateTableAsSelect) HashMap(java.util.HashMap) StatisticAggregations(io.trino.sql.planner.plan.StatisticAggregations) SimpleImmutableEntry(java.util.AbstractMap.SimpleImmutableEntry) OPTIMIZED(io.trino.sql.planner.LogicalPlanner.Stage.OPTIMIZED) Function(java.util.function.Function) Cast(io.trino.sql.tree.Cast) VarcharType(io.trino.spi.type.VarcharType) CachingCostProvider(io.trino.cost.CachingCostProvider) ImmutableList(com.google.common.collect.ImmutableList) Verify.verify(com.google.common.base.Verify.verify) Objects.requireNonNull(java.util.Objects.requireNonNull) RefreshMaterializedViewNode(io.trino.sql.planner.plan.RefreshMaterializedViewNode) NullLiteral(io.trino.sql.tree.NullLiteral) Field(io.trino.sql.analyzer.Field) GREATER_THAN_OR_EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) ProjectNode(io.trino.sql.planner.plan.ProjectNode) DISTRIBUTED_PLAN_SANITY_CHECKER(io.trino.sql.planner.sanity.PlanSanityChecker.DISTRIBUTED_PLAN_SANITY_CHECKER) WriterTarget(io.trino.sql.planner.plan.TableWriterNode.WriterTarget) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) UpdateNode(io.trino.sql.planner.plan.UpdateNode) QualifiedName(io.trino.sql.tree.QualifiedName) CostCalculator(io.trino.cost.CostCalculator) WarningCollector(io.trino.execution.warnings.WarningCollector) Row(io.trino.sql.tree.Row) Metadata(io.trino.metadata.Metadata) Insert(io.trino.sql.tree.Insert) Streams.zip(com.google.common.collect.Streams.zip) ColumnMetadata(io.trino.spi.connector.ColumnMetadata) TableStatisticAggregation(io.trino.sql.planner.StatisticsAggregationPlanner.TableStatisticAggregation) ArrayList(java.util.ArrayList) TableFinishNode(io.trino.sql.planner.plan.TableFinishNode) StatisticAggregations(io.trino.sql.planner.plan.StatisticAggregations) TableWriterNode(io.trino.sql.planner.plan.TableWriterNode)

Aggregations

Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 Verify.verify (com.google.common.base.Verify.verify)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 Logger (io.airlift.log.Logger)3 Session (io.trino.Session)3 Metadata (io.trino.metadata.Metadata)3 ResolvedFunction (io.trino.metadata.ResolvedFunction)3 TableExecuteHandle (io.trino.metadata.TableExecuteHandle)3 TableHandle (io.trino.metadata.TableHandle)3 TrinoException (io.trino.spi.TrinoException)3 ColumnHandle (io.trino.spi.connector.ColumnHandle)3 BIGINT (io.trino.spi.type.BigintType.BIGINT)3 Type (io.trino.spi.type.Type)3 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)3 PlannerContext (io.trino.sql.PlannerContext)3 AggregationNode (io.trino.sql.planner.plan.AggregationNode)3