Inf1mum opened a new pull request, #27519:
URL: https://github.com/apache/datafusion/pull/27519

   ## Rationale
   
   `ExpressionPlacement::MoveTowardsLeafNodes` is documented as a performance 
hint, but the optimizer also evaluates such expressions on rows the query would 
never call them on:
   
   - `ExtractLeafExpressions` lifts them out of conditional sub-expressions 
(for example the branches of a `CASE`) into an extraction projection evaluated 
for every input row;
   - `PushDownLeafProjections` then pushes that projection below `Filter` 
nodes, so the expression also runs on rows the filter removes.
   
   A UDF that returns this placement because it is cheap, but errors on some 
inputs, can therefore make the whole query fail even though `CASE` and `WHERE` 
semantics say those inputs are never evaluated. Neither the placement variant 
nor `ScalarUDFImpl::placement` stated this requirement.
   
   ## What's changed
   
   Docs only, no behavior change:
   
   - `ExpressionPlacement::MoveTowardsLeafNodes`: add an "Evaluation contract" 
section stating that an expression with this placement may be evaluated on rows 
that enclosing filters or conditional expressions would exclude, so it must 
produce a value on every input row and must not have side effects.
   - `ExpressionPlacement::should_push_to_leaves`: point readers at the 
evaluation contract.
   - `ScalarUDFImpl::placement`: state the same requirement for implementors, 
and note that the built-in `get_field`, `input_file_name` and `file_row_index` 
already satisfy it. The same assumption is relied on at the physical level by 
#26589.
   
   ## Are these tests included?
   
   Docs-only change, so no behavioral tests. `cargo doc -p 
datafusion-expr-common` builds clean with `-D warnings` (intra-doc links 
resolve), and `cargo check -p datafusion-expr-common` / `-p datafusion-expr` 
pass.
   
   Fixes #27487


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