class OptimizeStatementPlanner
Plans OPTIMIZE as one statement per bounded group of partitions, so no single query ever opens more writers than Trinoβs Iceberg connector default (iceberg.max-partitions-per-writer = 100) allows.
A table that is badly behind on maintenance can accumulate far more identity partitions than any static limit - a table that missed 100 daily partitions could just as easily miss 1000. Batching sidesteps the ceiling entirely: each statement touches only a bounded subset of the partition column, so it always completes instead of failing outright on the tables that need the maintenance most.
Batching only applies when it is safe to scope by partition: * the step is an OPTIMIZE * the operator did not already set a WHERE predicate (that would conflict) * the table has a single identity-transformed partition column In every other case the planner returns the single, unbatched statement, so behaviour is unchanged.
Constants
- DEFAULT_PARTITIONS_PER_QUERY
-
Safety margin below the connector default of 100 writers. Overridable per step via config.
Public Class Methods
# File app/services/optimize_statement_planner.rb, line 28 def initialize(table, step, runtime: TrinoRuntime) @table = table @step = step @runtime = runtime end
Creates the planner for a table and step.
@param table [IcebergTable] the target table @param step [MaintenanceStep] the step describing the operation @param runtime [Object] the Trino runtime used to discover partition values
Public Instance Methods
Source
# File app/services/optimize_statement_planner.rb, line 38 def statements(execution_id:) return [ single_statement ] unless batchable? batched_statements(execution_id) end
The OPTIMIZE statements to run for this table/step, in order.
@param execution_id [Integer] the execution id for header tagging @return [Array<String>] one or more ALTER TABLE β¦ EXECUTE statements