comphead commented on code in PR #8402:
URL: https://github.com/apache/arrow-datafusion/pull/8402#discussion_r1413199372
##########
datafusion/sql/src/expr/function.rs:
##########
@@ -90,10 +91,30 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let partition_by = window
.partition_by
.into_iter()
+ // ignore window spec PARTITION BY for scalar values
+ .filter(|e| !matches!(e, sqlparser::ast::Expr::Value { .. }))
.map(|e| self.sql_expr_to_logical_expr(e, schema,
planner_context))
.collect::<Result<Vec<_>>>()?;
- let order_by =
- self.order_by_to_sort_expr(&window.order_by, schema,
planner_context)?;
+
+ let order_by = self.order_by_to_sort_expr(
+ &window
+ .order_by
+ .into_iter()
+ // ignore window spec ORDER BY for scalar values
+ .filter(|e| {
+ !matches!(
+ e,
+ OrderByExpr {
+ expr: sqlparser::ast::Expr::Value { .. },
+ ..
+ }
+ )
Review Comment:
initial tests are in the ticket description
https://github.com/apache/arrow-datafusion/issues/8386#issue-2019933888
the small local test
```
❯ select rank() over (order by null) from (select 1 a union all select 2 a)
q;
Error during planning: Sort operation is not applicable to scalar value NULL
```
In pg/duckdb
```
D select rank() over (order by null) from (select 1 a union all select 2 a)
q;
┌─────────────────────────────┐
│ rank() OVER (ORDER BY NULL) │
│ int64 │
├─────────────────────────────┤
│ 1 │
│ 1 │
└─────────────────────────────┘
```
##########
datafusion/sql/src/expr/function.rs:
##########
@@ -90,10 +91,30 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
let partition_by = window
.partition_by
.into_iter()
+ // ignore window spec PARTITION BY for scalar values
+ .filter(|e| !matches!(e, sqlparser::ast::Expr::Value { .. }))
.map(|e| self.sql_expr_to_logical_expr(e, schema,
planner_context))
.collect::<Result<Vec<_>>>()?;
- let order_by =
- self.order_by_to_sort_expr(&window.order_by, schema,
planner_context)?;
+
+ let order_by = self.order_by_to_sort_expr(
+ &window
+ .order_by
+ .into_iter()
+ // ignore window spec ORDER BY for scalar values
+ .filter(|e| {
+ !matches!(
+ e,
+ OrderByExpr {
+ expr: sqlparser::ast::Expr::Value { .. },
+ ..
+ }
+ )
Review Comment:
initial tests are in the ticket description
https://github.com/apache/arrow-datafusion/issues/8386#issue-2019933888
the small local test
```
❯ select rank() over (order by null) from (select 1 a union all select 2 a)
q;
Error during planning: Sort operation is not applicable to scalar value NULL
```
In pg/duckdb
```
D select rank() over (order by null) from (select 1 a union all select 2 a)
q;
┌─────────────────────────────┐
│ rank() OVER (ORDER BY NULL) │
│ int64 │
├─────────────────────────────┤
│ 1 │
│ 1 │
└─────────────────────────────┘
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]