Title: feat(dataframe): expose the executed physical plan with per-operator metrics · Issue #96 · apache/datafusion-java · GitHub
Open Graph Title: feat(dataframe): expose the executed physical plan with per-operator metrics · Issue #96 · apache/datafusion-java
X Title: feat(dataframe): expose the executed physical plan with per-operator metrics · Issue #96 · apache/datafusion-java
Description: Is your feature request related to a problem or challenge? Today there are two ways to inspect the physical plan of a DataFrame, and neither is suitable for programmatic consumption: df.explain(false, false) / df.explain(true, false) -- ...
Open Graph Description: Is your feature request related to a problem or challenge? Today there are two ways to inspect the physical plan of a DataFrame, and neither is suitable for programmatic consumption: df.explain(fal...
X Description: Is your feature request related to a problem or challenge? Today there are two ways to inspect the physical plan of a DataFrame, and neither is suitable for programmatic consumption: df.explain(fal...
Opengraph URL: https://github.com/apache/datafusion-java/issues/96
X: @github
Domain: github.com
IPv4 address: 140.82.112.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"feat(dataframe): expose the executed physical plan with per-operator metrics","articleBody":"### Is your feature request related to a problem or challenge?\n\nToday there are two ways to inspect the physical plan of a `DataFrame`, and neither is suitable for programmatic consumption:\n\n1. **`df.explain(false, false)` / `df.explain(true, false)`** -- return a `DataFrame` of text rows describing the lazy logical plan (and optimised + physical plans when `verbose=true`). Pre-execution. No metrics.\n2. **`df.explain(true, true)`** -- runs the plan, then returns a `DataFrame` of text rows that includes per-operator metrics rendered as a string. Post-execution. Metrics are present but only as text -- `output_rows=12345, elapsed_compute=4.2ms` etc.\n\nBoth surface the plan as text rows. To answer \"did this query produce more output rows than the last run?\" or \"which operator spilled?\" today, callers run `df.explain(true, true).collect()` and *parse the strings*. Brittle to upstream wording, ergonomically painful, and the metric values lose their type.\n\nDataFusion's Rust API exposes the underlying structure already: `Arc\u003cdyn ExecutionPlan>` is a tree whose nodes have typed `metrics() -> Option\u003cMetricsSet>` accessors. The values are typed `Count`, `Time`, `Gauge`, `Timestamp`. None of that survives the trip into the existing `EXPLAIN` text. The gap is purely on the Java surface -- pre-execution and post-execution.\n\n### Describe the solution you'd like\n\nA new `DataFrame.executedPlan()` returning a small immutable POJO tree, modelled on Spark's `df.queryExecution.executedPlan`:\n\n```java\nrecord ExecutedPlan(\n String name, // \"HashAggregateExec\" / \"DataSourceExec\" / etc.\n String displayDetails, // single-line rendering, e.g. \"filter=x > 1\"\n List\u003cExecutedPlan> children,\n OperatorMetrics metrics) { }\n\nrecord OperatorMetrics(\n OptionalLong outputRows, // OutputRows summed across partitions; absent if the operator doesn't track this\n OptionalLong elapsedComputeNanos, // ElapsedCompute summed across partitions\n OptionalLong outputBytes,\n OptionalLong outputBatches,\n OptionalLong spillCount,\n OptionalLong spilledBytes,\n OptionalLong spilledRows,\n OptionalLong currentMemoryUsage, // peak / latest Gauge value\n Map\u003cString, Long> customCounters) { // any MetricValue::Count(name) the operator emits\n}\n```\n\n`executedPlan()` is **lazy** -- the call itself does not execute the query. It plans the DataFrame (forcing optimisation if not yet done) and returns a snapshot of the physical plan tree. Calling it before `collect()` / `executeStream()` returns the structure with zero-valued metrics. Calling it after returns the same structure with populated metrics. This matches Spark's shape: `df.queryExecution.executedPlan` is always available, and each node's `metrics` map fills in as the plan runs.\n\nTo make \"same plan, before-and-after\" work end-to-end, the native side stashes the planned `Arc\u003cdyn ExecutionPlan>` on the DataFrame handle. `collect()` and `executeStream()` use that stashed plan if present (instead of creating a new one each call). After execution, a second `executedPlan()` call returns the same tree with metrics populated -- by reference to the same plan -- not a freshly-replanned tree.\n\n```java\ntry (DataFrame df = ctx.sql(\"SELECT count(*) FROM events WHERE ts > '2026-01-01'\")) {\n ExecutedPlan before = df.executedPlan(); // structure, zero metrics\n System.out.println(before.name()); // \"AggregateExec\"\n System.out.println(before.children().get(0).name()); // \"DataSourceExec\"\n\n try (BufferAllocator alloc = new RootAllocator();\n ArrowReader r = df.collect(alloc)) {\n while (r.loadNextBatch()) { /* ... */ }\n }\n\n ExecutedPlan after = df.executedPlan(); // same tree, populated metrics\n long rows = after.children().get(0).metrics().outputRows().orElse(-1L);\n}\n```\n\n### Describe alternatives you've considered\n\n**Parse the text from `df.explain(true, true)`.** Cheapest implementation — no native API changes — but brittle to upstream wording. The whole motivation here is to avoid string-scraping.\n\n**Faithful 1:1 mirror of `MetricValue` variants.** A Java sealed type with one variant per upstream variant. More expressive, but pins the Java API to upstream's variant set; every DataFusion bump risks an API break. Going with the fixed set + `customCounters` map keeps the Java contract stable; the named getters cover every well-known variant, the map covers everything else.\n\n**Bundle into the existing `explain` text output.** Add structured metrics columns to the EXPLAIN-output DataFrame. Doesn't help the parsing problem; would need a separate type to carry typed values anyway.\n\n**Eager getter that runs the query if not already run.** `df.executedPlan()` would internally trigger materialisation when called before `collect()`. Surprising — a getter doing real work — and conflicts with the documented \"non-consuming\" pattern of the other introspection methods (`schema`, `explain`, `cache`, `describe`).\n\n### Additional context\n\n_No response_","author":{"url":"https://github.com/LantaoJin","@type":"Person","name":"LantaoJin"},"datePublished":"2026-05-26T08:10:13Z","url":"https://github.com/apache/datafusion-java/issues/96"}
| 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:adef78de-66aa-2a07-e3c9-b00a3bec96da |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C3F2:21700E:21B124:2E7811:6B0467EE |
| html-safe-nonce | 0d6668f72b769c02d453d13dc79bef082d5276fe8c788fb1768b26dfe6b2cf2a |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDM0YyOjIxNzAwRToyMUIxMjQ6MkU3ODExOjZCMDQ2N0VFIiwidmlzaXRvcl9pZCI6IjgzOTU1MDgwNTE0NDAwNjg1OTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 124014b4b137182e3082a4443c50de33c5c2c4857a4fe499fcab2d91a0ea2094 |
| hovercard-subject-tag | issue:4522561818 |
| 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/96/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c3f244edab48d943ae6ceb9e51b6d7e5d957f066110e34b8628b3316a135240a/apache/datafusion-java/issues/96 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c3f244edab48d943ae6ceb9e51b6d7e5d957f066110e34b8628b3316a135240a/apache/datafusion-java/issues/96 |
| og:image:alt | Is your feature request related to a problem or challenge? Today there are two ways to inspect the physical plan of a DataFrame, and neither is suitable for programmatic consumption: df.explain(fal... |
| 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