GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(dataframe): expose the executed physical plan with per-operator metrics by LantaoJin · Pull Request #97 · apache/datafusion-java

Conversation

@LantaoJin

@LantaoJin LantaoJin commented May 26, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

  • Closes feat(dataframe): expose the executed physical plan with per-operator metrics #96 .

Rationale for this change

df.explain(true, true) already runs the plan and attaches per-operator metrics, but the result is a DataFrame of text rows. Programmatic consumers — query-shape regression tests, operational audit feeds, build-time benchmarks — have to scrape output_rows=12345, elapsed_compute=4.2ms strings out of those rows. Brittle to upstream wording, ergonomically painful, and the typed metric values (Count, Time, Gauge) lose their type along the way.

This PR adds a typed accessor df.executedPlan() that returns an immutable ExecutedPlan tree once the DataFrame has been executed via collect() / executeStream(). Each node carries the operator name, a one-line display rendering, child nodes, and an OperatorMetrics POJO with OptionalLong fields for the well-known metric variants plus a Map<String, Long> for custom counters.

try (DataFrame df = ctx.sql("SELECT count(*) FROM events");
     ArrowReader r = df.collect(allocator)) {
    while (r.loadNextBatch()) { /* drain */ }
}
ExecutedPlan plan = df.executedPlan();
long rows = plan.metrics().outputRows().orElse(-1L);

The contract is post-mortem: executedPlan() requires a prior collect / executeStream and rejects with IllegalStateException("call collect() or executeStream() first") if called pre-execution. A future PR can extend the surface to make pre-execution structure inspection available too — that follow-up is intentionally out of scope here to keep this PR focused on the metric-snapshot surface.

What changes are included in this PR?

  • New public records ExecutedPlan and OperatorMetrics.
  • New DataFrame.executedPlan() method.
  • New proto/executed_plan.proto (ExecutedPlanNodeProto).
  • Native side: executed_plan.rs.
  • Java-side: one new final long planId field assigned at construction.

Out of scope (deferred to follow-up PRs):

  • Per-partition metric breakdown.
  • Time/Gauge-shaped custom metrics; v1 surfaces Count-shaped customs only.

Are these changes tested?

Yes. 10 new tests in the ExecutedPlanTest.

Are there any user-facing changes?

Yes, additive only -- no behavior changes for existing callers.

  • New public types ExecutedPlan and OperatorMetrics (records).
  • New DataFrame.executedPlan() method.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@LantaoJin
feat(dataframe): expose the executed physical plan with per-operator …
71c19cc
…metrics
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

feat(dataframe): expose the executed physical plan with per-operator metrics

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@LantaoJin
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.