Github user yhuai commented on a diff in the pull request:

    https://github.com/apache/spark/pull/14897#discussion_r82493549
  
    --- Diff: 
sql/core/src/test/scala/org/apache/spark/sql/execution/GlobalTempViewSuite.scala
 ---
    @@ -0,0 +1,168 @@
    +/*
    + * 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.execution
    +
    +import org.apache.spark.sql.{AnalysisException, QueryTest, Row}
    +import org.apache.spark.sql.catalog.Table
    +import org.apache.spark.sql.catalyst.TableIdentifier
    +import org.apache.spark.sql.catalyst.analysis.NoSuchTableException
    +import org.apache.spark.sql.test.SharedSQLContext
    +import org.apache.spark.sql.types.StructType
    +
    +class GlobalTempViewSuite extends QueryTest with SharedSQLContext {
    +  import testImplicits._
    +
    +  override protected def beforeAll(): Unit = {
    +    super.beforeAll()
    +    globalTempDB = spark.sharedState.globalTempViewManager.database
    +  }
    +
    +  private var globalTempDB: String = _
    +
    +  test("basic semantic") {
    +    sql("CREATE GLOBAL TEMP VIEW src AS SELECT 1, 'a'")
    +
    +    // If there is no database in table name, we should try local temp 
view first, if not found,
    +    // try table/view in current database, which is "default" in this 
case. So we expect
    +    // NoSuchTableException here.
    +    intercept[NoSuchTableException](spark.table("src"))
    +
    +    // Use qualified name to refer to the global temp view explicitly.
    +    checkAnswer(spark.table(s"$globalTempDB.src"), Row(1, "a"))
    +
    +    // Table name without database will never refer to a global temp view.
    +    intercept[NoSuchTableException](sql("DROP VIEW src"))
    +
    +    sql(s"DROP VIEW $globalTempDB.src")
    +    // The global temp view should be dropped successfully.
    +    intercept[NoSuchTableException](spark.table(s"$globalTempDB.src"))
    +
    +    // We can also use Dataset API to create global temp view
    +    Seq(1 -> "a").toDF("i", "j").createGlobalTempView("src")
    +    checkAnswer(spark.table(s"$globalTempDB.src"), Row(1, "a"))
    +
    +    // Use qualified name to rename a global temp view.
    +    sql(s"ALTER VIEW $globalTempDB.src RENAME TO src2")
    --- End diff --
    
    Should we do `sql(s"ALTER VIEW $globalTempDB.src RENAME TO 
$globalTempDB.src2")` since we always require operating global temp views using 
qualified identifiers?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to