Skip to content

Add ignore_metadata_file option to read_parquet (pyarrow-dataset and fastparquet support only) - #8034

Merged
jrbourbeau merged 11 commits into
dask:mainfrom
rjzamora:ignore-metadata-pyarrow
Aug 20, 2021
Merged

jrbourbeau merged 11 commits into
dask:mainfrom
rjzamora:ignore-metadata-pyarrow

Conversation

@rjzamora

@rjzamora rjzamora commented Aug 13, 2021 •

Copy link
Copy Markdown
Member

May address #8030

This PR makes it possible to ignore a global _metadata file using the ignore_metadata_file argument:

ddf = dd.read_parquet(
    path,
    engine="pyarrow-dataset",
    ignore_metadata_file=True,
)

Note that I did not add support for fastparquet or pyarrow-legacy (they will both raise an error if ignore_metadata_file=True), only because it is much trickier to implement for those engines (and because the pyarrow-legacy engine will be deprecated soon anyway).

EDIT: This PR now adds ignore_metadata_file support for both "pyarrow-datset" and "fastparquet". The "pyarrow-legacy" case still doesn't make much sense because: (1) it is deprecated, and (2) the engine will still construct a proxy _metadata file anyway.

@rjzamora rjzamora changed the title make it possible to ignore metadata in pyarrow-dataset engine Add ignore_metadata_file option to read_parquet (pyarrow-dataset support only) Aug 13, 2021

@jrbourbeau jrbourbeau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @rjzamora! Pardon my ignorance about our parquet engines, but I'm curious why supporting ignore_metadata_file is more involved for fastparquet (also cc @martindurant)

@rjzamora

Copy link
Copy Markdown
Member Author

Thanks @rjzamora! Pardon my ignorance about our parquet engines, but I'm curious why supporting ignore_metadata_file is more involved for fastparquet

You are absolutely right to ask this, because I should be able to add support for fastparquet. We will probably just need to use some variation of fs.find to discover all the nested paths before passing to fp.ParquetFile. I just noticed earlier that "fastparquet" was failing without the _metadata file for partitioned datasets, and I was not feeling particularly motivated to track down the root problem. However, now that a larger read_metadata revision is in the cards, I am feeling a bit differently :)

Comment thread dask/dataframe/io/parquet/arrow.py Resolved
Comment thread dask/dataframe/io/tests/test_parquet.py Resolved
@rjzamora rjzamora changed the title Add ignore_metadata_file option to read_parquet (pyarrow-dataset support only) Add ignore_metadata_file option to read_parquet (pyarrow-dataset and fastparquet support only) Aug 18, 2021
@rjzamora

Copy link
Copy Markdown
Member Author

Update: Thanks for the reivew here @jrbourbeau ! I addressed your comments, and added "fastparquet" support here. So, hopefully this PR is in good shape (once CI is passing).

@martindurant martindurant left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

At a quick glance, the fp route looks OK, but first I wonder: should we explicitly disallow the combination of ignore_metadata_file with gather_statistics?

# This is a directory.
# Check if _metadata and/or _common_metadata files exists
base = paths[0]
_metadata_exists = fs.isfile(fs.sep.join([base, "_metadata"]))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If ignore_metadata_file, then we know we will have to list the whole directory anyway, so we can avoid the calls to isfile and even isdir, above.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good point - I just pushed a change to avoid the isfile calls. However, it seems like we may need to move around the logic quite a bit to avoid the isdir call. In fact, I'm nor really sure of an elegant way to avoid it.

@rjzamora

Copy link
Copy Markdown
Member Author

At a quick glance, the fp route looks OK, but first I wonder: should we explicitly disallow the combination of ignore_metadata_file with gather_statistics?

My vote is "no" - I don't think a willingness to ignore the shared _metadata file means the user should not be able to gather statistics. After #8058, there may even be cases where a parallel read_metadata with ignore_metadata_file=True will be quite fast.

@jrbourbeau jrbourbeau left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Woo, thanks for adding ignore_metadata_file support to fastparquet!

Comment thread dask/dataframe/io/parquet/core.py Resolved
Comment thread dask/dataframe/io/tests/test_parquet.py Resolved
Comment thread dask/dataframe/io/tests/test_parquet.py Outdated
Comment on lines +3607 to +3609
# Should not have known divisions if gather_statistics=None
# Otherwise, we must have used a _metadata file
assert set(ddf2.divisions) == {None}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems fine, but I wonder if there's a more direct check we can have that _metadata wasn't used. For example, we could manually delete the _metadata file before calling read_parquet

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Without the file, we would presumably get the same behaviour whether you have ignore-metadata true or false.

@rjzamora rjzamora Aug 18, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I updated the test to do something pretty simple: We write two datasets (one with _metadata, and one without), and check that the result is the same with ignore_metadata_file=True. How does that sound?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'll defer to you two on this test. I think I still need to wrap my head around how we handle gathering metadata and how that translates to division information on the resulting DataFrame. If you two are happy with this, then let's go with it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Another option might be to create a dataset with a "wrong" _metadata file (eg only listing a subset of the files, or simply an invalid parquet file), and then reading it with ignore_metadata_file, you can be sure it was not used if you get the correct result.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

That's the answer, thanks @jorisvandenbossche - replace the _metadata file with something invalid (perhaps empty?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That seems like a good approach, I pushed de44f6a (where I copied in a "wrong" _metadata file) and then b472c2b (where I wrote out an "invalid" file). I'm going with the "invalid" approach for now, but happy to tweak things again.

@jrbourbeau

Copy link
Copy Markdown
Member

Just checking in, @rjzamora @martindurant is there anything else left to address here, or are we good to merge? Also cc @jorisvandenbossche for visibility

@jrbourbeau

Copy link
Copy Markdown
Member

Thanks for the test update @rjzamora -- I feel confident we're effectively testing that _metadata isn't read when ignore_metadata_file=True. There's a test_partition_on failure in CI, but from what I can tell it looks unrelated. Can you confirm?

@rjzamora

Copy link
Copy Markdown
Member Author

There's a test_partition_on failure in CI, but from what I can tell it looks unrelated. Can you confirm?

Yikes. I'd rather not ignore a failure in test_parquet.py. I'll try to figure out what is going wrong.

@martindurant

Copy link
Copy Markdown
Member

I'll try to figure out what is going wrong.

Sounds like an odd one, we can pair to figure this out, if you like.

@rjzamora

Copy link
Copy Markdown
Member Author

@martindurant - Are you able to reproduce the failure locally? I'm not sure how any of the fastparquet-engine changes could be causing this.

@martindurant

Copy link
Copy Markdown
Member

Passes with dask main/fastparquet main
Passes with your branch/fastparquet main

Since it's only coming up on one build, could it be some combination of the random numbers, e.g., one of the specific sub-directories ends up empty?

@martindurant

Copy link
Copy Markdown
Member

I ran with --count 30 and got no failures; but this is on mac.

@jrbourbeau

Copy link
Copy Markdown
Member

Just checking in, any luck reproducing? I'm inclined to merge if we're not able to and just keep an eye on test_partition_on

@rjzamora

Copy link
Copy Markdown
Member Author

Just checking in, any luck reproducing? I'm inclined to merge if we're not able to and just keep an eye on test_partition_on

No luck reproducing on my end. We may have some problematic behavior to fix, but I suspect it is not being caused by this PR.

@jrbourbeau

Copy link
Copy Markdown
Member

Alright, thanks for your efforts on trying to reproduce @rjzamora @martindurant. I'll plan to merge this later in the evening if there aren't any objections

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants