You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by "atognolas (via GitHub)" <gi...@apache.org> on 2026/06/29 17:31:00 UTC

[PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

atognolas opened a new pull request, #39158:
URL: https://github.com/apache/beam/pull/39158

   ## Summary
   - Modify `AppendFilesToTables.appendDataFiles()` to group data files by partition path and write one manifest per partition using `appendManifest()`
   - The commit remains atomic (single `AppendFiles` operation) while producing partition-aligned manifests
   - This enables manifest-level partition pruning in query engines (BigQuery, Trino) without a post-write `rewriteManifests` step
   
   ## Motivation
   When all files share a single partition spec, `appendDataFiles()` currently uses `appendFile()` which places everything into one manifest. With hundreds of partitions, query engines must scan all file entries in the manifest even for single-partition queries.
   
   Measured on a 400-partition table with 99-column schema:
   - Single manifest: **14s** BQ slot time
   - 400 partition-aligned manifests: **2.86s** BQ slot time (**5× improvement**)
   
   ## Notes
   Iceberg's `commit.manifest-merge.enabled` (default `true`) will merge these manifests back into fewer manifests. Users who want to preserve partition alignment should set this to `false` or run periodic `rewriteManifests`.
   
   ## Test plan
   - [ ] Existing `AppendFilesToTablesTest` passes
   - [ ] Run IcebergIO integration tests
   - [ ] Verify manifest count matches partition count via Iceberg metadata inspection
   - [ ] Verify query engines benefit from manifest-level pruning
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)


-- 
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: github-unsubscribe@beam.apache.org

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


