You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "comphead (via GitHub)" <gi...@apache.org> on 2023/12/15 21:32:56 UTC

[PR] minor: fix to support scalars [arrow-datafusion]

comphead opened a new pull request, #8559:
URL: https://github.com/apache/arrow-datafusion/pull/8559

   ## Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #8386 .
   
   ## Rationale for this change
   
   Support scalars for `PARTITION BY` clause to avoid `Expects PARTITION BY expression to be ordered` error.
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   ## What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   ## Are these changes tested?
   Yes
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   ## Are there any user-facing changes?
   No
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->
   


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] minor: fix to support scalars [arrow-datafusion]

Posted by "comphead (via GitHub)" <gi...@apache.org>.
comphead commented on PR #8559:
URL: https://github.com/apache/arrow-datafusion/pull/8559#issuecomment-1858515139

   @mustafasrepo please review


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] minor: fix to support scalars [arrow-datafusion]

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #8559:
URL: https://github.com/apache/arrow-datafusion/pull/8559#discussion_r1429133521


##########
datafusion/sqllogictest/test_files/window.slt:
##########
@@ -3794,8 +3794,36 @@ select a,
 1 1
 2 1
 
+# support scalar value in ORDER BY 
 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

Review Comment:
   👍  as @mustafasrepo  points out



##########
datafusion/sql/src/expr/function.rs:
##########
@@ -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

Review Comment:
   ```suggestion
                   // ignore window spec PARTITION BY for scalar values
                   // as they do not change and thus do not generate new partitions
   ```
   
   I also double checked https://docs.rs/sqlparser/latest/sqlparser/ast/enum.Value.html is indeed the right node for literals



-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] minor: fix to support scalars [arrow-datafusion]

Posted by "mustafasrepo (via GitHub)" <gi...@apache.org>.
mustafasrepo commented on code in PR #8559:
URL: https://github.com/apache/arrow-datafusion/pull/8559#discussion_r1429121784


##########
datafusion/sql/src/expr/function.rs:
##########
@@ -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(

Review Comment:
   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`. 



-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] minor: fix to support scalars [arrow-datafusion]

Posted by "mustafasrepo (via GitHub)" <gi...@apache.org>.
mustafasrepo merged PR #8559:
URL: https://github.com/apache/arrow-datafusion/pull/8559


-- 
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@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org