Skip to content

Commit 027c9b0

Browse files
authored
chore: document programmatical access to fallback reasons (apache#4597)
1 parent 82d674e commit 027c9b0

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

docs/source/user-guide/latest/understanding-comet-plans.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,51 @@ operators were arranged after Comet's serialization). See the
138138
[Metrics Guide](metrics.md) for details on the native metrics that appear in
139139
this output.
140140

141+
## Programmatic Access to Fallback Reasons
142+
143+
The configs above route fallback reasons to logs or the SQL UI. If you want
144+
the reasons for a specific query as data — for example, to assert in a test
145+
or to drive a custom report — use `org.apache.comet.ExtendedExplainInfo`
146+
directly. It is the same class that backs `spark.comet.explain.format`, and
147+
it works on any Spark version because it does not rely on the Spark 4.0
148+
`extendedExplainProviders` extension point.
149+
150+
```scala
151+
import org.apache.comet.ExtendedExplainInfo
152+
153+
val df = spark.sql("SELECT ...")
154+
val plan = df.queryExecution.executedPlan
155+
val info = new ExtendedExplainInfo()
156+
157+
// Sorted, deduplicated list of fallback reasons across the whole plan.
158+
val reasons: Seq[String] = info.getFallbackReasons(plan)
159+
160+
// Formatted string. Honors spark.comet.explain.format:
161+
// - "verbose" -> the full plan annotated with per-node fallback reasons
162+
// - "fallback" -> just the list of reasons
163+
val formatted: String = info.generateExtendedInfo(plan)
164+
```
165+
166+
Example:
167+
168+
```
169+
val df = spark.sql("SELECT from_unixtime(eventTime) FROM events")
170+
171+
val plan = df.queryExecution.executedPlan
172+
val info = new org.apache.comet.ExtendedExplainInfo()
173+
println(info.generateExtendedInfo(plan))
174+
```
175+
176+
Output
177+
178+
```
179+
Project [COMET: from_unixtime(eventTime#5L, yyyy-MM-dd HH:mm:ss, Some(GMT)) is not fully compatible with Spark. To enable it anyway, set spark.comet.expression.FromUnixTime.allowIncompatible=true. For more information, refer to the Comet Compatibility Guide (https://datafusion.apache.org/comet/user-guide/compatibility.html).]
180+
+- CometNativeColumnarToRow
181+
+- CometNativeScan parquet
182+
183+
Comet accelerated 1 out of 2 eligible operators (50%). Final plan contains 1 transitions between Spark and Comet.
184+
```
185+
141186
## Comet Operator Reference
142187

143188
The following sections describe the Comet nodes you will see in plans, grouped

0 commit comments

Comments
 (0)