alamb commented on code in PR #9798:
URL: https://github.com/apache/arrow-datafusion/pull/9798#discussion_r1538519670


##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -113,10 +113,38 @@ impl Unparser<'_> {
             }
             Expr::Case(Case {
                 expr,
-                when_then_expr: _,
-                else_expr: _,
+                when_then_expr,
+                else_expr,
             }) => {
-                not_impl_err!("Unsupported expression: {expr:?}")
+                let conditions = when_then_expr
+                    .iter()
+                    .map(|(w, _)| self.expr_to_sql(w))
+                    .collect::<Result<Vec<_>>>()?;
+                let results = when_then_expr
+                    .iter()
+                    .map(|(_, t)| self.expr_to_sql(t))
+                    .collect::<Result<Vec<_>>>()?;

Review Comment:
   I likewise tried to use `izip` and came up with this, which wasn't 
particularly nice
   
   ```rust
                   let (conditions, results): (Vec<_>, Vec<_>) = when_then_expr
                       .iter()
                       .map(|(w, t)| (self.expr_to_sql(w), self.expr_to_sql(t)))
                       .unzip();
   
                   let conditions = 
conditions.into_iter().collect::<Result<Vec<_>>>()?;
                   let results = 
results.into_iter().collect::<Result<Vec<_>>>()?;
   ```
   
   This is the best I could come up with but I am not sure how much better it 
is:
   
   ```rust
                   let mut conditions = vec![];
                   let mut results = vec[]!;
                   for (w, t) in when_then_expr {
                       conditions.push(self.expr_to_sql(w)?);
                       results.push(self.expr_to_sql(t)?);
                   }
   ```



-- 
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]

Reply via email to