You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ak...@apache.org on 2023/12/18 06:55:37 UTC

(arrow-datafusion) branch main updated: minor: fix to support scalars (#8559)

This is an automated email from the ASF dual-hosted git repository.

akurmustafa pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new b287cda40f minor: fix  to support scalars (#8559)
b287cda40f is described below

commit b287cda40fa906dbdf035fa6a4dabe485927f42d
Author: comphead <co...@users.noreply.github.com>
AuthorDate: Sun Dec 17 22:55:31 2023 -0800

    minor: fix  to support scalars (#8559)
    
    * minor: fix  to support scalars
    
    * Update datafusion/sql/src/expr/function.rs
    
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
    
    ---------
    
    Co-authored-by: Mustafa Akur <10...@users.noreply.github.com>
    Co-authored-by: Andrew Lamb <an...@nerdnetworks.org>
---
 datafusion/sql/src/expr/function.rs           |  3 +++
 datafusion/sqllogictest/test_files/window.slt | 28 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)

diff --git a/datafusion/sql/src/expr/function.rs b/datafusion/sql/src/expr/function.rs
index 73de4fa439..3934d6701c 100644
--- a/datafusion/sql/src/expr/function.rs
+++ b/datafusion/sql/src/expr/function.rs
@@ -90,6 +90,9 @@ impl<'a, S: ContextProvider> SqlToRel<'a, S> {
             let partition_by = window
                 .partition_by
                 .into_iter()
+                // ignore window spec PARTITION BY for scalar values
+                // as they do not change and thus do not generate new partitions
+                .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(
diff --git a/datafusion/sqllogictest/test_files/window.slt b/datafusion/sqllogictest/test_files/window.slt
index 6198209aaa..864f7dc0a4 100644
--- a/datafusion/sqllogictest/test_files/window.slt
+++ b/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
+# TODO: fix the test, some issue in RANK
+#query IIIIII
+#select rank() over (partition by 1 order by 1) rnk,
+#       rank() over (partition by a, 1 order by 1) rnk1,
+#       rank() over (partition by a, 1 order by a, 1) rnk2,
+#       rank() over (partition by 1) rnk3,
+#       rank() over (partition by null) rnk4,
+#       rank() over (partition by 1, null, a) rnk5
+#from (select 1 a union all select 2 a) x
+#----
+#1 1 1 1 1 1
+#1 1 1 1 1 1
+
+# support scalar value in both ORDER BY and PARTITION BY, ROW_NUMBER function
+query IIIIII
+select row_number() over (partition by 1 order by 1) rn,
+       row_number() over (partition by a, 1 order by 1) rn1,
+       row_number() over (partition by a, 1 order by a, 1) rn2,
+       row_number() over (partition by 1) rn3,
+       row_number() over (partition by null) rn4,
+       row_number() over (partition by 1, null, a) rn5
+from (select 1 a union all select 2 a) x;
+----
+1 1 1 1 1 1
+2 1 1 2 2 1
\ No newline at end of file