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

Substrait roundtrip fails for Sort with a fetch #13860

Closed
robtandy opened this issue Dec 20, 2024 · 1 comment · Fixed by #13862
Closed

Substrait roundtrip fails for Sort with a fetch #13860

robtandy opened this issue Dec 20, 2024 · 1 comment · Fixed by #13862
Labels
bug Something isn't working

Comments

@robtandy
Copy link
Contributor

Describe the bug

Substrait round trip fails for a query that produces a logical plan where the Sort node includes a fetch.

As an example,

Sort: data.b ASC NULLS LAST, fetch=2
  Filter: data.a > Int64(1)
    TableScan: data projection=[a, b, c, d, e, f], partial_filters=[data.a > Int64(1)]

Upon returning from the round trip produces

Sort: data.b ASC NULLS LAST
  Filter: data.a > Int64(1)
    TableScan: data projection=[a, b, c, d, e, f], partial_filters=[data.a > Int64(1)]

the fetch is lost.

I'm happy to take and fix this issue, but I wasn't sure where the fix should be made. Should this fix the Sort Rel in substrait that cannot hold a fetch member? Or should this be a fix in the substrait producer to produce a plan with a Limit and a Sort?

To Reproduce

Add a test to datafusion/substrait/tests/cases/round_trip_logical_plan.rs such as

#[tokio::test]
async fn select_with_filter_sort_limit() -> Result<()> {
    roundtrip("SELECT * FROM data WHERE a > 1 ORDER BY b ASC LIMIT 2").await
}

in this repo, run

cd datafusion/substrait
 cargo test -- --nocapture select_with_filter_sort_limit

Expected behavior

A round trip for this plan should work.

Additional context

No response

@robtandy robtandy added the bug Something isn't working label Dec 20, 2024
@robtandy
Copy link
Contributor Author

robtandy commented Dec 20, 2024

I think I've fixed this, let me submit a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant