fix: fold exprs within tuple_map evaluation#5877
Conversation
prql-bot
left a comment
There was a problem hiding this comment.
The fix correctly addresses the panic by folding each mapped FuncCall eagerly, and the test exercises the failure case from the description.
One suggestion on the error handling. The match with Err(_) => expr fallback silently discards real resolver errors (e.g. arity mismatch when the mapped function takes more than one arg) and falls back to the original unfolded FuncCall — which is exactly the shape that triggers the lineage-calculation panic this PR aims to prevent. So in the error path the user loses the diagnostic and may still hit the panic.
Every other fold_expr call in this file propagates with ?. Doing the same here keeps the behavior consistent and surfaces legitimate errors to the user. I verified the suggested form compiles and that test_tuple_map plus the std.prql join/tuple_every(tuple_map …) paths still produce identical SQL.
The following PRQL fails with a panic during compilation:
The error is:
The ultimate cause is that the invocation of
tuple_mapdoes not directly produce a tuple of evaluated results, but rather produces a tuple ofExprKind::FuncCallinstances. Those FuncCall instances are not expected at time of lineage calculation (where the panic happens intransforms.rs).The only place where
tuple_mapis currently used is instd.prql, for example:prql/prqlc/prqlc/src/semantic/std.prql
Lines 122 to 126 in 2c0465a
In the above case,
tuple_mapis being wrapped intuple_every, which effectively triggers a fold of the FuncCall instances that it returns (somehow... I'm not sure how, exactly). However, whentuple_mapis used on its own, those FuncCall instances are not evaluated as expected.This PR updates the implementation of
tuple_mapso that the FuncCall instances generated through the map process are folded immediately after they are created, ensuring that they are not propagated through to lineage calculation.