jaceklaskowski commented on a change in pull request #26829:
URL: https://github.com/apache/spark/pull/26829#discussion_r458382019
##########
File path: sql/core/src/main/scala/org/apache/spark/sql/Dataset.scala
##########
@@ -522,36 +522,58 @@ class Dataset[T] private[sql](
// scalastyle:on println
/**
- * Prints the plans (logical and physical) to the console for debugging
purposes.
+ * Prints the plans (logical and physical) with a format specified by a
given explain mode.
*
* @group basic
- * @since 1.6.0
+ * @since 3.0.0
*/
- def explain(extended: Boolean): Unit = {
+ def explain(mode: ExplainMode): Unit = {
// Because temporary views are resolved during analysis when we create a
Dataset, and
// `ExplainCommand` analyzes input query plan and resolves temporary views
again. Using
// `ExplainCommand` here will probably output different query plans,
compared to the results
// of evaluation of the Dataset. So just output QueryExecution's query
plans here.
val qe = ExplainCommandUtil.explainedQueryExecution(sparkSession,
logicalPlan, queryExecution)
- val outputString =
- if (extended) {
- qe.toString
- } else {
+ val outputString = mode match {
+ case ExplainMode.Simple =>
qe.simpleString
- }
+ case ExplainMode.Extended =>
+ qe.toString
+ case ExplainMode.Codegen =>
+ try {
+
org.apache.spark.sql.execution.debug.codegenString(queryExecution.executedPlan)
+ } catch {
+ case e: AnalysisException => e.toString
+ }
+ case ExplainMode.Cost =>
+ qe.stringWithStats
+ case ExplainMode.Formatted =>
+ qe.simpleString(formatted = true)
+ }
// scalastyle:off println
println(outputString)
// scalastyle:on println
}
+ /**
+ * Prints the plans (logical and physical) to the console for debugging
purposes.
+ *
+ * @group basic
+ * @since 1.6.0
Review comment:
That should really be 3.0.0, no?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]