Parquet: Fix column pruning for deeply nested fields
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.
I am not sure whether the use of originalField even when field is present is intentional behavior or a bug.
Following can be the issues related to this: https://github.com/apache/iceberg/issues/12428 https://github.com/apache/iceberg/issues/11617
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.
@amogh-jahagirdar Can you please take a look? Thanks.
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.
Can someone please take a look?
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.
Commenting to keep it alive.
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.
Commenting to keep it alive.
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.
@amogh-jahagirdar and @rdblue Can you take a look at PR again? Thanks.
@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.
@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?
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
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.
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
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
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.