ayushbilala commented on code in PR #59235:
URL: https://github.com/apache/spark/pull/59235#discussion_r4246270884


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowViewsSuiteBase.scala:
##########
@@ -64,4 +79,69 @@ trait ShowViewsSuiteBase extends QueryTest with 
DDLCommandTestUtils {
         s"isTemporary must be false for persistent view rows: $r"))
     }
   }
+
+  test("AS JSON returns a single json_metadata column") {
+    sql(s"CREATE VIEW $catalog.$namespace.v_json_schema AS SELECT 1 AS x")
+    val df = sql(s"SHOW VIEWS IN $catalog.$namespace AS JSON")
+    assert(df.schema.length == 1)
+    assert(df.schema.head.name == "json_metadata")
+  }
+
+  test("AS JSON lists user-created views") {
+    sql(s"CREATE VIEW $catalog.$namespace.v_json_a AS SELECT 1 AS x")
+    sql(s"CREATE VIEW $catalog.$namespace.v_json_b AS SELECT 2 AS x")
+    val views = showViewsAsJson(s"SHOW VIEWS IN $catalog.$namespace AS JSON")
+    val names = viewNames(views)
+    assert(names.contains("v_json_a"), s"v_json_a missing: $names")
+    assert(names.contains("v_json_b"), s"v_json_b missing: $names")
+    assert(names.distinct.length == names.length, s"duplicate entries: $names")
+    // Scope to the two views this test created: this suite also runs under 
v1, where a
+    // leftover temp view (empty namespace, isTemporary=true) would otherwise 
fail the asserts.
+    val created = views.filter(v => names.contains((v \ 
"viewName").extract[String]))

Review Comment:
   Good catch. names is derived from views itself, so names.contains(...) is 
true for every entry.
   Fixed by filtering against a literal Set("v_json_a", "v_json_b") instead, so 
the scoping is actually real now.



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