Title: bug(udf): scalar UDFs over nested Arrow types cannot be registered · Issue #58 · apache/datafusion-java · GitHub
Open Graph Title: bug(udf): scalar UDFs over nested Arrow types cannot be registered · Issue #58 · apache/datafusion-java
X Title: bug(udf): scalar UDFs over nested Arrow types cannot be registered · Issue #58 · apache/datafusion-java
Description: Describe the bug ScalarFunction.argTypes() returns List
Open Graph Description: Describe the bug ScalarFunction.argTypes() returns List
X Description: Describe the bug ScalarFunction.argTypes() returns List<ArrowType> and returnType() returns ArrowType (core/src/main/java/org/apache/datafusion/ScalarFunction.java:47, :50). Java Arrow's ...
Opengraph URL: https://github.com/apache/datafusion-java/issues/58
X: @github
Domain: github.com
IPv4 address: 140.82.114.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"bug(udf): scalar UDFs over nested Arrow types cannot be registered","articleBody":"### Describe the bug\n\n`ScalarFunction.argTypes()` returns `List\u003cArrowType>` and `returnType()` returns `ArrowType` (`core/src/main/java/org/apache/datafusion/ScalarFunction.java:47, :50`). Java Arrow's `ArrowType` is a *leaf marker* for the type kind: for primitives like `Int32` or `Float64` it is self-describing, but for nested types (`List`, `Struct`, `Map`, `FixedSizeList`) the element / member / key / value types live on the parent `Field`'s `children` list, not inside `ArrowType` itself. `ArrowType.List` is literally a no-field marker class.\n\nThat mismatch means a Java UDF author has no way to declare a typed nested signature. The closest they can write is:\n\n```java\npublic List\u003cArrowType> argTypes() {\n return List.of(new ArrowType.List()); // says \"list\" -- cannot say \"of Int32\"\n}\n```\n\nWhen this is passed to `SessionContext.registerUdf(ScalarUdf)` the registration path at `core/src/main/java/org/apache/datafusion/SessionContext.java:385-389` constructs the signature schema as:\n\n```java\nfields.add(new Field(\"return\", FieldType.nullable(returnType), null));\nfor (int i = 0; i \u003c argTypes.size(); i++) {\n fields.add(new Field(\"arg\" + i, FieldType.nullable(argTypes.get(i)), null));\n}\n```\n\nThe `null` children list is the bug: Arrow's IPC writer rejects the malformed `List` field during `serializeSchemaIpc(...)` before the schema ever crosses JNI. The user sees a low-level `IllegalArgumentException: Lists have one child Field. Found: none`.\n\nThis blocks the entire family of nested-type UDFs that exist as built-ins in DataFusion's `datafusion-functions-nested` crate (`array_length`, `cardinality`, `array_has`, `array_position`, `flatten`, `map_keys`, `map_values`, `arrays_zip`, ...). Anyone porting Spark UDFs over `ArrayType` / `StructType` / `MapType` columns to DataFusion-Java hits this on the first attempt.\n\nThe Rust API does not have this problem: `DataType::List(Arc\u003cField>)` carries the child field inline, so `Signature::exact(vec![DataType::List(Arc::new(Field::new(\"item\", DataType::Int32, true)))], ...)` round-trips with full structure.\n\n### To Reproduce\n\n```java\nstatic final class ListLength implements ScalarFunction {\n public String name() { return \"java_list_length\"; }\n public List\u003cArrowType> argTypes() { return List.of(new ArrowType.List()); }\n public ArrowType returnType() { return new ArrowType.Int(32, true); }\n public Volatility volatility() { return Volatility.IMMUTABLE; }\n public FieldVector evaluate(BufferAllocator allocator, List\u003cFieldVector> args, int rowCount) {\n /* ... */\n }\n}\n\nnew SessionContext().registerUdf(new ScalarUdf(new ListLength()));\n// throws:\n// IllegalArgumentException: Lists have one child Field. Found: none\n// at SessionContext.serializeSchemaIpc(SessionContext.java:398)\n// at SessionContext.registerUdf(SessionContext.java:391)\n```\n\n### Expected behavior\n\nA UDF whose argument or return type is a nested Arrow type registers successfully and is callable from SQL with full element-type information preserved end-to-end (Java → JNI → Rust `Signature::exact`).\n\n### Additional context\n\n_No response_","author":{"url":"https://github.com/LantaoJin","@type":"Person","name":"LantaoJin"},"datePublished":"2026-05-18T07:46:26Z","url":"https://github.com/apache/datafusion-java/issues/58"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:b9d3b839-38d3-2828-0d9a-33dc5e267394 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 830E:2352D8:7F3B3:B2146:6B046A0F |
| html-safe-nonce | df8130994b642ae65e5dbaa4226a7af33a13520aef14c63534ff628c87645df7 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzBFOjIzNTJEODo3RjNCMzpCMjE0Njo2QjA0NkEwRiIsInZpc2l0b3JfaWQiOiI0ODY3MjY3NzM0MzIyNTcxNzkxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 89c27120a41f5df8a07c96a46d57301e389673bb712725da873fe531d419bebf |
| hovercard-subject-tag | issue:4467235663 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/apache/datafusion-java/58/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7ef6c2981af01d8cb8fd457f3965d48cd5d994e28af6f7ea00af09b4e0a9ce20/apache/datafusion-java/issues/58 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7ef6c2981af01d8cb8fd457f3965d48cd5d994e28af6f7ea00af09b4e0a9ce20/apache/datafusion-java/issues/58 |
| og:image:alt | Describe the bug ScalarFunction.argTypes() returns List |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | LantaoJin |
| hostname | github.com |
| expected-hostname | github.com |
| None | 83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f |
| turbo-cache-control | no-preview |
| go-import | github.com/apache/datafusion-java git https://github.com/apache/datafusion-java.git |
| octolytics-dimension-user_id | 47359 |
| octolytics-dimension-user_login | apache |
| octolytics-dimension-repository_id | 1237105117 |
| octolytics-dimension-repository_nwo | apache/datafusion-java |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1237105117 |
| octolytics-dimension-repository_network_root_nwo | apache/datafusion-java |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ca4d07a7cef4e4b75f821dc25e7300d80c1450a9 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width