Search in sources :

Example 1 with UpdateTarget

use of io.trino.sql.planner.plan.TableWriterNode.UpdateTarget 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 UpdateTarget

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

the class QueryPlanner method plan.

public UpdateNode plan(Update node) {
    Table table = node.getTable();
    TableHandle handle = analysis.getTableHandle(table);
    TableSchema tableSchema = plannerContext.getMetadata().getTableSchema(session, handle);
    Map<String, ColumnHandle> columnMap = plannerContext.getMetadata().getColumnHandles(session, handle);
    List<ColumnSchema> columnsSchemas = tableSchema.getColumns();
    List<String> targetColumnNames = node.getAssignments().stream().map(assignment -> assignment.getName().getValue()).collect(toImmutableList());
    // Create lists of columnnames and SET expressions, in table column order
    ImmutableList.Builder<String> updatedColumnNamesBuilder = ImmutableList.builder();
    ImmutableList.Builder<ColumnHandle> updatedColumnHandlesBuilder = ImmutableList.builder();
    ImmutableList.Builder<Expression> orderedColumnValuesBuilder = ImmutableList.builder();
    for (ColumnSchema columnSchema : columnsSchemas) {
        String name = columnSchema.getName();
        int index = targetColumnNames.indexOf(name);
        if (index >= 0) {
            updatedColumnNamesBuilder.add(name);
            updatedColumnHandlesBuilder.add(requireNonNull(columnMap.get(name), "columnMap didn't contain name"));
            orderedColumnValuesBuilder.add(node.getAssignments().get(index).getValue());
        }
    }
    List<String> updatedColumnNames = updatedColumnNamesBuilder.build();
    List<ColumnHandle> updatedColumnHandles = updatedColumnHandlesBuilder.build();
    List<Expression> orderedColumnValues = orderedColumnValuesBuilder.build();
    // create table scan
    RelationPlan relationPlan = new RelationPlanner(analysis, symbolAllocator, idAllocator, lambdaDeclarationToSymbolMap, plannerContext, outerContext, session, recursiveSubqueries).process(table, null);
    PlanBuilder builder = newPlanBuilder(relationPlan, analysis, lambdaDeclarationToSymbolMap);
    if (node.getWhere().isPresent()) {
        builder = filter(builder, node.getWhere().get(), node);
    }
    builder = subqueryPlanner.handleSubqueries(builder, orderedColumnValues, analysis.getSubqueries(node));
    builder = builder.appendProjections(orderedColumnValues, symbolAllocator, idAllocator);
    PlanAndMappings planAndMappings = coerce(builder, orderedColumnValues, analysis, idAllocator, symbolAllocator, typeCoercion);
    builder = planAndMappings.getSubPlan();
    ImmutableList.Builder<Symbol> updatedColumnValuesBuilder = ImmutableList.builder();
    orderedColumnValues.forEach(columnValue -> updatedColumnValuesBuilder.add(planAndMappings.get(columnValue)));
    Symbol rowId = builder.translate(analysis.getRowIdField(table));
    updatedColumnValuesBuilder.add(rowId);
    List<Symbol> outputs = ImmutableList.of(symbolAllocator.newSymbol("partialrows", BIGINT), symbolAllocator.newSymbol("fragment", VARBINARY));
    Optional<PlanNodeId> tableScanId = getIdForLeftTableScan(relationPlan.getRoot());
    checkArgument(tableScanId.isPresent(), "tableScanId not present");
    // create update node
    return new UpdateNode(idAllocator.getNextId(), builder.getRoot(), new UpdateTarget(Optional.empty(), plannerContext.getMetadata().getTableMetadata(session, handle).getTable(), updatedColumnNames, updatedColumnHandles), rowId, updatedColumnValuesBuilder.build(), outputs);
}
Also used : PatternRecognitionComponents(io.trino.sql.planner.RelationPlanner.PatternRecognitionComponents) Arrays(java.util.Arrays) TypeSignatureProvider.fromTypes(io.trino.sql.analyzer.TypeSignatureProvider.fromTypes) Delete(io.trino.sql.tree.Delete) PlanNode(io.trino.sql.planner.plan.PlanNode) Node(io.trino.sql.tree.Node) Offset(io.trino.sql.tree.Offset) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) LongLiteral(io.trino.sql.tree.LongLiteral) Map(java.util.Map) Union(io.trino.sql.tree.Union) FetchFirst(io.trino.sql.tree.FetchFirst) TableScanNode(io.trino.sql.planner.plan.TableScanNode) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Assignments(io.trino.sql.planner.plan.Assignments) Set(java.util.Set) TableSchema(io.trino.metadata.TableSchema) SortItem(io.trino.sql.tree.SortItem) NodeUtils.getSortItemsFromOrderBy(io.trino.sql.NodeUtils.getSortItemsFromOrderBy) DEFAULT_FRAME(io.trino.sql.planner.plan.WindowNode.Frame.DEFAULT_FRAME) RelationType(io.trino.sql.analyzer.RelationType) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) AggregationNode.groupingSets(io.trino.sql.planner.plan.AggregationNode.groupingSets) DeleteTarget(io.trino.sql.planner.plan.TableWriterNode.DeleteTarget) PlanBuilder.newPlanBuilder(io.trino.sql.planner.PlanBuilder.newPlanBuilder) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) DecimalLiteral(io.trino.sql.tree.DecimalLiteral) ValuesNode(io.trino.sql.planner.plan.ValuesNode) ExpressionAnalyzer.isNumericType(io.trino.sql.analyzer.ExpressionAnalyzer.isNumericType) Session(io.trino.Session) Iterables(com.google.common.collect.Iterables) LimitNode(io.trino.sql.planner.plan.LimitNode) TypeCoercion(io.trino.type.TypeCoercion) BOOLEAN(io.trino.spi.type.BooleanType.BOOLEAN) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) UpdateTarget(io.trino.sql.planner.plan.TableWriterNode.UpdateTarget) ScopeAware.scopeAwareKey(io.trino.sql.planner.ScopeAware.scopeAwareKey) VARCHAR(io.trino.spi.type.VarcharType.VARCHAR) 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) GroupingOperationRewriter.rewriteGroupingOperation(io.trino.sql.planner.GroupingOperationRewriter.rewriteGroupingOperation) NodeUtils(io.trino.sql.NodeUtils) INTERVAL_DAY_TIME(io.trino.type.IntervalDayTimeType.INTERVAL_DAY_TIME) Query(io.trino.sql.tree.Query) StringLiteral(io.trino.sql.tree.StringLiteral) Relation(io.trino.sql.tree.Relation) GroupingSetAnalysis(io.trino.sql.analyzer.Analysis.GroupingSetAnalysis) Iterables.getOnlyElement(com.google.common.collect.Iterables.getOnlyElement) SortOrder(io.trino.spi.connector.SortOrder) AggregationNode.singleGroupingSet(io.trino.sql.planner.plan.AggregationNode.singleGroupingSet) TableHandle(io.trino.metadata.TableHandle) Table(io.trino.sql.tree.Table) GroupIdNode(io.trino.sql.planner.plan.GroupIdNode) YEAR(io.trino.sql.tree.IntervalLiteral.IntervalField.YEAR) OffsetNode(io.trino.sql.planner.plan.OffsetNode) ROWS(io.trino.sql.tree.WindowFrame.Type.ROWS) NullTreatment(io.trino.sql.tree.FunctionCall.NullTreatment) DAY(io.trino.sql.tree.IntervalLiteral.IntervalField.DAY) MeasureDefinition(io.trino.sql.tree.MeasureDefinition) INTERVAL_YEAR_MONTH(io.trino.type.IntervalYearMonthType.INTERVAL_YEAR_MONTH) Aggregation(io.trino.sql.planner.plan.AggregationNode.Aggregation) FilterNode(io.trino.sql.planner.plan.FilterNode) LambdaArgumentDeclaration(io.trino.sql.tree.LambdaArgumentDeclaration) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) OrderingScheme.sortItemToSortOrder(io.trino.sql.planner.OrderingScheme.sortItemToSortOrder) SelectExpression(io.trino.sql.analyzer.Analysis.SelectExpression) GROUPS(io.trino.sql.tree.WindowFrame.Type.GROUPS) DeleteNode(io.trino.sql.planner.plan.DeleteNode) Update(io.trino.sql.tree.Update) FunctionCall(io.trino.sql.tree.FunctionCall) QuerySpecification(io.trino.sql.tree.QuerySpecification) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) ResolvedFunction(io.trino.metadata.ResolvedFunction) TypeSignatureTranslator.toSqlType(io.trino.sql.analyzer.TypeSignatureTranslator.toSqlType) IntervalLiteral(io.trino.sql.tree.IntervalLiteral) RANGE(io.trino.sql.tree.WindowFrame.Type.RANGE) VariableDefinition(io.trino.sql.tree.VariableDefinition) PatternRecognitionNode(io.trino.sql.planner.plan.PatternRecognitionNode) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) String.format(java.lang.String.format) Preconditions.checkState(com.google.common.base.Preconditions.checkState) LESS_THAN_OR_EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.LESS_THAN_OR_EQUAL) GenericLiteral(io.trino.sql.tree.GenericLiteral) SimplePlanRewriter(io.trino.sql.planner.plan.SimplePlanRewriter) List(java.util.List) POSITIVE(io.trino.sql.tree.IntervalLiteral.Sign.POSITIVE) IfExpression(io.trino.sql.tree.IfExpression) ColumnSchema(io.trino.spi.connector.ColumnSchema) BIGINT(io.trino.spi.type.BigintType.BIGINT) WindowFrame(io.trino.sql.tree.WindowFrame) Optional(java.util.Optional) Expression(io.trino.sql.tree.Expression) WindowNode(io.trino.sql.planner.plan.WindowNode) DecimalType(io.trino.spi.type.DecimalType) OrderBy(io.trino.sql.tree.OrderBy) PlannerContext(io.trino.sql.PlannerContext) Analysis(io.trino.sql.analyzer.Analysis) IntStream(java.util.stream.IntStream) FieldId(io.trino.sql.analyzer.FieldId) UnionNode(io.trino.sql.planner.plan.UnionNode) WindowOperation(io.trino.sql.tree.WindowOperation) Type(io.trino.spi.type.Type) LambdaExpression(io.trino.sql.tree.LambdaExpression) HashMap(java.util.HashMap) SystemSessionProperties.getMaxRecursionDepth(io.trino.SystemSessionProperties.getMaxRecursionDepth) SortNode(io.trino.sql.planner.plan.SortNode) Function(java.util.function.Function) Cast(io.trino.sql.tree.Cast) HashSet(java.util.HashSet) ImmutableList(com.google.common.collect.ImmutableList) Objects.requireNonNull(java.util.Objects.requireNonNull) GREATER_THAN_OR_EQUAL(io.trino.sql.tree.ComparisonExpression.Operator.GREATER_THAN_OR_EQUAL) ProjectNode(io.trino.sql.planner.plan.ProjectNode) ResolvedWindow(io.trino.sql.analyzer.Analysis.ResolvedWindow) RowsPerMatch(io.trino.sql.tree.PatternRecognitionRelation.RowsPerMatch) Iterator(java.util.Iterator) TRUE_LITERAL(io.trino.sql.tree.BooleanLiteral.TRUE_LITERAL) UpdateNode(io.trino.sql.planner.plan.UpdateNode) QualifiedName(io.trino.sql.tree.QualifiedName) SystemSessionProperties.isSkipRedundantSort(io.trino.SystemSessionProperties.isSkipRedundantSort) FrameBound(io.trino.sql.tree.FrameBound) TableSchema(io.trino.metadata.TableSchema) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) ColumnSchema(io.trino.spi.connector.ColumnSchema) PlanBuilder.newPlanBuilder(io.trino.sql.planner.PlanBuilder.newPlanBuilder) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) UpdateNode(io.trino.sql.planner.plan.UpdateNode) ColumnHandle(io.trino.spi.connector.ColumnHandle) Table(io.trino.sql.tree.Table) UpdateTarget(io.trino.sql.planner.plan.TableWriterNode.UpdateTarget) SelectExpression(io.trino.sql.analyzer.Analysis.SelectExpression) ComparisonExpression(io.trino.sql.tree.ComparisonExpression) IfExpression(io.trino.sql.tree.IfExpression) Expression(io.trino.sql.tree.Expression) LambdaExpression(io.trino.sql.tree.LambdaExpression) TableHandle(io.trino.metadata.TableHandle)

Aggregations

Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 ImmutableMap.toImmutableMap (com.google.common.collect.ImmutableMap.toImmutableMap)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)2 Iterables (com.google.common.collect.Iterables)2 Iterables.getOnlyElement (com.google.common.collect.Iterables.getOnlyElement)2 Session (io.trino.Session)2 ResolvedFunction (io.trino.metadata.ResolvedFunction)2 TableHandle (io.trino.metadata.TableHandle)2 ColumnHandle (io.trino.spi.connector.ColumnHandle)2 SortOrder (io.trino.spi.connector.SortOrder)2 BIGINT (io.trino.spi.type.BigintType.BIGINT)2 Type (io.trino.spi.type.Type)2 VARCHAR (io.trino.spi.type.VarcharType.VARCHAR)2 PlannerContext (io.trino.sql.PlannerContext)2 AggregationNode (io.trino.sql.planner.plan.AggregationNode)2