René's URL Explorer Experiment


Title: feat(table): add SessionContext.registerStreamingTable for push-mode batch ingest by LantaoJin · Pull Request #98 · apache/datafusion-java · GitHub

Open Graph Title: feat(table): add SessionContext.registerStreamingTable for push-mode batch ingest by LantaoJin · Pull Request #98 · apache/datafusion-java

X Title: feat(table): add SessionContext.registerStreamingTable for push-mode batch ingest by LantaoJin · Pull Request #98 · apache/datafusion-java

Description: Which issue does this PR close? Closes #95 . Rationale for this change PR #65 shipped a Java-implemented TableProvider and SessionContext.registerTable(String, TableProvider). That covered the pull shape: DataFusion calls scan(BufferAllocator) and reads the returned ArrowReader. For Java callers who already have batches in memory, or who can produce them on demand, that's the right surface. It does not cover the push shape that event-driven batch sources need: A coordinator reducing over shard responses arriving incrementally. A Flight stream feeding into a query. Any in-process producer that emits batches as side-effects of other work and doesn't know in advance how many will arrive. Bridging these into PR #65 today requires writing a BlockingArrowReader adapter that buffers pushed batches and serves them through the pull interface. That's a serialisation point: the producer blocks waiting for loadNextBatch(), or DataFusion blocks waiting for the next batch -- the two ends can never run truly concurrently. The adapter also has to invent its own backpressure, error propagation, end-of-stream signalling, and thread-safety story. DataFusion itself solves this on the Rust side with StreamingTable + PartitionStream plus an mpsc channel. This PR surfaces that exact shape from Java. What changes are included in this PR? New public Java API on SessionContext returning a typed sink: TableSink sink = ctx.registerStreamingTable("shard_results", schema, /* capacity */ 16); // Producer thread (any thread, including outside any Tokio runtime, and including a thread // that is itself a Tokio worker -- see "Tokio context detection" below): try { while (hasMoreInput()) { sink.write(batch); // backpressures when channel is full } sink.close(); // EOF: queries see end-of-stream cleanly } catch (Throwable t) { sink.fail(t); // signal error: queries see RuntimeException } public final class TableSink implements AutoCloseable { void write(VectorSchemaRoot batch); @Override void close(); void fail(Throwable cause); } After registration the table can be queried like any other: DataFrame df = ctx.sql("SELECT count(*) FROM shard_results"); ArrowReader r = df.collect(allocator); Single-scan semantics. The registered table can be queried at most once; subsequent scans against the same registration throw a RuntimeException. This matches the natural semantic for an event-driven producer (the data is consumed as it arrives) and avoids buffering every batch internally. Callers who need re-scan should use the pull-mode registerTable + SimpleTableProvider path from PR #65 instead. Documented loudly on registerStreamingTable's Javadoc and tested explicitly (secondScanThrows). Schema constraints (validated at registration). The schema passed to registerStreamingTable must: Have at least one column. Zero-column streaming would have no allocator to borrow for the FFI scratch; rejected up front rather than failing at first write. Have no dictionary-encoded fields at any depth (recursive walk through Field.getChildren()). Data.exportVectorSchemaRoot would otherwise NPE on the missing DictionaryProvider -- v1 cannot supply one. The error message names the dotted path (e.g. 'row.code') so nested violations are debuggable. A future overload that accepts a DictionaryProvider would lift this restriction; out of scope here. Native side, in a new native/src/streaming_table.rs. JNI handlers in native/src/lib.rs. The Java TableSink mirrors this with an AtomicLong nativeHandle and a ReentrantReadWriteLock over the lifetime; write() holds the read lock during the JNI call, close()/fail() flip the handle to 0 (forbidding new writes), call closeSinkNative/failSinkNative (waking parked writes), then take the write lock and call dropHandleNative (which now waits for all readers to drain). The TableSink.write Java path derives the FFI scratch allocator from the producer's batch (batch.getFieldVectors().get(0).getAllocator()) so the exported buffers share an allocator-root with the producer's vectors. Using a separate RootAllocator would make Data.exportVectorSchemaRoot reject the cross-root transfer. Cancellation propagates automatically: when DataFusion drops the consumer (query cancelled, LIMIT N short-circuits, error in another operator), the receiver is dropped, Sender::send resolves to Err(SendError), and the JNI handler surfaces that as a RuntimeException on the producer thread. Producers that ignore the exception leak no resources because the sender's Drop runs unconditionally. tokio-stream is added as a direct Cargo dependency (it was already pulled in transitively by datafusion-physical-plan; declaring it directly insulates us from transitive resolution drift). The tokio dependency gains the sync feature for Notify. Out of scope (for follow-ups): Multi-partition registerStreamingTable. StreamingTable::try_new accepts Vec>; an overload accepting multiple sinks is a small additive follow-up. try_write(batch) -> boolean -- non-blocking variant. Easy to add as a method on TableSink. Re-scannable streaming. Would force buffering every batch; defeats the use case. Use pull-mode registerTable instead. Dictionary-encoded fields. Would need a DictionaryProvider overload on registerStreamingTable. Tracked as a future enhancement. Are these changes tested? Yes -- 18 new tests in SessionContextStreamingTableTest. Are there any user-facing changes? Yes -- purely additive. New public API: org.apache.datafusion.TableSink (final, AutoCloseable) SessionContext.registerStreamingTable(String, Schema, int) -> TableSink No API removals, no deprecations, no behavior change for existing callers. The native binary picks up tokio-stream as a direct dep but it was already on the classpath transitively, so the binary size delta is zero. The tokio dependency gains the sync feature, which is small (Notify, mpsc).

