From 91a443b849e4d1ccc50a32b25fdd2bb502cf9b84 Mon Sep 17 00:00:00 2001
From: Shixiong Zhu <shixiong@databricks.com>
Date: Mon, 11 Jul 2016 18:11:06 -0700
Subject: [PATCH] [SPARK-16433][SQL] Improve StreamingQuery.explain when no
 data arrives

## What changes were proposed in this pull request?

Display `No physical plan. Waiting for data.` instead of `N/A`  for StreamingQuery.explain when no data arrives because `N/A` doesn't provide meaningful information.

## How was this patch tested?

Existing unit tests.

Author: Shixiong Zhu <shixiong@databricks.com>

Closes #14100 from zsxwing/SPARK-16433.
---
 .../spark/sql/execution/streaming/StreamExecution.scala       | 2 +-
 .../apache/spark/sql/streaming/FileStreamSourceSuite.scala    | 4 ++--
 .../scala/org/apache/spark/sql/streaming/StreamSuite.scala    | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StreamExecution.scala b/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StreamExecution.scala
index f1af79e738..c90dcc5680 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StreamExecution.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/StreamExecution.scala
@@ -477,7 +477,7 @@ class StreamExecution(
   /** Expose for tests */
   def explainInternal(extended: Boolean): String = {
     if (lastExecution == null) {
-      "N/A"
+      "No physical plan. Waiting for data."
     } else {
       val explain = ExplainCommand(lastExecution.logical, extended = extended)
       sparkSession.sessionState.executePlan(explain).executedPlan.executeCollect()
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSourceSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSourceSuite.scala
index 29ce578bcd..3d28d4f99c 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSourceSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/streaming/FileStreamSourceSuite.scala
@@ -672,8 +672,8 @@ class FileStreamSourceSuite extends FileStreamSourceTest {
       val q = df.writeStream.queryName("file_explain").format("memory").start()
         .asInstanceOf[StreamExecution]
       try {
-        assert("N/A" === q.explainInternal(false))
-        assert("N/A" === q.explainInternal(true))
+        assert("No physical plan. Waiting for data." === q.explainInternal(false))
+        assert("No physical plan. Waiting for data." === q.explainInternal(true))
 
         val tempFile = Utils.tempFileWith(new File(tmp, "text"))
         val finalFile = new File(src, tempFile.getName)
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamSuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamSuite.scala
index 28170f3064..1caafb9d74 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamSuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/streaming/StreamSuite.scala
@@ -251,8 +251,8 @@ class StreamSuite extends StreamTest {
     val q = df.writeStream.queryName("memory_explain").format("memory").start()
       .asInstanceOf[StreamExecution]
     try {
-      assert("N/A" === q.explainInternal(false))
-      assert("N/A" === q.explainInternal(true))
+      assert("No physical plan. Waiting for data." === q.explainInternal(false))
+      assert("No physical plan. Waiting for data." === q.explainInternal(true))
 
       inputData.addData("abc")
       q.processAllAvailable()
-- 
GitLab