Adam-Alani opened a new pull request, #27476: URL: https://github.com/apache/datafusion/pull/27476
## Which issue does this PR close? - Closes #27475. ## Rationale for this change SQL evaluates `+`, `-`, `*`, `/`, `%`, and `power` from left to right. A producer can write a left spine as one n-ary Substrait call, for example `add(a, b, c, d)`, so the protobuf stays shallow. The consumer rebuilds that call as a balanced tree, so `((a + b) + c) + d` becomes `(a + b) + (c + d)`. Those shapes are not equal for floats. `power` misses this path entirely. It is a binary UDF, so an n-ary `power` call is passed every argument at once and does not match its two-argument signature. ## What changes are included in this PR? - `from_scalar_function` left-folds `add`, `subtract`, `multiply`, `divide`, `mod`, and `modulus` with more than two arguments, instead of calling `arg_list_to_binary_op_tree`. - An n-ary `power` call is folded into nested binary `power` calls before the generic UDF path. It looks up the `power` UDF, then `pow`. - `and` and `or` stay balanced. They are associative, and a balanced tree keeps a wide call shallow. ## Are these changes tested? Yes. `scalar_function.rs` now has: - `nary_arithmetic_is_left_folded` checks that a 4-argument call of each arithmetic operator is `(((1 op 2) op 3) op 4)`. - `nary_or_stays_balanced` checks that a 4-argument `or` is still a balanced tree. - `nary_power_is_left_folded` checks that a 4-argument `power` is nested binary `power` calls, left to right. `cargo test -p datafusion-substrait --lib logical_plan::consumer::expr::scalar_function` passed (11 tests), including the existing balanced-tree snapshots and the 50,000-argument `or` test. ## Are there any user-facing changes? Plans that contain an n-ary arithmetic call now evaluate left to right, matching SQL order. Float results can change. Integer results do not. An n-ary `power` call now plans instead of failing the UDF arity check. No public API change. -- 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]
