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

fix: Fix incorrect scan_parquet().with_row_index() with non-zero slice or with streaming collect #19609

Merged
merged 5 commits into from
Nov 4, 2024

Conversation

nameexhaustion
Copy link
Collaborator

@nameexhaustion nameexhaustion commented Nov 3, 2024

Fixes #19607
Fixes #19606

Issues affect queries of the form:

scan_parquet(...).with_row_index().slice(-N, ...)
scan_parquet(...).with_row_index().tail(N)
scan_parquet(...).with_row_index().collect(streaming=True)

For the negative-slice case we need to adjust the RowIndex offset accordingly. If we see that we need to add a row index we cannot stop early during reversed metadata scan, but instead need to scan through the metadata of the entire list of files to figure out the correct offset to begin from.

The other issue with streaming parquet was just forgetting to add the current row offset.

@github-actions github-actions bot added fix Bug fix python Related to Python Polars rust Related to Rust Polars labels Nov 3, 2024
@@ -149,6 +149,7 @@ def test_meta_tree_format(namespace_files_path: Path) -> None:
def test_meta_show_graph(namespace_files_path: Path) -> None:
e = (pl.col("foo") * pl.col("bar")).sum().over(pl.col("ham")) / 2
dot = e.meta.show_graph(show=False, raw_output=True)
assert dot is not None
Copy link
Collaborator Author

@nameexhaustion nameexhaustion Nov 3, 2024

Choose a reason for hiding this comment

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

drive-by fix mypy lint on main

@@ -830,7 +833,7 @@ fn rg_to_dfs_par_over_rg(
if let Some(rc) = &row_index {
df.with_row_index_mut(
rc.name.clone(),
Some(row_count_start as IdxSize + rc.offset),
Some(row_count_start as IdxSize + rc.offset + slice.0 as IdxSize),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In fn rg_to_dfs*, we also add slice.0 (offset), as it may be non-zero in a negative-slice case

Copy link

codecov bot commented Nov 3, 2024

Codecov Report

Attention: Patch coverage is 54.54545% with 40 lines in your changes missing coverage. Please review.

Project coverage is 79.84%. Comparing base (1eb2fcc) to head (e3edbe5).
Report is 4 commits behind head on main.

Files with missing lines Patch % Lines
...-stream/src/nodes/parquet_source/metadata_fetch.rs 0.00% 23 Missing ⚠️
...tes/polars-stream/src/nodes/parquet_source/init.rs 0.00% 8 Missing ⚠️
...ates/polars-stream/src/nodes/parquet_source/mod.rs 0.00% 7 Missing ⚠️
...tream/src/nodes/parquet_source/row_group_decode.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #19609      +/-   ##
==========================================
- Coverage   79.84%   79.84%   -0.01%     
==========================================
  Files        1536     1536              
  Lines      211405   211456      +51     
  Branches     2445     2445              
==========================================
+ Hits       168790   168829      +39     
- Misses      42060    42072      +12     
  Partials      555      555              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ritchie46 ritchie46 merged commit e98fb41 into pola-rs:main Nov 4, 2024
29 checks passed
tylerriccio33 pushed a commit to tylerriccio33/polars that referenced this pull request Nov 8, 2024
@nameexhaustion nameexhaustion deleted the parq-slice-row-index branch November 18, 2024 08:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix python Related to Python Polars rust Related to Rust Polars
Projects
None yet
2 participants