Skip to content

Improve parquet read implementation and multiple column read performance - #4906

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
e-kayrakli:parquet-multicol
Sep 23, 2025
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
e-kayrakli:parquet-multicol

Conversation

@e-kayrakli

@e-kayrakli e-kayrakli commented Sep 15, 2025 •

Copy link
Copy Markdown
Contributor

This PR has two main goals:

  • improve the performance of parquet reads, particularly when all the columns of the file(s) are read
  • start improving the implementation on C++ and Chapel sides

User-facing Change:

  • This PR deprecates has_non_float_nulls: Bool, in favor of null_handling: {"none", "only floats", "all"}
    • We need a 3-way switch to enable fast floating point reads when the user knows their data contains no nulls. Old boolean-based switch cannot capture that. The new null_handling formal to read_parquet defaults to "only floats" to match with the older behavior.
    • Right now, null_handling is effective only when reading all columns. has_non_float_nulls is used when only a subset of columns are read. It is a TODO to phase out has_non_float_nulls, among other things.

Why do we need a new implementation for performance?

Parquet is a columnar format. However, that doesn't mean that all data for a column is stored consecutively. For large files (512M by default, I think), Parquet files will be written in consecutive row groups instead of storing large columns one after another. Therefore, a more natural way of reading a parquet file is to read row-group-by-row-group while going through all the columns. Considering reading all columns as a common use case, it is important to read parquet files in that way for performance. Right now, if you have 10 columns, you open and read the entire file(s) 10 times, one for each column, skipping 9 columns during each read.

A small optimization along the way

With the new null_handling control flag, we can also enable batch reads of floating point types where prior to this PR we were reading them one-by-one to be able to catch nulls. I think even with nulls at play, we should be able to do better than that, but that's a post-merge TODO.

Performance Improvements

This is using ~400GBs of data in 5 columns partitioned into 128 files, read by 16 locales:

main (s) branch (s) improvement (x)
min 11.43 7.60 1.50
max 22.58 14.96 1.51
ave 16.69 9.38 1.78

This is using ~30GBs of data in 1000 columns partitioned into 128 files, read by 16 locales:

master (s) branch (s) improvement (x)
min 335.97 9.02 37.24
max 335.97 15.64 21.48
ave 335.97 9.98 33.67

Implementation details:

  • If the user doesn't pass any dataset names to read_parquet, we read all columns. This PR makes that case take an entirely new codepath with no modifications to the subset-of-columns code path. I intend to remove this old code path in favor of the new one even for subset-of columns. That's a post-merge TODO.
  • This new code path introduces the following on the C++ side:
    • namespace akcpp on the C++ side. I want more code to live in this namespace going forward. Within that namespace:
    • struct AkReadColOp on the C++ side to represent type-agnostic information for reading a single column.
    • This type has a template read() function for reading a column with specific dynamic type
    • read() has some template specializations for handling some specific cases like short integrals that are not represented on the Chapel side and need to be cast to bigger ones
    • The read() family of functions has a lot of code redundancy that I inherited from the earlier implementation. Refactoring those redundancies into helpers is an obvious TODO.
    • readAllCols function to handle the operation. This is the function that selects the correct read() instantiation based on the dynamic type.
  • This new code path introduces the following on the Chapel side:
    • readAllColsParquetMsg which is the main message handler here. The implementation is too much of a Frakenstein experiment where old style/structure is mixed with the new. Going forward, I want this function to be the general parquet read function, so it needs more improvements.
    • The implementation of this stores read metadata in pqReadColOp. This is deceptively similar to AkReadColOp. But it actually stores information for the whole read operation and it is not per-column. I want to consider whether we can have single metadata shared between C++ and Chapel.
    • This pqReadColOp determines whether we can read all columns at the same time based on the dynamic types of the columns. If we can't it will fall back to the old implementation. Currently that fallback is a bit rough as we call the message handler. I think that's a bad practice and the core logic of the read has to be available without the message handling. We'll need to reconcile the two different reads in any case, so that's part of post-merge TODOs.
    • I used this type to do column-per-column reads, too. That's the only change in the existing code path. I started off thinking that I can do all the refactoring in one go, but decided against it. Nevertheless, I left that part in. Currently that causes pqReadColOp to be more generic than I'd like. It will be fixed in the next refactor wave.
    • Simplified error location reporting
    • Several new small helpers and simplified helpers

