Skip to content

Allowing fastparquet to handle gather_statistics=False for file lists - #5157

Merged
martindurant merged 10 commits into
dask:masterfrom
rjzamora:fix-issue-5153
Jul 31, 2019
Merged

martindurant merged 10 commits into
dask:masterfrom
rjzamora:fix-issue-5153

Conversation

@rjzamora

@rjzamora rjzamora commented Jul 25, 2019 •

Copy link
Copy Markdown
Member

This is hopefully a fix for the bug raised in Issue#5153. The specific changes are in line with this comment.

In the fastparquet engine, it is possible to take in a list of files, but have gather_statistics=False. This case was previously untested. I added a new test (test_read_glob_nostats), and tweaked the engine a bit to allow the parts output of read_metadata to (optionally) include file paths rather than row-group information.

  • Tests added / passed
  • Passes black dask / flake8 dask

@rjzamora rjzamora changed the title addressing fastparquet case where a file list is passed in and gather… Allowing fastparquet to handle gather_statistics=False for file lists Jul 25, 2019
@mrocklin

Copy link
Copy Markdown
Member

@birdsarah @martindurant

@birdsarah

Copy link
Copy Markdown
Contributor

I am currently testing this. So far so good. I can load my dataset in a few seconds with 1800 partitions. Game changing!

I will keep working on this branch and see how I get on.

But this has definitely passed my bug from yesterday.

Thank you so much for the quick turnaround!

@martindurant

Copy link
Copy Markdown
Member

I second what @birdsarah says - it's great to have someone handling parquet stuff quickly!

@mrocklin

Copy link
Copy Markdown
Member
dask.parquet.bus_factor += 1

@birdsarah

birdsarah commented Jul 26, 2019 •

Copy link
Copy Markdown
Contributor

I have also successfully loaded my data with the latest commit. I have not checked the directory pathway. If you give me some example inputs I can test them on my real setup.

I am now successfully working on a dataset with 74,000 partitions and no _metadata.

Opening dataset and df.head() takes 7 - 30s. (Presumably depending on whether s3fs cache is cold or not). THIS IS HUGE! This was literally impossible before.

@mrocklin

mrocklin commented Jul 26, 2019 via email

Copy link
Copy Markdown
Member

@rjzamora

Copy link
Copy Markdown
Member Author

@birdsarah Following my comment in issue#4701, I made some changes here that should allow the pyarrow engine to be used to open a list or directory of files without _metadata file and with gather_statistics=False.

As noted by @wesm, the read_metadata code for both engines is a bit hard to follow, and could still use some cleanup/refactoring.

@rjzamora rjzamora mentioned this pull request Jul 29, 2019
8 tasks done
@rjzamora rjzamora mentioned this pull request Jul 29, 2019
2 tasks done
@birdsarah

birdsarah commented Jul 29, 2019 •

Copy link
Copy Markdown
Contributor

I'm confused @rjzamora. Do you want me to work on my PR or do you just want to do it here?

@rjzamora

Copy link
Copy Markdown
Member Author

@birdsarah I added your changes before I knew you were picking back up (just because we are trying to tie up loose ends for a release).

I'd actually prefer to have your PR separately merged - I am mostly incorperating your changes here as a check that I haven't brocken anything for you

@birdsarah

Copy link
Copy Markdown
Contributor

ok cool. i'll see my pr through ci today.

has anyone tested your new pyarrow metadata? i can test it on my large dataset if it's useful.

@rjzamora

Copy link
Copy Markdown
Member Author

ok cool. i'll see my pr through ci today.

has anyone tested your new pyarrow metadata? i can test it on my large dataset if it's useful.

That would be great!

@birdsarah

birdsarah commented Jul 29, 2019 •

Copy link
Copy Markdown
Contributor

Hmmmm.....I'm not sure this is an issue with your PR but it might be.....or my error might mean success for your PR :D

I'm trying to read my 74k partition parquet data with pyarrow.

I get the following error after ~20s, which seems reasonable to me.

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<timed exec> in <module>

/mnt/miniconda/envs/jestr-etl/lib/python3.7/site-packages/dask/dataframe/io/parquet/core.py in read_parquet(path, columns, filters, categories, index, storage_options, engine, gather_statistics, **kwargs)
    153         gather_statistics=gather_statistics,
    154         filters=filters,
--> 155         **kwargs
    156     )
    157     if meta.index.name is not None:

/mnt/miniconda/envs/jestr-etl/lib/python3.7/site-packages/dask/dataframe/io/parquet/arrow.py in read_metadata(fs, paths, categories, index, gather_statistics, filters, **kwargs)
    168             )
    169 
--> 170         dtypes = _get_pyarrow_dtypes(schema, categories)
    171         dtypes = {storage_name_mapping.get(k, k): v for k, v in dtypes.items()}
    172 

/mnt/miniconda/envs/jestr-etl/lib/python3.7/site-packages/dask/dataframe/io/utils.py in _get_pyarrow_dtypes(schema, categories)
     38                 numpy_dtype = pandas_metadata_dtypes[field.name]
     39         else:
---> 40             numpy_dtype = field.type.to_pandas_dtype()
     41 
     42         dtypes[field.name] = numpy_dtype

