felipecrv commented on issue #41094:
URL: https://github.com/apache/arrow/issues/41094#issuecomment-2087716483

   > Because if-else related expressions have a special execution order, should 
we extend ExecuteScalarIfElseExpression to handle such expressions separately?
   
   The solution should not be specific to if-then-else. Other constructs pose 
similar challenges (e.g. `CASE WHEN`):
   
   Velox (a vectorized query engine) calls these constructs "special forms". 
LISP uses the same terminology. Although `if` and `cond` look like function 
calls in Lisp [1][2], they are special in that not all arguments are eagerly 
evaluated:
   
   ```lisp
   (if (> den 0) (/ num den) 0)
   ```
   
   Other special forms are `and`, `or`, and `cond`:
   
   ```
   (and expr ...)
   (or expr ...)
   
   (cond [test-expr body ...+]
         ...)
   ```
   
   `and` is special because after the first `false` you get, you don't have to 
evaluate more input expressions. `or` is special because after the first `true` 
you get, you... `cond` is like `CASE .. WHEN` in SQL — a chain of 
if-then-else's.
   
   This can't be solved when `if_then_else` and `case_when` **are implemented 
as functions** in Arrow. We need to create special expression fragments that 
can receive unevaluated expressions as input parameters.
   
   They would look like `compute::Expression::Call` that can receive 
`compute::Expression` instances as parameters.
   
   
https://github.com/apache/arrow/blob/0d7fac0d49eae7f139735c3e7c9256fc304a698a/cpp/src/arrow/compute/expression.h#L136
   
   
   ```diff
   -  using Impl = std::variant<Datum, Parameter, Call>;
   +  using Impl = std::variant<Datum, Parameter, Call, Special>;
   ```
   
   ### Vectorized Evaluation of Special Forms
   
   Here I will try to expand on what @bkietz meant by "support for selection 
vectors".
   [1] https://courses.cs.northwestern.edu/325/readings/special-forms.html
   [2] https://docs.racket-lang.org/guide/conditionals.html
   


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