Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support 'hive partitioning' aware readers #11284

Merged
merged 14 commits into from
Sep 26, 2023
Merged

feat: support 'hive partitioning' aware readers #11284

merged 14 commits into from
Sep 26, 2023

Conversation

ritchie46
Copy link
Member

@ritchie46 ritchie46 commented Sep 24, 2023

closes #10980, #10276

@alexander-beedie
Copy link
Collaborator

Nice! Hive partitioning support is super-useful 👍

@ritchie46
Copy link
Member Author

Nice! Hive partitioning support is super-useful 👍

Yes, especially the savings are potentially huge!

@ritchie46 ritchie46 added the highlight Highlight this PR in the changelog label Sep 25, 2023
@ritchie46 ritchie46 changed the title WIP: support 'hive partitioning' aware readers feat: support 'hive partitioning' aware readers Sep 25, 2023
@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars rust Related to Rust Polars labels Sep 25, 2023
@ion-elgreco
Copy link
Contributor

Closes also this: #10276

@ritchie46 ritchie46 merged commit 27e32dc into main Sep 26, 2023
25 checks passed
@ritchie46 ritchie46 deleted the hive branch September 26, 2023 05:45
romanovacca pushed a commit to romanovacca/polars that referenced this pull request Oct 1, 2023
@uditrana
Copy link

uditrana commented Nov 1, 2023

I am noticing an interesting pattern/bug with this feature.
I wrote a large dataset out using

df.write_parquet(
            file=DIR,
            use_pyarrow=True,
            pyarrow_options={
                "partition_cols": ["part_id_1", "part_id_2"],
                "basename_template": "test_{i}.parquet",
                "existing_data_behavior": "overwrite_or_ignore",
            },
        )

When I read these files back in using pl.read_parquet(), I observe 2 different results:

df1 = pl.read_parquet(DIR / "part_id_1=1" / "part_id_2="A" / "test_0.parquet")
df2 = pl.read_parquet(DIR / "part_id_1=1" / "part_id_2="A" / "*test_0.parquet")

In df1, part_id_1 and part_id_2 are missing from the columns, while they are present in df2. Basically, seems that read_parquet will not look for hive-partitioning structure if it is passed a single file, and even though in the second case it is reading only one file... the fact that the pattern could include multiple causes it to pick up the structure correctly.

@uditrana
Copy link

uditrana commented Nov 1, 2023

Also, slightly tangentially, could it make sense to expose an option in pl.read_parquet to include an option to turn off schema extension for hive partition columns? I have a use case where I am running into this error while trying to read a dataset:

ComputeError: invalid hive partitions

Extending the schema with the hive partitioned columns creates duplicate fields.

This dataset was written in a way to keep the partition columns in the partitioned dataframes so that other libraries (like Pandas) can read the dataframes individually and concatenate serially (since they don't support Hive natively yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature highlight Highlight this PR in the changelog python Related to Python Polars rust Related to Rust Polars
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use with_columns addition to a lazy frame with filter to prevent physically reading files
4 participants