You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ag...@apache.org on 2023/05/26 22:44:40 UTC

[arrow-datafusion-python] branch main updated: Add Expr::Case when_then_else support to rex_call_operands function (#388)

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

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


The following commit(s) were added to refs/heads/main by this push:
     new d912db5  Add Expr::Case when_then_else support to rex_call_operands function (#388)
d912db5 is described below

commit d912db5ea6ba5fc373a8412e505399bfe21c9a90
Author: Jeremy Dyer <jd...@gmail.com>
AuthorDate: Fri May 26 18:44:34 2023 -0400

    Add Expr::Case when_then_else support to rex_call_operands function (#388)
    
    * Add Expr::Case when_then_else support to rex_call_operands function
    
    * Update gitignore and formatting
    
    * Update gitignore and formatting
---
 .gitignore  |  5 ++++-
 src/expr.rs | 19 +++++++++++++------
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/.gitignore b/.gitignore
index 1d0a84a..365b89d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,9 @@ __pycache__/
 *.py[cod]
 *$py.class
 
+# Python dist ignore
+dist
+
 # C extensions
 *.so
 
@@ -24,4 +27,4 @@ apache-rat-*.jar
 .env
 CHANGELOG.md.bak
 
-docs/mdbook/book
\ No newline at end of file
+docs/mdbook/book
diff --git a/src/expr.rs b/src/expr.rs
index 1a9adf8..819edff 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -384,14 +384,21 @@ impl PyExpr {
                 let mut operands: Vec<PyExpr> = Vec::new();
 
                 if let Some(e) = expr {
-                    operands.push(PyExpr::from(*e.clone()));
+                    for (when, then) in when_then_expr {
+                        operands.push(PyExpr::from(Expr::BinaryExpr(BinaryExpr::new(
+                            Box::new(*e.clone()),
+                            Operator::Eq,
+                            Box::new(*when.clone()),
+                        ))));
+                        operands.push(PyExpr::from(*then.clone()));
+                    }
+                } else {
+                    for (when, then) in when_then_expr {
+                        operands.push(PyExpr::from(*when.clone()));
+                        operands.push(PyExpr::from(*then.clone()));
+                    }
                 };
 
-                for (when, then) in when_then_expr {
-                    operands.push(PyExpr::from(*when.clone()));
-                    operands.push(PyExpr::from(*then.clone()));
-                }
-
                 if let Some(e) = else_expr {
                     operands.push(PyExpr::from(*e.clone()));
                 };