Test Status:

  • local parquet unit testing
  • oversubscribed parquet unit testing

Post-Merge TODO

  • Refactor read() functions into having more helpers
    • Consider handling per-batch post-processing differently, maybe with functors.
  • use the akcpp::readAllCols function for reading subset of columns, too and remove the old read implementation completely. Similarly for readAllColsParquetMsg on Chapel side
    • Fall back to col-per-col read in a more graceful way
    • completely deprecate has_non_float_nulls
  • Can we read floating point columns with nulls in them in batches and process nulls differently?
  • Can we use a single metadata type for C++ and Chapel?
  • Use message registration attributes for Parquet message handlers
  • Short integer and float reads use a temporary buffer. We can get rid of that by reading into the larger Chapel buffer and spacing things out in reverse order.
  • Handle ARROWERROR and error messages populated by the C level better and more consistently
  • Remove strict_types argument from the Parquet interface #4925

Comment thread ServerModules.cfg Resolved
Comment thread Makefile Resolved
Comment thread ServerModules.cfg Resolved
Comment thread registration-config.json Resolved
Comment thread src/parquet/SharedEnums.h Resolved
Comment thread src/ParquetMsg.chpl Resolved
Comment thread src/parquet/ReadParquet.cpp Resolved
Comment thread src/parquet/ReadParquet.cpp Resolved
Comment thread src/parquet/ReadParquet.cpp Resolved
Comment thread src/parquet/ReadParquet.cpp Resolved
Comment thread src/parquet/UtilParquet.cpp Resolved
@e-kayrakli

Copy link
Copy Markdown
Contributor Author

Thanks, @ajpotts and @jabraham17

@ajpotts / @jabraham17 : I will revert the configuration files. I am keeping them as is to make my life easier testing the branch on different systems.

@jabraham17 : I resolved bunch of your comments with a new set of commits. Feel free to iterate through those to follow changes. Probably the first new commit is the most consequential one.

I left some discussions unresolved because I either need some more clarifications, or prefer to do the changes you request in a subsequent PR out of paranoia + principle to not make nitty-gritty stylistic changes in this PR where big chunks of code being moved around and introduced. Let me know if you want to argue for urgency of those changes.

One big item for me to try tomorrow is your suggestion to replace the symlink-based enum interop with... something more principled (I need to remember the idea by going through our Slack convo). But feel free to chime in on the unresolved discussions in the meantime.

@e-kayrakli

Copy link
Copy Markdown
Contributor Author

I will do my testing after rebasing on main.

@jabraham17

Copy link
Copy Markdown
Contributor

I left some discussions unresolved because I either need some more clarifications, or prefer to do the changes you request in a subsequent PR out of paranoia + principle to not make nitty-gritty stylistic changes in this PR where big chunks of code being moved around and introduced. Let me know if you want to argue for urgency of those changes.

I think many of my comments were about improving the quality of the code, both for developer readability and maintainability/future extensibility. I am perfectly happy with those comments being addressed in a future PR

Comment thread src/ParquetSharedEnums.chpl Resolved
Comment thread registration-config.json Resolved
Comment thread tests/pandas/io_test.py Resolved
Comment thread src/ParquetMsg.chpl Resolved
Comment thread src/ParquetMsg.chpl Resolved
Comment thread src/ParquetMsg.chpl Resolved
Comment thread src/parquet/ReadParquet.h Resolved

@ajpotts ajpotts left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before I can merge this we need to figure out why I can't compile this PR on my Ubuntu box.

@e-kayrakli
e-kayrakli force-pushed the parquet-multicol branch 2 times, most recently from 30c4b8c to c1065b2 Compare September 19, 2025 19:01
@ajpotts
ajpotts added this pull request to the merge queue Sep 23, 2025
Merged via the queue into Bears-R-Us:main with commit 673f80e Sep 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants