-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix: Add projection to generate_series #18298
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
Conversation
e605743 to
589bd3d
Compare
589bd3d to
3cbb00e
Compare
| let array = self.current.create_array(buf)?; | ||
| let batch = RecordBatch::try_new(Arc::clone(&self.schema), vec![array])?; | ||
| Ok(Some(batch)) | ||
| let projected = match self.projection.as_ref() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that the MemoryStream projects in https://github.com/apache/datafusion/blob/main/datafusion/physical-plan/src/memory.rs#L103 while the LazyMemoryStream used in generate_series doesn't. An alternative approach could be to project generically in the LazyMemoryStream instead inside of the generator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds like a great idea. Perhaps you could do so as a follow on PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @mkleen
|
Thanks @mkleen and @xudong963 |
## Which issue does this PR close? - Closes apache#17830 ## Rationale for this change The queries from the original ticket fail, because an unprojected `generate_series` function would produce in a join the wrong number of columns which leads to a runtime error. ## What changes are included in this PR? This adds a missing projection to `generate_series` to ensure values are only emitted when projected. ## Are these changes tested? I added a sql-logic test. I also compared the results against Postgres and DuckDB: Postgres: ```sql mkleen=# SELECT v1 FROM (select generate_series as v1 from generate_series(1, 3)) g1, (select generate_series as v2 from generate_series(1, 3)) g2; v1 ---- 1 1 1 2 2 2 3 3 3 (9 rows) ``` DuckDB: ```sql D SELECT v1 FROM (select generate_series as v1 from generate_series(1, 3)) g1, (select generate_series as v2 from generate_series(1, 3)) g2; ┌───────┐ │ v1 │ │ int64 │ ├───────┤ │ 1 │ │ 2 │ │ 3 │ │ 1 │ │ 2 │ │ 3 │ │ 1 │ │ 2 │ │ 3 │ └───────┘ ``` ## Are there any user-facing changes? No
## Which issue does this PR close? - None, This is a follow-up for #18298 ## Rationale for this change This moves the projection logic from `generate_series` out of the generator into `LazyMemoryStream` as discussed in #18298 (comment) This makes the projection logic generic for all generators. ## What changes are included in this PR? The projection logic is moved from `generate_series` into the `LazyMemoryStream` and relevant tests, where `LazyMemoryStream` is used, are adapted accordingly. ## Are these changes tested? This is only a small refactoring; the changes are covered by the tests from #18298 ## Are there any user-facing changes? There is a new parameter added to LazyMemoryExec::try_new method
…8373) ## Which issue does this PR close? - None, This is a follow-up for apache#18298 ## Rationale for this change This moves the projection logic from `generate_series` out of the generator into `LazyMemoryStream` as discussed in apache#18298 (comment) This makes the projection logic generic for all generators. ## What changes are included in this PR? The projection logic is moved from `generate_series` into the `LazyMemoryStream` and relevant tests, where `LazyMemoryStream` is used, are adapted accordingly. ## Are these changes tested? This is only a small refactoring; the changes are covered by the tests from apache#18298 ## Are there any user-facing changes? There is a new parameter added to LazyMemoryExec::try_new method
Which issue does this PR close?
generate_series: Invalid argument error: number of columns must match number of fields in schema #17830Rationale for this change
The queries from the original ticket fail, because an unprojected
generate_seriesfunction would produce in a join the wrong number of columns which leads to a runtime error.What changes are included in this PR?
This adds a missing projection to
generate_seriesto ensure values are only emitted when projected.Are these changes tested?
I added a sql-logic test. I also compared the results against Postgres and DuckDB:
Postgres:
DuckDB:
Are there any user-facing changes?
No