gengliangwang commented on code in PR #51080:
URL: https://github.com/apache/spark/pull/51080#discussion_r2130879866


##########
sql/pipelines/src/main/scala/org/apache/spark/sql/pipelines/graph/SqlGraphRegistrationContext.scala:
##########
@@ -0,0 +1,675 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.sql.pipelines.graph
+
+import scala.collection.mutable
+
+import org.apache.spark.{SparkException, SparkRuntimeException}
+import org.apache.spark.sql.{AnalysisException, SparkSession}
+import org.apache.spark.sql.catalyst.analysis.UnresolvedRelation
+import org.apache.spark.sql.catalyst.plans.logical.{CreateFlowCommand, 
CreateMaterializedViewAsSelect, CreateStreamingTable, 
CreateStreamingTableAsSelect, CreateView, InsertIntoStatement, LogicalPlan}
+import org.apache.spark.sql.catalyst.util.StringUtils
+import org.apache.spark.sql.execution.command.{CreateViewCommand, 
SetCatalogCommand, SetCommand, SetNamespaceCommand}
+import org.apache.spark.sql.pipelines.{Language, QueryOriginType}
+import org.apache.spark.sql.types.StructType
+
+/**
+ * Data class for all state that is accumulated while processing a particular
+ * [[SqlGraphRegistrationContext]].
+ *
+ * @param initialCatalogOpt The initial catalog to assume.
+ * @param initialDatabaseOpt The initial database to assume.
+ * @param initialSqlConf The initial sql confs to assume.
+ */
+class SqlGraphRegistrationContextState(
+    initialCatalogOpt: Option[String],
+    initialDatabaseOpt: Option[String],
+    initialSqlConf: Map[String, String]) {
+  private val sqlConf = mutable.HashMap[String, String](initialSqlConf.toSeq: 
_*)
+  private var currentCatalogOpt: Option[String] = initialCatalogOpt
+  private var currentDatabaseOpt: Option[String] = initialDatabaseOpt
+
+  def getSqlConf: Map[String, String] = sqlConf.toMap
+  def getCurrentCatalogOpt: Option[String] = currentCatalogOpt
+  def getCurrentDatabaseOpt: Option[String] = currentDatabaseOpt
+
+  def setSqlConf(k: String, v: String): Unit = sqlConf.put(k, v)
+  def setCurrentCatalog(catalogName: String): Unit = {
+    currentCatalogOpt = Option(catalogName)
+  }
+  def setCurrentDatabase(databaseName: String): Unit = {
+    currentDatabaseOpt = Option(databaseName)
+  }
+  def clearCurrentDatabase(): Unit = {
+    currentDatabaseOpt = None
+  }
+}
+
+case class SqlGraphElementRegistrationException(
+    msg: String,
+    queryOrigin: QueryOrigin) extends AnalysisException(
+  errorClass = "PIPELINE_SQL_GRAPH_ELEMENT_REGISTRATION_ERROR",
+  messageParameters = Map(
+    "message" -> msg,
+    "offendingQuery" -> 
SqlGraphElementRegistrationException.offendingQueryString(queryOrigin),
+    "codeLocation" -> 
SqlGraphElementRegistrationException.codeLocationStr(queryOrigin)
+  )
+)
+
+object SqlGraphElementRegistrationException {
+  private def codeLocationStr(queryOrigin: QueryOrigin): String = 
queryOrigin.filePath match {
+    case Some(fileName) =>
+      queryOrigin.line match {
+        case Some(lineNumber) =>
+          s"Query defined at $fileName:$lineNumber"
+        case None =>
+          s"Query defined in file $fileName"
+      }
+    case None => ""
+  }
+
+  private def offendingQueryString(queryOrigin: QueryOrigin): String = 
queryOrigin.sqlText match {
+    case Some(sqlText) =>
+      s"""
+         |Offending query:
+         |${sqlText}
+         |""".stripMargin
+    case None => ""
+  }
+}
+
+/**
+ * SQL statement processor context. At any instant, an instance of this class 
holds the "active"
+ * catalog/schema in use within this SQL statement processing context, and 
tables/views/flows that
+ * have been registered from SQL statements within this context.
+ */
+class SqlGraphRegistrationContext(
+    graphRegistrationContext: GraphRegistrationContext
+) {

Review Comment:
   class SqlGraphRegistrationContext(graphRegistrationContext: 
GraphRegistrationContext) {



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

To unsubscribe, e-mail: [email protected]

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