cloud-fan commented on a change in pull request #29767:
URL: https://github.com/apache/spark/pull/29767#discussion_r491827460



##########
File path: 
sql/core/src/main/scala/org/apache/spark/sql/streaming/DataStreamWriter.scala
##########
@@ -380,17 +381,44 @@ final class DataStreamWriter[T] private[sql](ds: 
Dataset[T]) {
         createV1Sink(optionsWithPath)
       }
 
-      df.sparkSession.sessionState.streamingQueryManager.startQuery(
-        extraOptions.get("queryName"),
-        extraOptions.get("checkpointLocation"),
-        df,
-        optionsWithPath.originalMap,
-        sink,
-        outputMode,
-        useTempCheckpointLocation = source == "console" || source == "noop",
-        recoverFromCheckpointLocation = true,
-        trigger = trigger)
+      startQuery(sink, optionsWithPath.originalMap)
+    }
+  }
+
+  private def startQuery(
+      sink: Table,
+      newOptions: Map[String, String],
+      resultDf: Option[DataFrame] = None,
+      recoverFromCheckpoint: Boolean = true): StreamingQuery = {
+    val queryName = extraOptions.get("queryName")
+    val checkpointLocation = extraOptions.get("checkpointLocation")
+    val useTempCheckpointLocation = 
SOURCES_ALLOW_ONE_TIME_QUERY.contains(source)
+
+    val query = df.sparkSession.sessionState.streamingQueryManager.startQuery(
+      queryName,
+      checkpointLocation,
+      df,
+      newOptions,
+      sink,
+      outputMode,
+      useTempCheckpointLocation = useTempCheckpointLocation,
+      recoverFromCheckpointLocation = recoverFromCheckpoint,
+      trigger = trigger)
+
+    resultDf.foreach { resDf => resDf.createOrReplaceTempView(query.name) }

Review comment:
       only the in-memory sink passes in `resultDf`. Shall we register temp 
view only in the `else if (source == "memory")`  branch?




----------------------------------------------------------------
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]

Reply via email to