Open Graph Description: Which issue does this PR close? Closes #95 . Rationale for this change PR #65 shipped a Java-implemented TableProvider and SessionContext.registerTable(String, TableProvider). That covered the pu...

X Description: Which issue does this PR close? Closes #95 . Rationale for this change PR #65 shipped a Java-implemented TableProvider and SessionContext.registerTable(String, TableProvider). That covered the pu...

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

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.4

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:90b48db4-2df4-231f-9a8f-c3f9079fadcc
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idA44C:2D066D:22F11F:2FFE5C:6B04681F
html-safe-nonce83ccab32a9ea13af2ee9bb478d6b0e307c0a92c553947db6d9ffe185e04a0b45
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNDRDOjJEMDY2RDoyMkYxMUY6MkZGRTVDOjZCMDQ2ODFGIiwidmlzaXRvcl9pZCI6IjMxODY1NTc4Mzc4MTE5MzUyNjMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac42d4b162b74e6dfac95aae91eb8f8129b37bef61997376cf2fd8759d22b23428
hovercard-subject-tagpull_request:3748931571
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/98/files
twitter:imagehttps://avatars.githubusercontent.com/u/1853780?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/1853780?s=400&v=4
og:image:altWhich issue does this PR close? Closes #95 . Rationale for this change PR #65 shipped a Java-implemented TableProvider and SessionContext.registerTable(String, TableProvider). That covered the pu...
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/98/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fapache%2Fdatafusion-java%2Fpull%2F98%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%2F98%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/98/files
Reloadhttps://github.com/apache/datafusion-java/pull/98/files
Reloadhttps://github.com/apache/datafusion-java/pull/98/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
LantaoJinhttps://github.com/LantaoJin
apache:mainhttps://github.com/apache/datafusion-java/tree/main
LantaoJin:feat/streaming-table-sinkhttps://github.com/LantaoJin/datafusion-java/tree/feat/streaming-table-sink
Conversation 0 https://github.com/apache/datafusion-java/pull/98
Commits 1 https://github.com/apache/datafusion-java/pull/98/commits
Checks 0 https://github.com/apache/datafusion-java/pull/98/checks
Files changed https://github.com/apache/datafusion-java/pull/98/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/98/files
feat(table): add SessionContext.registerStreamingTable for push-mode batch ingest https://github.com/apache/datafusion-java/pull/98/files#top
Show all changes 1 commit https://github.com/apache/datafusion-java/pull/98/files
852d12e feat(table): add SessionContext.registerStreamingTable for push-mode … LantaoJin May 26, 2026 https://github.com/apache/datafusion-java/pull/98/commits/852d12ee00561916f91519df851f76aa01d2a3ae
Clear filters https://github.com/apache/datafusion-java/pull/98/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/98/files
Please reload this pagehttps://github.com/apache/datafusion-java/pull/98/files
SessionContext.java https://github.com/apache/datafusion-java/pull/98/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
TableSink.java https://github.com/apache/datafusion-java/pull/98/files#diff-ffc9cb683e1b8364bab8b0b541861c2553a6e98607339cb0f1ac02cec70d7570
SessionContextStreamingTableTest.java https://github.com/apache/datafusion-java/pull/98/files#diff-10c06f90044cda78bca0eecb343dee4454e3a36ff83a5ffa8ee7c7cbb313d2fd
Cargo.lock https://github.com/apache/datafusion-java/pull/98/files#diff-078f375cfc74d2a2bae74160d7469389a54227046a6daec4edb0481597ec2aa8
Cargo.toml https://github.com/apache/datafusion-java/pull/98/files#diff-a1571d177cbc44d96f49c8f29b6340febcee141a0e26833931bcd78c5441fb55
lib.rs https://github.com/apache/datafusion-java/pull/98/files#diff-697685fba8d3d4a3a8a287bad6e1369e50e1c98bd878823415758c2a642cbb6e
streaming_table.rs https://github.com/apache/datafusion-java/pull/98/files#diff-cd97652b693ae9f11f70acd6488cb773faeea8b14cfbb5a8727b23b34ee3f45d
core/src/main/java/org/apache/datafusion/SessionContext.javahttps://github.com/apache/datafusion-java/pull/98/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
View file https://github.com/apache/datafusion-java/blob/852d12ee00561916f91519df851f76aa01d2a3ae/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/98/{{ revealButtonHref }}
https://github.com/apache/datafusion-java/pull/98/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/98/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
https://github.com/apache/datafusion-java/pull/98/files#diff-9aa9338a7364e93d5e2e4547564e7eb08e65a70f6d51b6fa896325cd4d87451e
core/src/main/java/org/apache/datafusion/TableSink.javahttps://github.com/apache/datafusion-java/pull/98/files#diff-ffc9cb683e1b8364bab8b0b541861c2553a6e98607339cb0f1ac02cec70d7570
View file https://github.com/apache/datafusion-java/blob/852d12ee00561916f91519df851f76aa01d2a3ae/core/src/main/java/org/apache/datafusion/TableSink.java
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/apache/datafusion-java/pull/98/{{ revealButtonHref }}
Please reload this pagehttps://github.com/apache/datafusion-java/pull/98/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.