[branch-54] Fix evaluation of lambda with multiple parameters when some are unused (backport of #22853, adapted)#23660
Conversation
|
I don't understand this PR It claims to be a backport of However, that PR and this PR says:
Which I read to be that this isn't a user visible bug However, the PR contains a slt test that implies this is a user visible issue I think we need to explain more clearly what we are doing more clearly before backporting this to a release |
| } | ||
|
|
||
| fn register_multi_arg_lambda_udf(ctx: &SessionContext) { | ||
| #[derive(Debug, PartialEq, Eq, Hash)] |
There was a problem hiding this comment.
can we please add comments about the rationale for this function? It isn't at all clear to me
|
@alamb I did a quick read of the mainline PR description without giving it much attention before replicating it here, my bad. The public higher-order trait supports lambdas with multiple parameters but in the 54 release all built-in ones are single parameter, so this is only visible for user defined higher-order functions. I found a case in Sail, for example Any query like SELECT array_filter(a, (v, i) -> i > 1) -- first parameter not usedwould fail without the workaround Sail is using. I updated this PR description For context, before being merged, the |
Which issue does this PR close?
Adapted backport of #22853 (non-breaking). Note that the fix is totally different from the mainline PR
Rationale for this change
Despite all built-in higher-order functions being single parameter in the 54 release, the public higher-order trait supports lambdas with multiple parameters, which would trigger the bug. I found a case in Sail, for example
See mainline PR #22853 description as well
What changes are included in this PR?
Currently the lambda body and the captured record batch are projected to avoid copying uncaptured columns.
This PR instead replace uncaptured columns with cheap
NullArray's, so no projection is necessary, and therefore no wrong projection happens.In contrast, the mainline PR collects the lambda parameters that are actually used, and skips the evaluation and insertion of unused ones into the evalution batch, so no errors occurs (with the bonus of avoiding unused parameter evaluation at the cost of a breaking change)
Are these changes tested?
sqllogictests in new file
multi_arg_lambda.sltAre there any user-facing changes?
No