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



##########
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) }
+    query
+  }
+
+  private def isTempView(sparkSession: SparkSession, multiPartIdentifier: 
Seq[String]): Boolean = {
+    val globalTempDBName = df.sparkSession.conf.get(
+      org.apache.spark.sql.internal.StaticSQLConf.GLOBAL_TEMP_DATABASE)
+    val identifierForTempView = multiPartIdentifier match {
+      case Seq(dbName, tempViewName) if dbName.equals(globalTempDBName) =>
+        Seq(dbName, tempViewName)
+      case Seq(_, tempViewName) => Seq(tempViewName)
+      case ident => ident
     }
+    df.sparkSession.sessionState.catalog.isTempView(identifierForTempView)

Review comment:
       shall we simply call `...catalog.isTempView(multiPartIdentifier)`?




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