/mnt/miniconda/envs/jestr-etl/lib/python3.7/site-packages/pyarrow/types.pxi in pyarrow.lib.DataType.to_pandas_dtype()

NotImplementedError: struct<key_value: list<key_value: struct<key: string, value: string> not null>>

Why might it be related: This pr updates the definition of dataset to

        parts, dataset = _determine_dataset_parts(
            fs, paths, gather_statistics, **kwargs
        )

which is what then makes a schema which is passed into _get_pyarrow_dtypes.

But it may be that nothing about this actually changed. And that I never got to this error message before because it was trying to read metadata from 74k files, which never finished.

So this error may actually be a sign of success.

Of course, if you happen to know how to work around this NotImplementedError that would be amazing because my data is actually this wierd nested struct. (https://gitter.im/dask/dask?at=5d3b445e0d0ffc39758b138f)

@rjzamora

Copy link
Copy Markdown
Member Author

...my data is actually this wierd nested struct. (https://gitter.im/dask/dask?at=5d3b445e0d0ffc39758b138f)

Right - Sorry, that is probably the issue here. The new _determine_dataset_parts function is using the metadata from a single file in the case that the _metadata file is unavailable and gather_statistics=False (uses _common_metadata if available). In many cases, the schema metadata should be the same.

You are most-likely right that you would have had the same problem before this PR, but just needed to wait a lot longer to find out :)

@birdsarah

Copy link
Copy Markdown
Contributor

You are most-likely right that you would have had the same problem before this PR, but just needed to wait a lot longer to find out :)

Then I think this is a success. Unfortunately I don't have a dataset to hand that is v. large and has simple datatypes.

I will note that I was only trying to read in one column, that was just an integer field. What do you think about opening an issue that adds, as a follow-on optimization, only inferring metadata for the requested columns?

@rjzamora

Copy link
Copy Markdown
Member Author

I will note that I was only trying to read in one column, that was just an integer field. What do you think about opening an issue that adds, as a follow-on optimization, only inferring metadata for the requested columns?

Sure - That might be a reasonable workaround. In the mean time, I put the to_pandas_dtype call in a try block for you to test here (if you have time) - dtypes should not need to contain fields that you are not actually reading in, so this might actually do the trick.

@birdsarah

Copy link
Copy Markdown
Contributor

Testing

@birdsarah

Copy link
Copy Markdown
Contributor

This worked. Was able to read in 1 column of my 74k partition dataset with engine='pyarrow' even though I have a column in that dataset that dask's pyarrow import can't currently handle. Awesome!

@martindurant

Copy link
Copy Markdown
Member

To be clear, this was working too for fastparquet?

@birdsarah

Copy link
Copy Markdown
Contributor

To be clear, this was working too for fastparquet?

100% yes. Both have been tested against very high n partition data with no _metadata / _common_metadata.

@rjzamora

Copy link
Copy Markdown
Member Author

@martindurant Can you review these changes at your convenience? I will rebase/merge after #5150 goes through, but that should only change some test names.

@mrocklin

Copy link
Copy Markdown
Member

How important is it to get this PR in before the release? Is there a regression here?

(poking @martindurant for review, if he has time)

Also, I'll admit that I'm a little scared by the amount of extra logic introduced here (though of course it may be necessary)

@rjzamora

rjzamora commented Jul 31, 2019 •

Copy link
Copy Markdown
Member Author

@mrocklin That is a fair question.

The previous fastparquet engine couldn't handle gather_statistics=False when a list of files was supplied. It also couldn't handle a directory input without the "_metadata" file. Therefore, there are technically two "bug fixes" here (one if you are okay with the assumption that a directory input must include "_metadata").

Although the pyarrow engine wasn't crashing for these cases, it was only "working" because it was scanning the metadata for every file by default (not what you actually want on non-local file systems).

It does worry me to push this through in a rush, but most of these changes probably should have been in the original refactor anyway.

With that said, since we are no longer scanning every file in read_metadata, there does seem to be a regression in the reading of partitioned datasets that are written by a different engine (when gather_statistics=False).

@mrocklin

Copy link
Copy Markdown
Member

@martindurant can you provide a judgement call here? Should this be merged in? Should it go into the upcoming release? I'm at a point where I would like to cut a dask/dask release, and am not sure if this should go in or not.

@martindurant

Copy link
Copy Markdown
Member

Sorry, I haven't had the chance to look through it yet. I think the idea of the functionality is simple enough (in concept, if not implementation) and this is certainly useful in many cases. Given only limited opportunity for regression, as described above, I'd be fairly pro. I have traditionally been less cautious than others, however.

@mrocklin

mrocklin commented Jul 31, 2019 via email

Copy link
Copy Markdown
Member

@birdsarah

Copy link
Copy Markdown
Contributor

For what it's worth. This is extremely helpful for my current workflows and I'll end up continuing to work in production on a manually installed branch version if this doesn't make it into release.

If there's regressions and fall out I'm happy to commit to helping with testing fixes if that's useful.

@martindurant
martindurant merged commit 5e4eccd into dask:master Jul 31, 2019
@rjzamora
rjzamora deleted the fix-issue-5153 branch July 31, 2019 18:45
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.

4 participants