You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "bharos (via GitHub)" <gi...@apache.org> on 2026/06/16 20:21:25 UTC

[I] [FEATURE] Add Iceberg sort maintenance strategy (end-to-end policy + strategy handler) [gravitino]

bharos opened a new issue, #11699:
URL: https://github.com/apache/gravitino/issues/11699

   ### Describe the feature
   
   Add end-to-end support for a **sort** maintenance strategy for Iceberg tables in the Table Maintenance Service (Optimizer), so a table can be automatically rewritten into a sorted (or z-ordered) data file layout based on a policy — analogous to the existing `system_iceberg_compaction` strategy.
   
   The execution layer already exists: the built-in `builtin-iceberg-rewrite-data-files` job (`IcebergRewriteDataFilesJob`) already supports `--strategy sort` and `--sort-order`. What is missing is the **policy + strategy-recommendation layer** that decides *when* a table should be sorted and emits the corresponding job.
   
   ### Motivation
   
   Sorting (and z-ordering) data files significantly improves query performance via better data skipping and file pruning, especially for high-cardinality filter columns. Today the optimizer only has a compaction (`binpack`) strategy (`CompactionStrategyHandler` / `system_iceberg_compaction`); there is no way to express "keep this table sorted by columns X, Y" as a managed policy and have the optimizer schedule it.
   
   This complements the in-flight expire-snapshots (#11194), remove-orphan-files (#11195), and rewrite-manifests (#11196) work under umbrella #8864, reusing the same strategy → job design pattern established in the expire-snapshots design doc (#11206).
   
   ### Describe the solution
   
   Following the existing compaction flow and the design pattern in #11206:
   
   1. **Policy content** — add `IcebergSortContent` (similar to `IcebergDataCompactionContent`) with: sort order (list of `{column, direction, nullOrdering}`), sort `strategy` (`sort` | `zorder`), optional `where` filter, and rewrite options (e.g. `target-file-size-bytes`, `min-input-files`).
   2. **Policy type** — add `system_iceberg_sort` to `Policy.BuiltInType` and the matching `PolicyContentDTO` / `PolicyDTO` JSON subtypes (mirroring `system_iceberg_compaction`).
   3. **Strategy handler** — add `SortStrategyHandler extends BaseExpressionStrategyHandler` (mirroring `CompactionStrategyHandler`), emitting a `JobExecutionContext` that invokes `builtin-iceberg-rewrite-data-files` with `strategy=sort` and the configured `sort-order`. Register it in `GravitinoStrategyProvider`.
   4. **Reuse** the existing `IcebergRewriteDataFilesJob` — no new job class is needed.
   5. Unit tests for the policy content (serde), the strategy handler (recommendation logic), and the job-options mapping, consistent with the existing compaction / expire-snapshots test coverage.
   
   ### Additional context
   
   - Umbrella: #8864 (built-in jobs for table maintenance)
   - Sibling strategies: #11194 (expire-snapshots), #11195 (remove-orphan-files), #11196 (rewrite-manifests)
   - Design pattern reference: #11206 (expire-snapshots end-to-end design doc)
   - Trino-side `rewrite_data_files` (incl. sort) procedure delegation already merged in #10500
   
   I'd like to work on this.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [FEATURE] Add Iceberg sort maintenance strategy (end-to-end policy + strategy handler) [gravitino]

Posted by "lasdf1234 (via GitHub) via commits" <co...@gravitino.apache.org>.
lasdf1234 commented on issue #11699:
URL: https://github.com/apache/gravitino/issues/11699#issuecomment-6758213360

   Thanks for the proposal.
   
   **This looks already implemented** on current `main`, without adding a separate `system_iceberg_sort` built-in type.
   
   ### How it was implemented
   
   Sort / z-order rewrite is folded into the existing **`system_iceberg_compaction`** policy (`IcebergDataCompactionContent`) via two content fields:
   
   - `rewriteStrategy`: `binpack` (default) or `sort`
   - `sortOrder`: required when `rewriteStrategy` is `sort` (e.g. `zorder(c1,c2)` or a sort-order expression); must be empty for `binpack`
   
   Wiring:
   
   1. Policy content validates the pair and puts `rewriteStrategy` / `sortOrder` into strategy `rules`.
   2. `CompactionStrategyHandler` reads those rules and builds `CompactionJobContext`.
   3. `GravitinoCompactionJobAdapter` maps them to the existing `builtin-iceberg-rewrite-data-files` job as Iceberg procedure args `strategy` / `sort_order`.
   
   So TMS can already schedule sorted rewrites with the same policy type + handler + job path as binpack compaction; no new `Policy.BuiltInType`, `SortStrategyHandler`, or job class is required for the original end-to-end ask.
   
   Landed in: https://github.com/apache/gravitino/pull/13727 (`[#13726] feat(policy): Support Iceberg rewrite strategy and sort order`).
   
   ### Example shape
   
   ```json
   {
     "policyType": "system_iceberg_compaction",
     "content": {
       "rewriteStrategy": "sort",
       "sortOrder": "zorder(c1,c2)",
       "rewriteOptions": {
         "min-input-files": "5"
       }
     }
   }
   ```
   
   ### Remaining gap (optional follow-up)
   
   Trigger / score expressions are still the compaction MSE / delete-file ones, not a dedicated “table is unsorted” signal. If we later want sort-specific recommendation semantics or a structured sort-order schema, that can be a smaller follow-up — but a separate `system_iceberg_sort` policy type does not seem necessary now.
   
   Suggest closing this issue as completed by #13727 (unless we want to keep it open only for sort-specific triggers/docs).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] [FEATURE] Add Iceberg sort maintenance strategy (end-to-end policy + strategy handler) [gravitino]

Posted by "lasdf1234 (via GitHub) via commits" <co...@gravitino.apache.org>.
lasdf1234 closed issue #11699: [FEATURE] Add Iceberg sort maintenance strategy (end-to-end policy + strategy handler)
URL: https://github.com/apache/gravitino/issues/11699


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org