René's URL Explorer Experiment


Title: feat: add Java scalar UDF support by andygrove · Pull Request #46 · apache/datafusion-java · GitHub

Open Graph Title: feat: add Java scalar UDF support by andygrove · Pull Request #46 · apache/datafusion-java

X Title: feat: add Java scalar UDF support by andygrove · Pull Request #46 · apache/datafusion-java

Description: Which issue does this PR close? N/A Rationale for this change Add support for implement scalar UDFs in Java. What changes are included in this PR? Public Java API ScalarUdf @FunctionalInterface with one method FieldVector evaluate(BufferAllocator allocator, List args) Volatility enum (IMMUTABLE / STABLE / VOLATILE) SessionContext.registerUdf(name, udf, returnType, argTypes, volatility) Internals org.apache.datafusion.internal.JniBridge — per-call static trampoline that imports the input columns, calls user code, validates (non-null + row count), and exports the result via the Arrow C Data Interface native/src/udf.rs — JavaScalarUdf implementing DataFusion's ScalarUDFImpl. Holds GlobalRefs to the user instance + bridge class and a cached JStaticMethodID; constructs an FFI struct-array view of the args, attaches the current thread to JNI, calls the bridge, translates any pending Java exception into a DataFusionError::Execution, imports the result via arrow::ffi::from_ffi, and validates the type matches the declared return type JNI_OnLoad in native/src/lib.rs caches the JavaVM* in a OnceLock so DataFusion's worker threads can attach Refinements from the design discussion Args ride a single FFI struct pair (FFI_ArrowArray + FFI_ArrowSchema for a struct-array view of the columns), not an ArrowArrayStream — v1 always sees one batch per invoke and the simpler ABI avoids streaming overhead. The per-call allocator is a single shared static RootAllocator on JniBridge rather than a fresh-per-call one — closing a per-call allocator while an FFI release callback still holds buffer references would throw. StructArray::try_new_with_length(... , number_rows) is used for the args export so a zero-argument UDF doesn't panic. number_rows is usize::try_into:: checked before crossing JNI — a batch larger than i32::MAX would otherwise silently truncate and miscompare with Java's row-count check. Docs + example docs/source/user-guide/scalar-udf.md (linked from the user-guide toctree) examples/src/main/java/org/apache/datafusion/examples/AddOneExample.java How are these changes tested? make test from a clean checkout. The new ScalarUdfTest has 12 tests covering: Happy paths: add_one(Int32), concat(Utf8, Utf8), square(Float64), repeated invocations in one session, a 100-row VALUES scan Contract violations: UDF returning null, wrong row count, wrong type, and a UDF that throws IllegalArgumentException — all surface as RuntimeExceptions with the expected message substrings (class name + user message preserved) Lifecycle: two UDFs registered in the same session, register-after-close in a new session Volatility: all three Volatility values round-trip through registration and execute correctly

Open Graph Description: Which issue does this PR close? N/A Rationale for this change Add support for implement scalar UDFs in Java. What changes are included in this PR? Public Java API ScalarUdf @FunctionalInterface wi...

X Description: Which issue does this PR close? N/A Rationale for this change Add support for implement scalar UDFs in Java. What changes are included in this PR? Public Java API ScalarUdf @FunctionalInterface wi...

