Skip to content

Custom sort key for dataframe.read_parquet with multiple paths as input #10045

Open

Description

@alexgorban

dask.dataframe.read_parquet accepts a list of paths as input. It uses natural_sort_key under the hood to sort the paths in several places. In my case parquet files are not in the natural order and I'd like to sort them outside and keep the same order inside the read_parquet, so I do monkey patching like this to make it work:

with (mock.patch.object(dask.dataframe.io.parquet.core, 'natural_sort_key', new=lambda p: p),
      mock.patch.object(dask.dataframe.io.parquet.utils, 'natural_sort_key', new=lambda p: p)):    
    return dd.read_parquet(paths, index='index', calculate_divisions=True)

It would be great if there was a parameter to control the sort key (disable natural_sort_key or provide my own).

Activity

  1. added
    needs triage
    on Mar 10, 2023
  2. jrbourbeau commented on Mar 13, 2023

    @jrbourbeau
    Member

    Thanks for the issue @alexgorban. Out of curiosity, how are your files being produced?

    @rjzamora does it make sense to use the given file order if users provide a list of paths?

  3. rjzamora commented on Mar 13, 2023

    @rjzamora
    Member

    does it make sense to use the given file order if users provide a list of paths?

    Yes. This has come up before (I’ll need to find the original issue and link later). It may be a bit easier to make it optional to sort a user-provided path list now.

  4. alexgorban commented on Mar 29, 2023

    @alexgorban
    Author

    Out of curiosity, how are your files being produced?

    Files are created using Apache Arrow with filenames sorted alphabetically (pyarrow.Table.sort_by doesn't support custom key functions) and have the following format: {hash}_{a}_{b}_{c}_{d}.parquet, ex. 10023947602400723454_1120_000_1140_000. Their order is important because they have a sorted index column and their metadata stored with this order. Full details about the dataset format can be found here https://github.com/waymo-research/waymo-open-dataset/blob/master/tutorial/tutorial_v2.ipynb.

    Thanks a lot for considering implementing this feature!

  5. rjzamora commented on Mar 29, 2023

    @rjzamora
    Member

    Thanks for explaining @alexgorban! Please feel free to provide feedback on the proposed solution in #10061. The current plan is to simply preserve the order of a user-provided path list, but to use natural sorting when a directory or glob-pattern is specified.

  6. removed
    needs triage
    on Apr 3, 2023
  7. added
    needs attention
    on Mar 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dataframeioneeds attentionparquet

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions