You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@datafusion.apache.org by "notfilippo (via GitHub)" <gi...@apache.org> on 2024/07/12 13:43:57 UTC
[I] Preceding and Following (WindowFrameBound) are incorrectly handled when an unoptimized plan created via SQL is converted to a substrait Plan [datafusion]
notfilippo opened a new issue, #11432:
URL: https://github.com/apache/datafusion/issues/11432
### Describe the bug
The function which parses the Preceding and Following expressions in window functions returns a `ScalarValue::Utf8`:
https://github.com/apache/datafusion/blob/1dfac86a89750193491cf3e04917e37b92c64ffa/datafusion/expr/src/window_frame.rs#L364
I suspect that for unoptimized plans the `WindowFrameBound` containing a `ScalarValue::Utf8` gets directly passed to the substrait conversion logic, causing the fallback branch in the pattern match to execute and resulting to a `SubstraitBound::Unbounded`.
https://github.com/apache/datafusion/blob/1dfac86a89750193491cf3e04917e37b92c64ffa/datafusion/substrait/src/logical_plan/producer.rs#L1824
Not sure if the fix should be developed in the substrait conversion logic or before.
### To Reproduce
```rust
#[tokio::main]
async fn main() -> datafusion::error::Result<()> {
let ctx = SessionContext::new();
let schema = Schema::new(vec![
Field::new("salary", DataType::Int64, false),
Field::new("empno", DataType::Int64, false),
]);
let table = MemTable::try_new(Arc::new(schema), vec![])?;
ctx.register_table("empsalary", Arc::new(table))?;
let df = ctx
.sql(
"SELECT
avg(salary) OVER(ORDER BY salary ASC ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING) AS avg
FROM empsalary
ORDER BY empno",
)
.await?;
let plan = df.logical_plan();
let plan = datafusion_substrait::logical_plan::producer::to_substrait_plan(plan, &ctx)?;
eprintln!("{:#?}", plan);
Ok(())
}
```
```
WindowFunction {
function_reference: 0,
arguments: [
...
],
invocation: Unspecified,
partitions: [],
bounds_type: Rows,
lower_bound: Some(
Bound {
kind: Some(
Unbounded(
Unbounded,
),
),
},
),
upper_bound: Some(
Bound {
kind: Some(
Unbounded(
Unbounded,
),
),
},
),
args: [],
},
```
### Expected behavior
The bounds such as `BETWEEN 1 PRECEDING AND 1 FOLLOWING` should be correctly encoded in substrait.
### Additional context
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Preceding and Following (WindowFrameBound) are incorrectly handled when an unoptimized plan created via SQL is converted to a substrait Plan [datafusion]
Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal closed issue #11432: Preceding and Following (WindowFrameBound) are incorrectly handled when an unoptimized plan created via SQL is converted to a substrait Plan
URL: https://github.com/apache/datafusion/issues/11432
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org
Re: [I] Preceding and Following (WindowFrameBound) are incorrectly handled when an unoptimized plan created via SQL is converted to a substrait Plan [datafusion]
Posted by "goldmedal (via GitHub)" <gi...@apache.org>.
goldmedal closed issue #11432: Preceding and Following (WindowFrameBound) are incorrectly handled when an unoptimized plan created via SQL is converted to a substrait Plan
URL: https://github.com/apache/datafusion/issues/11432
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: github-unsubscribe@datafusion.apache.org
For additional commands, e-mail: github-help@datafusion.apache.org