Re: [PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed pull request #39158: [IcebergIO] Use partition-aligned manifests for faster query pruning
URL: https://github.com/apache/beam/pull/39158


-- 
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: github-unsubscribe@beam.apache.org

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


Re: [PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

Posted by "derrickaw (via GitHub)" <gi...@apache.org>.
derrickaw commented on PR #39158:
URL: https://github.com/apache/beam/pull/39158#issuecomment-4916335833

   Hi @atognolas, please fix the spotless issue. Thanks!


-- 
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: github-unsubscribe@beam.apache.org

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


Re: [PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39158:
URL: https://github.com/apache/beam/pull/39158#issuecomment-5664180180

   This pull request has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time.


-- 
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: github-unsubscribe@beam.apache.org

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


Re: [PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39158:
URL: https://github.com/apache/beam/pull/39158#issuecomment-5570841294

   This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 1 week if no further activity occurs. If you think that’s incorrect or this pull request requires a review, please simply write any comment. If closed, you can revive the PR at any time and @mention a reviewer or discuss it on the dev@beam.apache.org list. Thank you for your contributions.


-- 
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: github-unsubscribe@beam.apache.org

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


Re: [PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #39158:
URL: https://github.com/apache/beam/pull/39158#issuecomment-4836323801

   Checks are failing. Will not request review until checks are succeeding. If you'd like to override that behavior, comment `assign set of reviewers`


-- 
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: github-unsubscribe@beam.apache.org

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


Re: [PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

Posted by "atognolas (via GitHub)" <gi...@apache.org>.
atognolas commented on PR #39158:
URL: https://github.com/apache/beam/pull/39158#issuecomment-4835313575

   @ahmedabu98 — Would you mind reviewing this? These are a set of IcebergIO fixes validated on production-scale benchmarks (39M users, 400 partitions, 99-column schema). The four PRs are independent and can be reviewed/merged in any order.


-- 
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: github-unsubscribe@beam.apache.org

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


Re: [PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #39158:
URL: https://github.com/apache/beam/pull/39158#issuecomment-4835290497

   ## Summary of Changes
   
   Hello, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
   
   This pull request optimizes Iceberg table writes by implementing partition-aligned manifest generation. By grouping data files by their partition path before committing, the system allows downstream query engines to perform more efficient partition pruning, reducing scan times and improving overall query performance without sacrificing commit atomicity.
   
   ### Highlights
   
   * **Partition-Aligned Manifests**: Modified the Iceberg IO append process to group data files by partition path, creating individual manifests for each partition.
   * **Performance Optimization**: Enables manifest-level partition pruning in query engines like BigQuery and Trino, resulting in significant query performance improvements.
   * **Atomic Commits**: Maintains atomicity by performing a single AppendFiles operation, ensuring data integrity while improving metadata structure.
   
   <details>
   <summary><b>New Features</b></summary>
   
   🧠 You can now enable **Memory** (public preview) to help **Gemini Code Assist** learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. **Click [here](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
   </details>
   
   <details>
   <summary><b>Using Gemini Code Assist</b></summary>
   <br>
   
   The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
   
   <b>Invoking Gemini</b>
   
   You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
   
   Feature | Command | Description
   --- | --- | ---
   Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
   Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
   Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
   Help | `/gemini help` | Displays a list of available commands.
   
   <b>Customization</b>
   
   To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
   
   <b>Limitations & Feedback</b>
   
   Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up [here](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
   </details>
   
   
   [^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
   


-- 
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: github-unsubscribe@beam.apache.org

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


Re: [PR] [IcebergIO] Use partition-aligned manifests for faster query pruning [beam]

Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #39158:
URL: https://github.com/apache/beam/pull/39158#discussion_r3493582486


##########
sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/AppendFilesToTables.java:
##########
@@ -152,15 +152,38 @@ public void processElement(
           KV.of(element.getKey(), SnapshotInfo.fromSnapshot(snapshot)), window.maxTimestamp());
     }
 
-    // This works only when all files are using the same partition spec.
-    private void appendDataFiles(Table table, Iterable<FileWriteResult> fileWriteResults) {
-      AppendFiles update = table.newAppend();
+    private void appendDataFiles(Table table, Iterable<FileWriteResult> fileWriteResults)
+        throws IOException {
+      Map<Integer, PartitionSpec> specs = table.specs();
+      FileIO io = table.io();
+      String uuid = UUID.randomUUID().toString();
+
+      Map<String, List<DataFile>> byPartition = new HashMap<>();
       for (FileWriteResult result : fileWriteResults) {
-        DataFile dataFile = result.getDataFile(table.specs());
-        update.appendFile(dataFile);
+        DataFile dataFile = result.getDataFile(specs);
+        String partitionPath = result.getSerializableDataFile().getPartitionPath();
+        byPartition.computeIfAbsent(partitionPath, k -> new ArrayList<>()).add(dataFile);
         committedDataFileByteSize.update(dataFile.fileSizeInBytes());
         committedDataFileRecordCount.update(dataFile.recordCount());
       }
+
+      AppendFiles update = table.newAppend();
+      int manifestIdx = 0;
+      for (Map.Entry<String, List<DataFile>> entry : byPartition.entrySet()) {
+        List<DataFile> files = entry.getValue();
+        PartitionSpec spec =
+            files.get(0).specId() >= 0
+                ? Preconditions.checkStateNotNull(specs.get(files.get(0).specId()))
+                : table.spec();
+        ManifestWriter<DataFile> writer =
+            createManifestWriter(
+                table.location(), uuid + "-" + manifestIdx++, spec, io);
+        for (DataFile file : files) {
+          writer.add(file);
+        }
+        writer.close();
+        update.appendManifest(writer.toManifestFile());

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   There are two issues here:
   1. `createManifestWriter` is not a standard Iceberg API and is not defined in this class, which will cause a compilation error.
   2. The `ManifestWriter` is not closed within a `try-finally` or `try-with-resources` block. If an exception occurs while adding files, the writer will leak resources.
   
   We can resolve both issues by using the standard `ManifestFiles.write` API from Iceberg and wrapping the write loop in a `try-finally` block to ensure the writer is closed properly before retrieving the manifest file.
   
   Note: You will need to import `org.apache.iceberg.ManifestFiles` and `org.apache.iceberg.io.OutputFile`.
   
   ```java
           OutputFile outputFile = io.newOutputFile(
               table.location() + "/metadata/" + uuid + "-" + manifestIdx++ + ".avro");
           ManifestWriter<DataFile> writer = ManifestFiles.write(spec, outputFile);
           try {
             for (DataFile file : files) {
               writer.add(file);
             }
           } finally {
             writer.close();
           }
           update.appendManifest(writer.toManifestFile());
   ```



-- 
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: github-unsubscribe@beam.apache.org

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