Skip to content

Parquet _metadata too large to parse #8027

Closed

Description

@jrbourbeau

I encountered the following error (the full traceback is further down):

OSError: Could not open Parquet input source 'oss-shared-scratch/timeseries.parquet/_metadata': Couldn't deserialize thrift: MaxMessageSize reached

when reading in a Parquet dataset on S3 with a large _metadata file. In this particular case the _metadata file was 676.5 MB. Based on the error message it looks like this _metadata file is too big for pyarrow to parse.

cc @jorisvandenbossche @rjzamora

Full traceback:
---------------------------------------------------------------------------
OSError                                   Traceback (most recent call last)
<timed exec> in <module>

~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/dask/dataframe/io/parquet/core.py in read_parquet(path, columns, filters, categories, index, storage_options, engine, gather_statistics, split_row_groups, read_from_paths, chunksize, aggregate_files, **kwargs)
    314         gather_statistics = True
    315 
--> 316     read_metadata_result = engine.read_metadata(
    317         fs,
    318         paths,

~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/dask/dataframe/io/parquet/arrow.py in read_metadata(cls, fs, paths, categories, index, gather_statistics, filters, split_row_groups, read_from_paths, chunksize, aggregate_files, **kwargs)
    540             split_row_groups,
    541             gather_statistics,
--> 542         ) = cls._gather_metadata(
    543             paths,
    544             fs,

~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/dask/dataframe/io/parquet/arrow.py in _gather_metadata(cls, paths, fs, split_row_groups, gather_statistics, filters, index, dataset_kwargs)
   1038             if fs.exists(meta_path):
   1039                 # Use _metadata file
-> 1040                 ds = pa_ds.parquet_dataset(
   1041                     meta_path,
   1042                     filesystem=fs,

~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/pyarrow/dataset.py in parquet_dataset(metadata_path, schema, filesystem, format, partitioning, partition_base_dir)
    492     )
    493 
--> 494     factory = ParquetDatasetFactory(
    495         metadata_path, filesystem, format, options=options)
    496     return factory.finish(schema)

~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/pyarrow/_dataset.pyx in pyarrow._dataset.ParquetDatasetFactory.__init__()

~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/pyarrow/error.pxi in pyarrow.lib.pyarrow_internal_check_status()

~/mambaforge/envs/coiled-jrbourbeau-parquet-demo/lib/python3.9/site-packages/pyarrow/error.pxi in pyarrow.lib.check_status()

OSError: Could not open Parquet input source 'oss-shared-scratch/timeseries.parquet/_metadata': Couldn't deserialize thrift: MaxMessageSize reached

Activity

  1. mrocklin commented on Aug 12, 2021

    @mrocklin
    Member

    Also, we should probably make it optional to even read this file. I think that in @jrbourbeau 's case this resulted in him downloading a 600MB file every time. We should consider a read_metadata_file=True keyword that can be set to False. Currently there is no way to turn this off.

  2. jrbourbeau commented on Aug 12, 2021

    @jrbourbeau
    MemberAuthor

    Thanks for the additional context @mrocklin. I was going to open a separate issue for that, but as it's also related to the large _metadata file, here is a good place for that discussion too.

    I should also point out that based on the description of gather_statistics

    gather_statistics : bool, default None
    Gather the statistics for each dataset partition. By default,
    this will only be done if the _metadata file is available. Otherwise,
    statistics will only be gathered if True, because the footer of
    every file will be parsed (which is very slow on some systems).

    FWIW I thought setting gather_statistics=False would result in us not reading the _metadata file, but that turned out to not be the case (at least for the pyarrow-dataset and fastparquet engines)

  3. mrocklin commented on Aug 12, 2021

    @mrocklin
    Member

    Separate issue sounds good to me.

  4. jrbourbeau commented on Aug 12, 2021

    @jrbourbeau
    MemberAuthor

    xref #8030

  5. jorisvandenbossche commented on Aug 13, 2021

    @jorisvandenbossche
    Member

    And the metadata file itself was produced by pyarrow? (or did it come from somewhere else?)

  6. mrocklin commented on Aug 17, 2021

    @mrocklin
    Member

    @jorisvandenbossche given @jrbourbeau 's comment in the meta-issue here #8031 I suspect that this was done with the pyarrow-dataset engine. James would know for sure though.

  7. jorisvandenbossche commented on Aug 17, 2021

    @jorisvandenbossche
    Member

    Would it be possible to put the offending file on a public bucket (or somewhere else publicly accessible)?
    And the code that was used to create the file, is this the code in #8031? (to have a reproducible code example)

  8. jrbourbeau commented on Aug 18, 2021

    @jrbourbeau
    MemberAuthor

    And the metadata file itself was produced by pyarrow? (or did it come from somewhere else?)

    Good question. I'm not sure certain as, IIRC, I was running into #7977 when using the pyarrow-dataaset engine, so I switched to fastparquet. I ended up deleting the _metadata file as a temporary workaround which, with hindsight, wasn't the wisest decision. I'll try to reproduce in a public bucket and will report back

  9. jrbourbeau commented on Aug 18, 2021

    @jrbourbeau
    MemberAuthor

    Indeed I ran into issues writing a large dataset using the pyarrow-dataset engine and switched to fastparquet (for writing). Below is the code snippet used the create the parquet dataset

    import coiled
    from dask.distributed import Client
    
    cluster = coiled.Cluster(
        name="parquet-demo",
        software="parquet-demo",
        n_workers=20,
        worker_memory="16 GiB",
    )
    client = Client(cluster)
    
    cluster.scale(200)
    client.wait_for_workers(150)
    
    import dask
    
    df = dask.datasets.timeseries(
        dtypes={str(i): int for i in range(1_000)},
        freq="1s",
        start="2000-01-01",
        end="2021-01-01",
    )
    
    storage_options={
        "config_kwargs": {"region_name": "us-east-1"},
    }
    
    df.to_parquet(
        "s3://james-scratch/timeseries-public.parquet",
        engine="fastparquet",
        storage_options=storage_options,
        write_metadata_file=True,
    )

    I'm able to reproduce the

    OSError: Could not open Parquet input source 'james-scratch/timeseries-public.parquet/_metadata': Couldn't deserialize thrift: MaxMessageSize reached
    

    error when attempting to read the dataset using the pyarrow-dataset engine:

    import dask.dataframe as dd
    
    # This is where the `OSError` is raised
    df = dd.read_parquet(
        "s3://james-scratch/timeseries-public.parquet",
        engine="pyarrow-dataset",
        storage_options=storage_options,
    )

    I'll make that bucket publicly accessible in AWS us-east-1 tomorrow 👍

    EDIT: s3://james-scratch/timeseries-public.parquet/_metadata should now be publicly accessible (let me know if it isn't)

  10. jorisvandenbossche commented on Aug 18, 2021

    @jorisvandenbossche
    Member

    @jrbourbeau thanks for the reproducer!

    I downloaded the file to check locally, and I can reproduce the error with pyarrow 4.0 and 5.0, but it does work with my local development install:

    In [1]: import pyarrow as pa
    
    In [2]: pa.__version__
    Out[2]: '5.0.0'
    
    In [3]: import pyarrow.dataset as ds
    
    In [4]: dataset = ds.parquet_dataset("james-metadata")
    ...
    OSError: Could not open Parquet input source 'james-metadata': Couldn't deserialize thrift: MaxMessageSize reached

    vs

    In [1]: import pyarrow as pa
    
    In [2]: pa.__version__
    Out[2]: '6.0.0.dev98+g973dbaea3.d20210818'
    
    In [3]: import pyarrow.dataset as ds
    
    In [4]: dataset = ds.parquet_dataset("james-metadata")
    
    In [5]: dataset.schema
    Out[5]: 
    timestamp: timestamp[ns]
    0: int64
    1: int64
    ...
    
    In [6]: dataset.files[0]
    Out[6]: 'part.0.parquet'
    
    In [7]: dataset.files[-1]
    Out[7]: 'part.7670.parquet

    Now, I don't really know what's the reason for this difference (I don't think it's "fixed", as it also fails with a nightly package). I am not very familiar with thrift, but there might be some config/build options that influence this.

  11. jorisvandenbossche commented on Aug 18, 2021

    @jorisvandenbossche
    Member

    OK, so indeed this is related to the thrift version. In my local development environment, I still had libthrift 0.13, with which it works fine as mentioned above. But the latest releases of pyarrow on conda-forge are build with libthrift 0.14. Creating a new local environment with thrift 0.14 and building master of pyarrow with that, I also get the error.

    It seems that Apache Thrift introduced a MaxMessageSize configuration option (https://github.com/apache/thrift/blob/master/doc/specs/thrift-tconfiguration.md#maxmessagesize) in version 0.14 (https://issues.apache.org/jira/browse/THRIFT-5237).

    Fastparquet uses the python bindings of thrift, and it seems that is still at version 0.13 and not yet updated to 0.14 (https://github.com/conda-forge/thrift-feedstock/). So I suppose this is the reason that the file could be created with the fastparquet engine.

    If you have an environment with Arrow built against libthrift 0.13, the file can be read fine. But, with conda-forge, the recent releases are built against 0.14, and you can only get pyarrow 3.0 or lower with libthrift=0.13.

    I opened https://issues.apache.org/jira/browse/ARROW-13655 on the Arrow side. I suppose we could expose this configuration option on the Arrow side (but that's not a short-term workaround).

  12. mrocklin commented on Aug 18, 2021

    @mrocklin
    Member
  13. Nogbit commented on Sep 3, 2021

    @Nogbit

    @jorisvandenbossche any idea on a workaround? I just ran into this myself with a 700MB metadata file using Dask with Pyarrow 5 to create and read the metadata. Now I can't read it with Dask in my cluster. I'm thinking a custom container with older versions etc, but that's a chore of course (using default image from the Dask helm chart right now).

  14. jrbourbeau commented on Sep 3, 2021

    @jrbourbeau
    MemberAuthor

    FYI, I think @jorisvandenbossche is on vacation for a few more days. The dask=2021.08.1 release added a ignore_metadata_file= keyword argument to read_parquet which can be used to bypass reading the global _metadata file altogether. That may be useful for working around the thrift MaxMessageSize issue

  15. Nogbit commented on Sep 3, 2021

    @Nogbit

    Fantastic, I will give that try

  16. Nogbit commented on Sep 3, 2021

    @Nogbit

    Not going too well. I have over 100K parquet files, that metadata file seems pretty essential. I run into this now #4701 as a df = dd.read_parquet() takes forever, with zero activity on the dashboard (workers sit there doing nothing). Looks like I might have to rebuild my parquet files with a different engine.

  17. jrbourbeau commented on Sep 3, 2021

    @jrbourbeau
    MemberAuthor

    Ah, I see. Could you try setting gather_statistics=False too then?

    Also wanted to point out that there is some ongoing work to improve reading parquet metadata in parallel over in #8072

  18. Nogbit commented on Sep 3, 2021

    @Nogbit

    Isn't that param ignored if also ignoring metadata file? Here is what I tried...(with and without inferdivisions)

    df = dd.read_parquet(
      path='s3://bucket-here/parquet/**/*.*',
      engine='pyarrow',
      ignore_metadata_file=True,     # https://github.com/dask/dask/issues/8027
      columns=parquet_to_read,
      infer_divisions=False
    )  
  19. Nogbit commented on Sep 3, 2021

    @Nogbit

    I tried what you suggested, same problem.

    df = dd.read_parquet(
      path='s3://my-bucket/parquet/',
      engine='pyarrow',
      ignore_metadata_file=True,     # https://github.com/dask/dask/issues/8027
      columns=parquet_to_read,
      infer_divisions=False,
      gather_statistics=False
    ) 

    I recreated it all with fastparquet as well, and have the same issue on the read side of things with it stalling and nothing happening (metadata file is 1GB). Though here, my notebook kernel auto restarts after 8min.

    df = dd.read_parquet(
      path='s3://bucket-here-v2/parquet/',
      engine='fastparquet',
      columns=parquet_to_read
    )  
  20. jorisvandenbossche commented on Sep 9, 2021

    @jorisvandenbossche
    Member

    any idea on a workaround?

    Unfortunately there is no direct workaround (if needing to read the actual file), except for using an older thrift version. But the built packages (both wheels and conda-forge, I think) of recent pyarrow versions include the latest thrift, so that might mean building (py)arrow yourself ..
    I hope we can fix this on the pyarrow side for the next release (https://issues.apache.org/jira/browse/ARROW-13655), but so that's not a short-term fix.

  21. jorisvandenbossche commented on Sep 9, 2021

    @jorisvandenbossche
    Member

    Although it seems that some old builds of arrow-cpp 4.0 still use libthrift 0.13 on conda-forge (testing it with mamba create -n test python=3.9 pyarrow libthrift=0.13 seems to give pyarrow 3.0, though)

  22. jorisvandenbossche commented on Sep 14, 2021

    @jorisvandenbossche
    Member

    Small update: we have a PR to fix this for the next pyarrow release (apache/arrow#11123, thanks to Antoine Pitrou). There are some security questions related to a CVE, but hopefully that can get resolved.

  23. self-assigned this
    on Mar 24, 2022
  24. jcrist commented on May 13, 2022

    @jcrist
    Member

    We no longer write _metadata files by default, and in many cases no longer load file statistics. With that combined with the upstream pyarrow fix, I believe this can be closed.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions