ayushbilala commented on code in PR #59235:
URL: https://github.com/apache/spark/pull/59235#discussion_r4246289407
##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/v1/ShowViewsSuite.scala:
##########
@@ -17,6 +17,83 @@
package org.apache.spark.sql.execution.command.v1
+import org.apache.spark.sql.AnalysisException
import org.apache.spark.sql.execution.command
-class ShowViewsSuite extends command.ShowViewsSuiteBase with
ViewCommandSuiteBase
+/**
+ * Temp views live in the session catalog only, so they are covered here
rather than in the
+ * unified `ShowViewsSuiteBase`.
+ */
+class ShowViewsSuite extends command.ShowViewsSuiteBase with
ViewCommandSuiteBase {
+
+ test("AS JSON reports a local temp view as temporary") {
+ withTempView("v_json_local_temp") {
+ sql("CREATE TEMPORARY VIEW v_json_local_temp AS SELECT 1 AS x")
+ val views = showViewsAsJson(s"SHOW VIEWS IN $catalog.$namespace AS JSON")
+ val temp = views.filter(v => (v \ "viewName").extract[String] ==
"v_json_local_temp")
+ assert(temp.length == 1, s"expected exactly one entry:
${viewNames(views)}")
+ assert((temp.head \ "isTemporary").extract[Boolean])
+ // A local temp view belongs to no database, so its namespace is empty.
+ assert((temp.head \ "namespace").extract[Seq[String]].isEmpty)
+ }
+ }
+
+ test("AS JSON lists global temp views under the global temp database") {
+ withGlobalTempView("v_json_global_temp") {
+ sql("CREATE GLOBAL TEMPORARY VIEW v_json_global_temp AS SELECT 1 AS x")
+ val globalTempDb = spark.sharedState.globalTempDB
+ val views = showViewsAsJson(s"SHOW VIEWS IN $globalTempDb AS JSON")
+ val temp = views.filter(v => (v \ "viewName").extract[String] ==
"v_json_global_temp")
+ assert(temp.length == 1, s"expected exactly one entry:
${viewNames(views)}")
+ assert((temp.head \ "isTemporary").extract[Boolean])
+ assert((temp.head \ "namespace").extract[Seq[String]] ==
Seq(globalTempDb))
+ }
+ }
+
+ test("AS JSON agrees with the tabular output for a global temp view") {
+ withGlobalTempView("v_json_global_parity") {
+ sql("CREATE GLOBAL TEMPORARY VIEW v_json_global_parity AS SELECT 1 AS x")
+ val globalTempDb = spark.sharedState.globalTempDB
+ val expected = sql(s"SHOW VIEWS IN $globalTempDb").collect()
+ .map(r => (r.getString(0), r.getString(1), r.getBoolean(2))).toSet
+ val actual = showViewsAsJson(s"SHOW VIEWS IN $globalTempDb AS JSON").map
{ v =>
+ ((v \ "namespace").extract[Seq[String]].mkString("."),
+ (v \ "viewName").extract[String],
+ (v \ "isTemporary").extract[Boolean])
+ }.toSet
+ assert(actual == expected)
+ }
+ }
+
+ test("AS JSON without IN or FROM uses the current namespace") {
+ sql(s"USE $catalog.$namespace")
Review Comment:
Rewrote it to create a separate namespace, USE it, create a view there, and
also create a view that exists only in default. the test now asserts the first
view is listed and the second is not, then restores the original namespace and
drops the new one via `withCurrentCatalogAndNamespace` / `withNamespace`.
--
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]