zhuqi-lucas commented on code in PR #26400:
URL: https://github.com/apache/datafusion/pull/26400#discussion_r4307426024
##########
datafusion/sql/src/select.rs:
##########
@@ -1437,42 +1437,106 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
{
let mut err = None;
let _ = visit_expressions_mut(expr, |expr| {
- if let SQLExpr::Function(f) = expr
- && let Some(WindowType::NamedWindow(ident)) = &f.over
- {
- let normalized_ident =
- self.ident_normalizer.normalize(ident.clone());
- for (
- NamedWindowDefinition(_, window_expr),
- normalized_window_ident,
- ) in named_windows.iter()
- {
- if normalized_ident.eq(normalized_window_ident) {
- f.over = Some(match window_expr {
- NamedWindowExpr::NamedWindow(ident) => {
- WindowType::NamedWindow(ident.clone())
- }
- NamedWindowExpr::WindowSpec(spec) => {
- WindowType::WindowSpec(spec.clone())
- }
- })
+ if let SQLExpr::Function(f) = expr {
Review Comment:
Thanks @jayzhan211, good catch! Applied in 2d171c58a: QUALIFY and ORDER BY
are resolved as well, with QUALIFY and ORDER BY cases added to `window.slt`.
##########
datafusion/sql/src/select.rs:
##########
@@ -1437,42 +1437,106 @@ impl<S: ContextProvider> SqlToRel<'_, S> {
{
let mut err = None;
let _ = visit_expressions_mut(expr, |expr| {
- if let SQLExpr::Function(f) = expr
- && let Some(WindowType::NamedWindow(ident)) = &f.over
- {
- let normalized_ident =
- self.ident_normalizer.normalize(ident.clone());
- for (
- NamedWindowDefinition(_, window_expr),
- normalized_window_ident,
- ) in named_windows.iter()
- {
- if normalized_ident.eq(normalized_window_ident) {
- f.over = Some(match window_expr {
- NamedWindowExpr::NamedWindow(ident) => {
- WindowType::NamedWindow(ident.clone())
- }
- NamedWindowExpr::WindowSpec(spec) => {
- WindowType::WindowSpec(spec.clone())
- }
- })
+ if let SQLExpr::Function(f) = expr {
Review Comment:
Thanks! Fixed it in this PR rather than a follow-up: the resolver now tracks
query depth and only rewrites at depth 0, so each subquery resolves against its
own `WINDOW` clause. Added your case, plus one where the subquery has no
`WINDOW` clause, which now errors like PostgreSQL.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]