Opengraph URL: https://github.com/apache/datafusion-java/pull/46

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.113.3

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:93269fa4-a78d-6c4c-64ff-c1c18c71aaf7
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idB954:3C4279:24EAC1:347839:6B046A40
html-safe-nonce25165ca1b268ceb49f7c18326fd31e843201407763ae0ce57c7af5efeb740cfa
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCOTU0OjNDNDI3OToyNEVBQzE6MzQ3ODM5OjZCMDQ2QTQwIiwidmlzaXRvcl9pZCI6IjI1ODc4NjgwNzg1NDExMzg0OTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac42256cd3aeb1b7b2d0b425a13914880b373d27baa559cf9b631999d1ce173e5f
hovercard-subject-tagpull_request:3679848072
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/apache/datafusion-java/pull/46/files
twitter:imagehttps://avatars.githubusercontent.com/u/934084?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/934084?s=400&v=4
og:image:altWhich issue does this PR close? N/A Rationale for this change Add support for implement scalar UDFs in Java. What changes are included in this PR? Public Java API ScalarUdf @FunctionalInterface wi...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None83e4c0e58c5162177f3c161c5fbad38527ae04c11ac14980f9f9d85ae2027b1f
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/apache/datafusion-java git https://github.com/apache/datafusion-java.git
octolytics-dimension-user_id47359
octolytics-dimension-user_loginapache
octolytics-dimension-repository_id1237105117
octolytics-dimension-repository_nwoapache/datafusion-java
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1237105117
octolytics-dimension-repository_network_root_nwoapache/datafusion-java
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseca4d07a7cef4e4b75f821dc25e7300d80c1450a9
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/apache/datafusion-java/pull/46/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fapache%2Fdatafusion-java%2Fpull%2F46%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fapache%2Fdatafusion-java%2Fpull%2F46%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=apache%2Fdatafusion-java
Reloadhttps://github.com/apache/datafusion-java/pull/46/files
Reloadhttps://github.com/apache/datafusion-java/pull/46/files
Reloadhttps://github.com/apache/datafusion-java/pull/46/files
apachehttps://github.com/apache
datafusion-javahttps://github.com/apache/datafusion-java
Codehttps://github.com/apache/datafusion-java
Issues10 (10)https://github.com/apache/datafusion-java/issues
Pull requests10 (10)https://github.com/apache/datafusion-java/pulls
Discussionshttps://github.com/apache/datafusion-java/discussions
Actionshttps://github.com/apache/datafusion-java/actions
Security and qualityhttps://github.com/apache/datafusion-java/security
Insightshttps://github.com/apache/datafusion-java/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fapache%2Fdatafusion-java%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fapache%2Fdatafusion-java%2Fissues%2Fnew%2Fchoose
andygrovehttps://github.com/andygrove
apache:mainhttps://github.com/apache/datafusion-java/tree/main
andygrove:feat/scalar-udfhttps://github.com/andygrove/datafusion-java/tree/feat/scalar-udf
Conversation 9 https://github.com/apache/datafusion-java/pull/46
Commits 14 https://github.com/apache/datafusion-java/pull/46/commits
Checks 2 https://github.com/apache/datafusion-java/pull/46/checks
Files changed https://github.com/apache/datafusion-java/pull/46/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/46/files
feat: add Java scalar UDF support https://github.com/apache/datafusion-java/pull/46/files#top
Show all changes 14 commits https://github.com/apache/datafusion-java/pull/46/files
7517f86 feat(native): cache JavaVM in OnceLock via JNI_OnLoad andygrove May 13, 2026 https://github.com/apache/datafusion-java/pull/46/commits/7517f86dc25edbabacc18bcb766f16f8b40b6795
52a2589 feat(udf): add ScalarUdf interface and Volatility enum andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/52a2589c5100535a8cf31c8c4aeb1b0f266b9374
10c32bb feat(udf): add JniBridge trampoline for per-call UDF invocation andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/10c32bbbd88470a52f39b48aa92207d7cdb1313d
b4df132 feat(native): add JavaScalarUdf skeleton implementing ScalarUDFImpl andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/b4df1325ebda20a203cb109707d13917e919a049
36ce35f feat(udf): register Java UDFs via SessionContext.registerUdf andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/36ce35ff0a84b8d3859ccc4003881e805353e05d
9d933c4 feat(udf): implement invoke_with_args via Arrow C Data Interface andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/9d933c471bc54ccd10740419f4827b15c54d2316
264bcb0 fix(udf): plug exception leak, add SAFETY comment, validate row count… andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/264bcb0f61ed610fb06f4d649dd62f7f117d4a11
742629c test(udf): cover concat, square, and repeated invocations andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/742629c1f42d170fa9c51bfde6a3c203c1a28bdc
cf187a3 test(udf): cover null/wrong-rows/wrong-type/exception contract violat… andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/cf187a3250cad238c0cadd51b0bd03b14d6cd047
4ef01fd test(udf): cover multi-UDF, cross-session, and multi-row lifecycle andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/4ef01fdc6af20a21c6fa6cf9568b503dca25eb89
086cba7 test(udf): exercise all three Volatility kinds andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/086cba7e121c28fe4ab9a2d7339812ce41dc3538
0d06aa5 docs(udf): add user-guide page and runnable AddOne example andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/0d06aa549d7abd3056633aa229bfe337a89877b7
296b3be refactor(udf): null-guard registerUdf arguments and drop dead assertion andygrove May 14, 2026 https://github.com/apache/datafusion-java/pull/46/commits/296b3beb83cd168a21a9acfab83bf0ff1a87e320
d1c9803 refactor(udf): split ScalarUdf into ScalarFunction impl iface and hol… andygrove May 17, 2026 https://github.com/apache/datafusion-java/pull/46/commits/d1c9803eeeaa3a1fc5d97c7d43c236eef3008fdb
Clear filters https://github.com/apache/datafusion-java/pull/46/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/46/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/46/files
ScalarFunction.java https://github.com/apache/datafusion-java/pull/46/files#diff-bd89b23d6028824ee8aa496782bd8683b521588c78f471de76829dd3a74aadd3
ScalarUdf.java https://github.com/apache/datafusion-java/pull/46/files#diff-4e8a48ce1cf63fee2680588a132d8b235f86ba7c44a2afb9c817dd738a2c4de7
SessionContext.java https://github.com/apache/datafusion-java/pull/46/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
Volatility.java https://github.com/apache/datafusion-java/pull/46/files#diff-d8124c6b64df558f19f3cb95d577d0db531a86a6a8c8ed42c87547e26a733e32
JniBridge.java https://github.com/apache/datafusion-java/pull/46/files#diff-d8782084eee38e7e495ad13caf3a16d2c19b6eb7a1c290c9423e4d7224a5f2f3
DataFrameTransformationsTest.java https://github.com/apache/datafusion-java/pull/46/files#diff-0f4d6c073f539bbb3655a39b796b32698df9adc312c08e5ddb99d31c3ecb7923
ScalarUdfTest.java https://github.com/apache/datafusion-java/pull/46/files#diff-44b18e4a141ffd448eb762005708913dfd7d6209335637e5fdf6291a63410b26
index.md https://github.com/apache/datafusion-java/pull/46/files#diff-c5d556935b075b3f69ce1807990a7d6a6c59e8ecb075ffdceb6d96bdea1e1ec0
scalar-udf.md https://github.com/apache/datafusion-java/pull/46/files#diff-0c0208f26eacc9b3a2c6e9c178bc140ab31ff32d4d097b4971bfda47674626e9
AddOneExample.java https://github.com/apache/datafusion-java/pull/46/files#diff-69812f77b37e69bcc057b6c77b21304b26cf9af77d2692a827e3ca28188e4222
lib.rs https://github.com/apache/datafusion-java/pull/46/files#diff-697685fba8d3d4a3a8a287bad6e1369e50e1c98bd878823415758c2a642cbb6e
udf.rs https://github.com/apache/datafusion-java/pull/46/files#diff-1c9a0800b6151fc16f2965eb70c73bcf80208567d7d14d2f6f28de9f59cdda8a
core/src/main/java/org/apache/datafusion/ScalarFunction.javahttps://github.com/apache/datafusion-java/pull/46/files#diff-bd89b23d6028824ee8aa496782bd8683b521588c78f471de76829dd3a74aadd3
View file https://github.com/andygrove/datafusion-java/blob/d1c9803eeeaa3a1fc5d97c7d43c236eef3008fdb/core/src/main/java/org/apache/datafusion/ScalarFunction.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/46/{{ revealButtonHref }}
core/src/main/java/org/apache/datafusion/ScalarUdf.javahttps://github.com/apache/datafusion-java/pull/46/files#diff-4e8a48ce1cf63fee2680588a132d8b235f86ba7c44a2afb9c817dd738a2c4de7
View file https://github.com/andygrove/datafusion-java/blob/d1c9803eeeaa3a1fc5d97c7d43c236eef3008fdb/core/src/main/java/org/apache/datafusion/ScalarUdf.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/46/{{ revealButtonHref }}
core/src/main/java/org/apache/datafusion/SessionContext.javahttps://github.com/apache/datafusion-java/pull/46/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
View file https://github.com/andygrove/datafusion-java/blob/d1c9803eeeaa3a1fc5d97c7d43c236eef3008fdb/core/src/main/java/org/apache/datafusion/SessionContext.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/46/{{ revealButtonHref }}
https://github.com/apache/datafusion-java/pull/46/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/46/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/46/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/46/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/46/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
core/src/main/java/org/apache/datafusion/Volatility.javahttps://github.com/apache/datafusion-java/pull/46/files#diff-d8124c6b64df558f19f3cb95d577d0db531a86a6a8c8ed42c87547e26a733e32
View file https://github.com/andygrove/datafusion-java/blob/d1c9803eeeaa3a1fc5d97c7d43c236eef3008fdb/core/src/main/java/org/apache/datafusion/Volatility.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/46/{{ revealButtonHref }}
core/src/main/java/org/apache/datafusion/internal/JniBridge.javahttps://github.com/apache/datafusion-java/pull/46/files#diff-d8782084eee38e7e495ad13caf3a16d2c19b6eb7a1c290c9423e4d7224a5f2f3
View file https://github.com/andygrove/datafusion-java/blob/d1c9803eeeaa3a1fc5d97c7d43c236eef3008fdb/core/src/main/java/org/apache/datafusion/internal/JniBridge.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/46/{{ revealButtonHref }}
core/src/test/java/org/apache/datafusion/DataFrameTransformationsTest.javahttps://github.com/apache/datafusion-java/pull/46/files#diff-0f4d6c073f539bbb3655a39b796b32698df9adc312c08e5ddb99d31c3ecb7923
View file https://github.com/andygrove/datafusion-java/blob/d1c9803eeeaa3a1fc5d97c7d43c236eef3008fdb/core/src/test/java/org/apache/datafusion/DataFrameTransformationsTest.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/46/{{ revealButtonHref }}
https://github.com/apache/datafusion-java/pull/46/files#diff-0f4d6c073f539bbb3655a39b796b32698df9adc312c08e5ddb99d31c3ecb7923
https://github.com/apache/datafusion-java/pull/46/files#diff-0f4d6c073f539bbb3655a39b796b32698df9adc312c08e5ddb99d31c3ecb7923
Please reload this pagehttps://github.com/apache/datafusion-java/pull/46/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/46/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlno-cache

Viewport: width=device-width


URLs of crawlers that visited me.