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

minor: fix to support scalars #8559

Merged
merged 2 commits into from
Dec 18, 2023
Merged

minor: fix to support scalars #8559

merged 2 commits into from
Dec 18, 2023

Conversation

comphead
Copy link
Contributor

Which issue does this PR close?

Closes #8386 .

Rationale for this change

Support scalars for PARTITION BY clause to avoid Expects PARTITION BY expression to be ordered error.

What changes are included in this PR?

Are these changes tested?

Yes

Are there any user-facing changes?

No

@github-actions github-actions bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Dec 15, 2023
@comphead
Copy link
Contributor Author

@mustafasrepo please review

Copy link
Contributor

@mustafasrepo mustafasrepo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @comphead. I have one minor comment. However It is not important for this PR.

@@ -90,6 +90,8 @@ 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 mut order_by = self.order_by_to_sort_expr(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to test it seems that we have no problem with ScalarValues inside window order_by. However, I think we can apply similar filtering done for window.partition_by to the window.order_by.

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me -- thank you @comphead and @mustafasrepo

datafusion/sql/src/expr/function.rs Outdated Show resolved Hide resolved
query I
select rank() over (order by 1) rnk from (select 1 a union all select 2 a) x
----
1
1

# support scalar value in both ORDER BY and PARTITION BY, RANK function
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 as @mustafasrepo points out

Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL Planner sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: windows frame don't support scalars in ORDER BY/PARTITION BY clauses
3 participants