iceberg icon indicating copy to clipboard operation
iceberg copied to clipboard

Parquet: Fix column pruning for deeply nested fields

Open sriharshaj opened this issue 1 year ago • 19 comments

This PR addresses a performance issue related to column pruning in nested structures when reading Iceberg tables from Parquet files.

Issue

In the current implementation of PruneColumns#struct, we are including the entire parent column in the read schema, even when only a subset of nested fields is required. This occurs because:

The originalField is being added to the filteredFields regardless of whether the passed filtered field is already present. This behavior causes the entire parent column to be read if any leaf node within the nested structure is selected in a query.

Proposed solution

I updated the code to use passed filtered field when present, and use originalField when passed filtered field is null.

sriharshaj avatar Mar 25 '25 00:03 sriharshaj

I am not sure whether the use of originalField even when field is present is intentional behavior or a bug.

sriharshaj avatar Mar 25 '25 02:03 sriharshaj

Following can be the issues related to this: https://github.com/apache/iceberg/issues/12428 https://github.com/apache/iceberg/issues/11617

sriharshaj avatar Mar 25 '25 02:03 sriharshaj

This pull request has been marked as stale due to 30 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 [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Apr 26 '25 00:04 github-actions[bot]

@amogh-jahagirdar Can you please take a look? Thanks.

sriharshaj avatar Apr 28 '25 18:04 sriharshaj

This pull request has been marked as stale due to 30 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 [email protected] list. Thank you for your contributions.

github-actions[bot] avatar May 29 '25 00:05 github-actions[bot]

Can someone please take a look?

sriharshaj avatar Jun 02 '25 20:06 sriharshaj

This pull request has been marked as stale due to 30 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 [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Jul 03 '25 00:07 github-actions[bot]

Commenting to keep it alive.

sriharshaj avatar Jul 03 '25 17:07 sriharshaj

This pull request has been marked as stale due to 30 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 [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Aug 03 '25 00:08 github-actions[bot]

Commenting to keep it alive.

sriharshaj avatar Aug 05 '25 18:08 sriharshaj

This pull request has been marked as stale due to 30 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 [email protected] list. Thank you for your contributions.

github-actions[bot] avatar Oct 17 '25 00:10 github-actions[bot]

@amogh-jahagirdar and @rdblue Can you take a look at PR again? Thanks.

sriharshaj avatar Oct 21 '25 16:10 sriharshaj

@sriharshaj Hi, if I may ask question of understanding: I know that there is large code base in spark itself for column pruning, and now you are changing internal to iceberg functionality that is related to same area. What principle defines separation between two(spark vs iceberg)? How have you decided that you need to improve pruning of columns in iceberg itself and not in spark(e.g.)? ps: I'm trying to work on supporting pruning of nested fields inside arrays of structs and personally I'm focusing on spark codebase.

IgorBerman avatar Nov 09 '25 13:11 IgorBerman

@sriharshaj Hi, if I may ask question of understanding: I know that there is large code base in spark itself for column pruning, and now you are changing internal to iceberg functionality that is related to same area. What principle defines separation between two(spark vs iceberg)? How have you decided that you need to improve pruning of columns in iceberg itself and not in spark(e.g.)? ps: I'm trying to work on supporting pruning of nested fields inside arrays of structs and personally I'm focusing on spark codebase.

Hey @IgorBerman, My understanding is that based on the Spark query or DF logic, Iceberg decides which columns need to be read from the Parquet data. So, I believe the change should happen at the Iceberg level. WDYT?

sriharshaj avatar Dec 05 '25 21:12 sriharshaj

I was checking this mechanism lately and I think there are 2 parts in the story. First, Spark computes "needed" schema and can prune schema by different optimization rules. Then it passes this schema to Iceberg level and then there is additional PruneColumns logic that Iceberg doing, in which Iceberg trying to take file schema and needed schema(computed by spark) and decide what columns from parquet(e.g.) to read(by judging if needed schema is sound with file schema etc). I.e. IO pruning depends on the later logic, but it takes into account what Spark computed

IgorBerman avatar Dec 05 '25 21:12 IgorBerman

I was checking this mechanism lately and I think there are 2 parts in the story. First, Spark computes "needed" schema and can prune schema by different optimization rules. Then it passes this schema to Iceberg level and then there is additional PruneColumns logic that Iceberg doing, in which Iceberg trying to take file schema and needed schema(computed by spark) and decide what columns from parquet(e.g.) to read(by judging if needed schema is sound with file schema etc). I.e. IO pruning depends on the later logic, but it takes into account what Spark computed

Yeah, that sounds right. Optimizations on the Spark side may not be applied when reading the data from Parquet.

sriharshaj avatar Dec 05 '25 21:12 sriharshaj

ok, I was a bit blind to what you are doing and did something similar(after you opened your PR and actually I commented on it before) due to our usecase (where we want pruning of columns inside structs inside arrays https://github.com/apache/iceberg/pull/14744). I needed to support cases of pruning not only due to structs chains but also for struct<array<struct<array>> cases I'll try to test your fix with my tests to see if it gives same results

IgorBerman avatar Dec 06 '25 08:12 IgorBerman

ok, verified and your fix passes also my tests containing nested arrays of structs can you please take few tests from https://github.com/apache/iceberg/pull/14744/files#diff-1bbe7597b597eead2808831e8b9c9ac16dc8a2a912670cc8a78f5b09584b4468 then I'll close my PR as duplicate

IgorBerman avatar Dec 06 '25 08:12 IgorBerman

ok, verified and your fix passes also my tests containing nested arrays of structs can you please take few tests from https://github.com/apache/iceberg/pull/14744/files#diff-1bbe7597b597eead2808831e8b9c9ac16dc8a2a912670cc8a78f5b09584b4468 then I'll close my PR as duplicate

Thanks for testing. Sure, I will add more of them.

sriharshaj avatar Dec 08 '25 18:12 sriharshaj