Repository navigation
Conversation
|
@zhuqi-lucas could you perhaps help review this PR (or help find someone that could)? |
zhuqi-lucas
left a comment
There was a problem hiding this comment.
Thanks @rank-p for the fix, and @alamb for the ping. I also ran a few row group layouts locally (overlapping groups, ties on the first key, NULLs in a later group, DESC and mixed ASC/DESC keys, strings, timestamps, floats with and without NaN): the inferred ordering and the results were all correct.
| || group | ||
| .column(column_index) | ||
| .statistics() | ||
| .and_then(ParquetStatistics::nan_count_opt) |
There was a problem hiding this comment.
Files whose float statistics have no nan_count (e.g. written by pyarrow 23, which I checked locally) used to keep a float sort key and now lose it, so the SortExec comes back for them. That seems right since NaNs are not in min/max, but it may be worth a line in the upgrade guide.
|
Hi @xudong963, I see that you self-requested a review, are you able to take a look at this? |
alamb
left a comment
There was a problem hiding this comment.
Thank you for this PR @rank-p
Can we please break this PR up into smaller pieces so we can more easily undertand the implications of the changes?
This looks to me like it will disable floating point statisics in some cases, for example, as well as potentially try to handle statistics for nested strucutres.
Also the tests are really hard to follow as they have a lot of repeated boilerplate that obscures what is desired
| } | ||
|
|
||
| #[tokio::test] | ||
| async fn test_parquet_unordered_row_groups_require_sort() -> Result<()> { |
There was a problem hiding this comment.
I found these tests very hard to read -- is there some way we can convert them to mostly/all sqllogictests?
Or at least insta snapshot tests?
for example, a test that shows:
- Input (with relevant sorting)
- Query that calls for sorting
- Verifificion of the correct results and plan
|
|
||
| // Find the column in the arrow schema | ||
| let (index, _) = arrow_schema.column_with_name(name)?; | ||
| /// Refine boundaries still tied on earlier keys. A strict earlier boundary |
There was a problem hiding this comment.
this code feels much more complicated than necessary to me.
Can you add some exampels of what it is actually doing?
| return Ok(None); | ||
| }; | ||
| let resolver = LeafResolver::new(parquet_schema, &physical_schema); | ||
| let mut ordering = Vec::with_capacity(sorting_columns.len()); |
There was a problem hiding this comment.
is this code to handle sorting of nested columns new? Is it needed for this PR? If so, I think we should have end to end slt/sql examples that show what is going on
| Some(PhysicalSortExpr::new(expr, options)) | ||
| }) | ||
| .collect() | ||
| fn float_bounds_exclude_zero( |
There was a problem hiding this comment.
CHanging the sorting statistics for floating point columns seems like a substantial new behavior as well
7ae491b to
817963e
Compare
|
Hi @alamb, thanks a lot for the review, I really appreciate it. I scoped this PR down. The core logic in
If statistics are unknown the file is labeled as not ordered. This could be the case if null counts are missing. One question from my side: For the snapshot tests, is this how you are usually doing this? Sqllogictest can't test this behavior as it can't write a file like this ( |
Which issue does this PR close?
Related to lakehq/sail#2730.
Rationale for this change
Parquet sort declarations apply to individual row groups. Using the first group's declaration for the whole file can remove a required sort. For groups
[1, 4]and[2, 3],ORDER BY a ASC NULLS FIRST LIMIT 2returned[1, 4]instead of[1, 2].What changes are included in this PR?
Keep only the common leading sort keys whose row-group boundaries are ordered. Use typed bounds that account for NULLs, comparison order, and schema mapping. Missing or incompatible metadata leaves the required sort in place.
What is the testing strategy for this PR?
core/tests/parquet/ordering.rsfail on the old code and pass with the fix, includingORDER BY ... LIMIT.Are there any user-facing changes?
Correct ordering and row selection when reading Parquet files whose row groups are sorted but the whole file is not. No public API changes.
AI assistance: Codex.