GH-37761: [R] Argument names ignored in schema supplied as in_type argument to register_scalar_function() - #51324
Conversation
|
|
There was a problem hiding this comment.
🟡 Changes recommended
Validation still bypasses explicitly declared arguments when a function also includes ....
Get a fresh assessment by requesting another Copilot review.
Pull request overview
Adds validation to ensure named UDF input schemas match function argument names.
Changes:
- Implements argument-name validation.
- Adds regression tests and snapshots.
- Updates documentation.
File summaries
| File | Description |
|---|---|
r/tests/testthat/test-udf.R |
Adds validation tests. |
r/tests/testthat/_snaps/udf.md |
Records validation output. |
r/R/udf.R |
Implements argument-name validation. |
r/man/register_scalar_function.Rd |
Documents naming requirements. |
Review details
Files not reviewed (1)
- r/man/register_scalar_function.Rd: Generated file
- Files reviewed: 3/4 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
8b9e111 to
063692f
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
Two moderate validation gaps remain in r/R/udf.R.
Review details
Files not reviewed (1)
- r/man/register_scalar_function.Rd: Generated file
Suppressed comments (2)
r/R/udf.R:171
- When a later kernel has more fields than
fun, indexingfun_arg_namespast its length yieldsNA;any()then returnsNAandisTRUE()suppresses the mismatch. For example,function(context, x)withlist(schema(x = int32()), schema(x = int32(), y = int32()))passes this new name check and produces an invalidarrow_scalar_function; treat named positions beyondfun_arg_namesas mismatches (and add a regression test).
isTRUE(any(nzchar(nms) & nms != fun_arg_names[seq_along(nms)]))
r/R/udf.R:166
- Because the name check is gated by
!fun_formals_have_dots, any function with...bypasses it—evenfunction(context, x, ...), wherexis a fixed positional argument. For example,schema(blah = int32())is still silently accepted for that function, so the bug this PR targets remains for mixed fixed/ellipsis formals. Restrict the exemption to the ellipsis portion and validate explicit formals before it.
if (!fun_formals_have_dots) {
fun_arg_names <- names(formals(fun))[-1]
- Files reviewed: 3/4 changed files
- Comments generated: 0 new
- Review effort level: Lite
There was a problem hiding this comment.
🟢 Approval recommended
The validation is correctly implemented and documented, and the added tests/snapshots cover the new behavior and expected error messaging.
Review details
Files not reviewed (1)
- r/man/register_scalar_function.Rd: Generated file
- Files reviewed: 3/4 changed files
- Comments generated: 0 new
- Review effort level: Lite
Rationale for this change
No validation/warning makes it easy for incorrectly specified UDFs to appear to work...but they don't!
What changes are included in this PR?
Validation
Are these changes tested?
Yeah
Are there any user-facing changes?
I guess if they have incorrectly specified UDFs, yeah
AI usage
All of it, we talked tho
in_typeargument toregister_scalar_function()#37761