Skip to content

Disabling loading consolidated Parquet _metadata #8030

Closed

Description

@jrbourbeau

For large Parquet datasets, loading the consolidated _metadata file, especially when it's a remote file, can be quite slow. We should consider adding an flag to optionally disable reading _metadata. Initially I thought setting gather_statistics=False would do this, but that turned out to not be the case (at least for the pyarrow-dataset and fastparquet engines)

cc @rjzamora in case you have thoughts on this topic

Activity

  1. rjzamora commented on Aug 13, 2021

    @rjzamora
    Member

    I agree that we should make it possible to avoid reading _metadata if there are fundamental limits in pyarrow for parsing the file.

    Other (somewhat-related) thoughts...

    I also think we should try to decentralize the read_parquet "planning" stage a bit. Note that I am working on a (second) refactor of the read_orc API in #8004, where I am breaking up the typical "read_metadata" stage, and I am getting the feeling that we need something very similar for parquet. More specifically, I think the "planning stage" of read_parquet should follow three stages:

    Stage 1: Get general dataset information. In this stage, we use pyarrow/fastparquet to populate a dictionary of general dataset information. The engine can use the _metadata file by default, but we should also make it possible to ignore this file if desired. Note that this stage should be "fast," so it should not dig into the data or file statistics.

    Stage 2: Construct output meta. Once we have general dataset information, we should be able to construct the meta without reading in any data, parsing parquet metadata/statistics, or constructing list of output partitions. Calculating the meta separately and early like this should also benefit the high-level expression plans discussed in #7933.

    Stage 3: Construct an output-partition plan. This is the stage where the heavy lifting is done, because we need to construct a list of path/row-group-range combinations for every output partition. In the current arrow engine, we effectively start this process by constructing a global "parquet metadata" object. When _metadata is not present, we can do this in parallel on the workers, but we always end up processing the global metadata on the client. This is because we rely on "shared"/"core" Dask logic to process the statistics, apply filters, and calculate divisions. However, if we move the stats/filtering/divisions responsibility onto the engine, the entire output-partition plan process can be parallelized pretty easily. Overall, I am vaguely suggesting that we bite the bullet and move the statistics-related logic into the engine. The engine implementations can still call shared utilities.

  2. jorisvandenbossche commented on Aug 13, 2021

    @jorisvandenbossche
    Member

    Stage 1: Get general dataset information. ... The engine can use the _metadata file by default, but we should also make it possible to ignore this file if desired. Note that this stage should be "fast," so it should not dig into the data or file statistics.

    I suppose the idea is that the meta can be constructed exclusively with information gathered here?
    I am wondering how you can do that with the current parquet datasets written by dask without either parsing a metadata file or either reading one single parquet data file + doing a filesystem scan (which can also be costly).

    For example to discover the partitioning (know which fields need to be added to the schema as partition columns), you need to know something about the directory structure? (which can either be read from the metadata file, or either requires a filesystem scan, with the current information stored in the dataset?)

  3. rjzamora commented on Aug 13, 2021

    @rjzamora
    Member

    Stage 1: Get general dataset information. ... The engine can use the _metadata file by default, but we should also make it possible to ignore this file if desired. Note that this stage should be "fast," so it should not dig into the data or file statistics.

    I suppose the idea is that the meta can be constructed exclusively with information gathered here?
    I am wondering how you can do that with the current parquet datasets written by dask without either parsing a metadata file or either reading one single parquet data file + doing a filesystem scan (which can also be costly).

    For example to discover the partitioning (know which fields need to be added to the schema as partition columns), you need to know something about the directory structure? (which can either be read from the metadata file, or either requires a filesystem scan, with the current information stored in the dataset?)

    You are 100% correct - This step cannot always be "fast", and I am still unsure of the best way to handle the case where we don't have a _metadata file, or that _metadata file is too large. What I do know is that we will want to be able to calculate the DataFrame._meta before starting the build the graph (gather/process parts/statistics), because we may use the high-level expressions for predicate pushdown/column-projection after the metadata is first generated. When we can assume that the dataset is not hive/directory partitioned, this is easy - Otherwise, we do need to do some up-front work to capture the correct metadata.

  4. mrocklin commented on Aug 13, 2021

    @mrocklin
    Member
  5. rjzamora commented on Aug 13, 2021

    @rjzamora
    Member

    We can probably read the head of the first row group and get the _meta
    information happily

    Yes - This will do the trick in most cases, but it will not capture directory-partitioned columns.

  6. iameskild commented on Aug 16, 2021

    @iameskild

    Hi folks, this might the same issue I'm currently experiencing, here is the error message I see when we call read_parquet (spatialpandas, using pyarrow v0.3.0):

    ddf_packed = ddf.pack_partitions_to_parquet(
      File "/opt/conda/envs/datum/lib/python3.8/site-packages/spatialpandas/dask.py", line 530, in pack_partitions_to_parquet
        return read_parquet_dask(
      File "/opt/conda/envs/datum/lib/python3.8/site-packages/spatialpandas/io/parquet.py", line 321, in read_parquet_dask
        result = _perform_read_parquet_dask(
      File "/opt/conda/envs/datum/lib/python3.8/site-packages/spatialpandas/io/parquet.py", line 421, in _perform_read_parquet_dask
        meta = dd_read_parquet(
      File "/opt/conda/envs/datum/lib/python3.8/site-packages/dask/dataframe/io/parquet/core.py", line 313, in read_parquet
        read_metadata_result = engine.read_metadata(
      File "/opt/conda/envs/datum/lib/python3.8/site-packages/dask/dataframe/io/parquet/arrow.py", line 537, in read_metadata
        ) = cls._gather_metadata(
      File "/opt/conda/envs/datum/lib/python3.8/site-packages/dask/dataframe/io/parquet/arrow.py", line 1035, in _gather_metadata
        ds = pa_ds.parquet_dataset(
      File "/opt/conda/envs/datum/lib/python3.8/site-packages/pyarrow/dataset.py", line 457, in parquet_dataset
        factory = ParquetDatasetFactory(
      File "pyarrow/_dataset.pyx", line 2043, in pyarrow._dataset.ParquetDatasetFactory.__init__
      File "pyarrow/error.pxi", line 122, in pyarrow.lib.pyarrow_internal_check_status
      File "pyarrow/error.pxi", line 84, in pyarrow.lib.check_status
    pyarrow.lib.ArrowInvalid: Extracting file path from RowGroup failed. The column chunks' file paths should be set, but got an empty file path.

    I recently upgraded to 2021.8.0 and got this error. After reverting back to 2021.7.2 the issue seems to have gone away. I see there is a PR 8034 open for this already but if an extra set of hands are needed, I'm happy to contribute. I will try to test the changes in PR 8034 to see if they fix my issue as well.
    Thanks for all the great work!

  7. mrocklin commented on Aug 17, 2021

    @mrocklin
    Member

    Stage 3: Construct an output-partition plan. This is the stage where the heavy lifting is done, because we need to construct a list of path/row-group-range combinations for every output partition. In the current arrow engine, we effectively start this process by constructing a global "parquet metadata" object. When _metadata is not present, we can do this in parallel on the workers, but we always end up processing the global metadata on the client. This is because we rely on "shared"/"core" Dask logic to process the statistics, apply filters, and calculate divisions. However, if we move the stats/filtering/divisions responsibility onto the engine, the entire output-partition plan process can be parallelized pretty easily. Overall, I am vaguely suggesting that we bite the bullet and move the statistics-related logic into the engine. The engine implementations can still call shared utilities.

    In general I support parallelizing metadata harvesting and construction. FWIW I think that Spark also does this (there appears to be a small compute period when they read a dataset).

    I'm curious about moving statistics functionality out of core. My current sense is that the remote-vs-local choice doesn't necessarily have to trigger a change of responsibility from core code to engine code. Is this understanding correct?

  8. jorisvandenbossche commented on Aug 17, 2021

    @jorisvandenbossche
    Member

    @iameskild that doesn't seem directly related. It is an error coming from parsing the _metadata file, and so having an option to not use that file (what this issue is about) would also help for your case as a workaround. But the fact that you get an error reading this file should have some cause / is a bug (for which I would recommend opening a separate issue).

  9. rjzamora commented on Aug 17, 2021

    @rjzamora
    Member

    I'm curious about moving statistics functionality out of core. My current sense is that the remote-vs-local choice doesn't necessarily have to trigger a change of responsibility from core code to engine code. Is this understanding correct?

    Yes. Your understanding is correct - but the exact separation between “core” and “engine” logic already varies a bit among engine implementation.

    Right now, the read_parquet logic starts by asking the engine to read and process the dataset and all relevant parquet metadata (in engine.read_metadata). This classmethod is expected to produce the output meta, a list of information needed to produce each output partition (parts), and a corresponding list of statistics (statistics). The engine is already free to use compute within this class method to compile parts/statistics remotely. The "pyarrow-legacy" engine does parallelize the harvesting/construction of a global parquet-metadata object when the _metadata file is missing, but the construction of parts/statistics still occurs on the client.

    It wouldn't be a significant change to implement parallel-construction of parts/statistics. As you suggested, it does not require any official "change of responsibility" from core code to engine code. However, the current separation of "responsibilities" requires that we follow up the read_metadata call with a second (optional) pass over the parts/statistics (on the client) to perform filtering, and then a third (optional) pass to perform part/file aggregation. We could certainly make the filtering logic remote without making it the responsibility of the engine, or refactor things so that "core" filtering is done in parallel. However, the "core" filtering pass is already being skipped by "pyarrow-dataset," because the row-groups/partitions are already filtered during dataset-fragment discovery.

    Therefore, my general suggestion here is that we may want to stop "pretending" like filtering is "core" logic when it already isn’t. We can maintain general/shared filtering utilities, but pushing the official responsibility into the engine actually feels like an easier-to-maintain solution to me.

  10. jrbourbeau commented on Aug 24, 2021

    @jrbourbeau
    MemberAuthor

    Closing this issue as an ignore_metadata_file option was added in #8034 and @rjzamora opened #8058 to discuss improving metadata processing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions