rluvaton commented on code in PR #18183:
URL: https://github.com/apache/datafusion/pull/18183#discussion_r2555031060


##########
datafusion/physical-expr/src/expressions/case.rs:
##########
@@ -1370,6 +1445,26 @@ impl PhysicalExpr for CaseExpr {
             }
             EvalMethod::ScalarOrScalar => self.scalar_or_scalar(batch),
             EvalMethod::ExpressionOrExpression(p) => self.expr_or_expr(batch, 
p),
+            EvalMethod::WithExprScalarLookupTable {
+                lookup_table,
+                fallback_for_datatype_mismatch,
+            } => {
+                // Currently, the lookup table does not support different data 
types between
+                // the <expr> and the "when" values. If that is the case, use 
that eval method
+                // as a fallback instead
+                if &self
+                    .body
+                    .expr
+                    .as_ref()
+                    .unwrap()
+                    .data_type(batch.schema_ref())?
+                    == lookup_table.when_data_type()
+                {
+                    self.with_lookup_table(batch, lookup_table)
+                } else {
+                    self.case_when_with_expr(batch, 
fallback_for_datatype_mismatch)
+                }

Review Comment:
   I don't like this for couple of reasons:
   1. `case_when_with_expr` can assume that it is being called when eval method 
is `WithExpression` (currently no use of self.eval in  `case_when_with_expr`)
   2. complicate stuff
   
   But I don't have a better idea, as we don't have schema before hand in the 
`new` function, and case expr can get different data types for when and expr 
(which I think it's wrong, but anyway)).
   
   doing cast will cause bugs as it can change the data, so while first I use 
cast in the `with_lookup_table` I moved from it



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

Reply via email to