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


##########
sql/core/src/test/scala/org/apache/spark/sql/execution/command/ShowViewsSuiteBase.scala:
##########
@@ -64,4 +79,72 @@ 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.
+    // Uses a literal set, not `names` (which is derived from `views` itself 
and would match
+    // everything, silently disabling this scoping).
+    val createdNames = Set("v_json_a", "v_json_b")
+    val created = views.filter(v => createdNames.contains((v \ 
"viewName").extract[String]))
+    created.foreach { v =>
+      assert((v \ "namespace").extract[Seq[String]] == Seq(namespace))
+      assert(!(v \ "isTemporary").extract[Boolean])
+    }
+  }
+
+  test("AS JSON applies the LIKE pattern") {
+    sql(s"CREATE VIEW $catalog.$namespace.v_json_match AS SELECT 1 AS x")
+    sql(s"CREATE VIEW $catalog.$namespace.v_json_skip AS SELECT 1 AS x")
+    val names = viewNames(
+      showViewsAsJson(s"SHOW VIEWS IN $catalog.$namespace LIKE 'v_json_match' 
AS JSON"))

Review Comment:
   Updated the test to use `LIKE 'V_JSON_M*|no_such_view'`, covering wildcard, 
case-insensitive, and alternation matching while asserting that only 
v_json_match is returned.



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