feat(dataframe): expose the executed physical plan with per-operator metrics
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 42/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
調査の方向性
Java DataFrame API と explain()、collect()、executeStream() で使用されるネイティブブリッジから開始し、物理 ExecutionPlan がどのように作成され保持されるかを追跡します。既存の EXPLAIN メトリクスパスと、要求されている ExecutedPlan および OperatorMetrics の形状を比較します。実行前後で同じプランを、オペレーターごとの型付きメトリクスとともに公開できれば完了です。
索引モデルが issue の本文から書いたものです。
説明
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)-- return aDataFrameof text rows describing the lazy logical plan (and optimised + physical plans whenverbose=true). Pre-execution. No metrics.df.explain(true, true)-- runs the plan, then returns aDataFrameof 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.2msetc.
Both 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.
DataFusion's Rust API exposes the underlying structure already: Arc<dyn ExecutionPlan> is a tree whose nodes have typed metrics() -> Option<MetricsSet> 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.
Describe the solution you'd like
A new DataFrame.executedPlan() returning a small immutable POJO tree, modelled on Spark's df.queryExecution.executedPlan:
record ExecutedPlan(
String name, // "HashAggregateExec" / "DataSourceExec" / etc.
String displayDetails, // single-line rendering, e.g. "filter=x > 1"
List<ExecutedPlan> children,
OperatorMetrics metrics) { }
record OperatorMetrics(
OptionalLong outputRows, // OutputRows summed across partitions; absent if the operator doesn't track this
OptionalLong elapsedComputeNanos, // ElapsedCompute summed across partitions
OptionalLong outputBytes,
OptionalLong outputBatches,
OptionalLong spillCount,
OptionalLong spilledBytes,
OptionalLong spilledRows,
OptionalLong currentMemoryUsage, // peak / latest Gauge value
Map<String, Long> customCounters) { // any MetricValue::Count(name) the operator emits
}
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.
To make "same plan, before-and-after" work end-to-end, the native side stashes the planned Arc<dyn 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.
try (DataFrame df = ctx.sql("SELECT count(*) FROM events WHERE ts > '2026-01-01'")) {
ExecutedPlan before = df.executedPlan(); // structure, zero metrics
System.out.println(before.name()); // "AggregateExec"
System.out.println(before.children().get(0).name()); // "DataSourceExec"
try (BufferAllocator alloc = new RootAllocator();
ArrowReader r = df.collect(alloc)) {
while (r.loadNextBatch()) { /* ... */ }
}
ExecutedPlan after = df.executedPlan(); // same tree, populated metrics
long rows = after.children().get(0).metrics().outputRows().orElse(-1L);
}
Describe alternatives you've considered
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.
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.
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.
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).
Additional context
No response
- 主要言語
- Java
- スター
- 32
- フォーク
- 12
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/datafusion-java のほかの issue
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
apache/datafusion-java#116 ·
-
難易度 5/5 1週間以上 初心者へのやさしさ 25/100
apache/datafusion-java#112 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 38/100
apache/datafusion-java#95 ·
-
Create first release オープンenhancement
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
apache/datafusion-java#86 · コメント 3 件 ·
-
enhancement
難易度 5/5 1週間以上 初心者へのやさしさ 45/100
apache/datafusion-java#68 ·
apache/datafusion-java の issue をすべて見る
似ている issue
-
bug untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
opensearch-project/ml-commons#5094 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
-
emitter:client:csharp feature
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
affects/8.10 affects/8.9 component/clients kind/bug likelihood/mid severity/mid
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
Two open-case totals on one screen: the Programs tile says 15,858 and the nav badge says 15,868 オープンbug frontend maui-pilot
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100