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


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/datasources/v2/ShowTablesExec.scala:
##########
@@ -33,18 +36,51 @@ case class ShowTablesExec(
     output: Seq[Attribute],
     catalog: TableCatalog,
     namespace: Seq[String],
-    pattern: Option[String]) extends V2CommandExec with LeafExecNode {
+    pattern: Option[String],
+    asJson: Boolean = false) extends V2CommandExec with LeafExecNode {
   override protected def run(): Seq[InternalRow] = {
-    val rows = new ArrayBuffer[InternalRow]()
-
     val tables = catalog.listTables(namespace.toArray)
-    tables.map { table =>
-      if (pattern.map(StringUtils.filterPattern(Seq(table.name()), 
_).nonEmpty).getOrElse(true)) {
+    val filteredTables = tables.filter { table =>
+      pattern.map(StringUtils.filterPattern(Seq(table.name()), 
_).nonEmpty).getOrElse(true)
+    }
+
+    if (asJson) {
+      val jsonTables = filteredTables.map { table =>
+        JObject(
+          "name" -> JString(table.name()),
+          "namespace" -> JArray(table.namespace().map(JString(_)).toList),
+          "isTemporary" -> JBool(isTempView(table, catalog))
+        )
+      }.toList
+
+      val jsonTempViews = if (CatalogV2Util.isSessionCatalog(catalog)) {
+        val sessionCatalog = session.sessionState.catalog

Review Comment:
   Fixed. JSON path has been moved to the new ShowTablesJsonExec which guards 
the separate listTempViews() call with 
!CatalogV2Util.isSessionCatalog(catalog), matching the logic of the non-JSON 
path. 
   
   When catalog is V2SessionCatalog, temp views are already included in 
listTables() results and the separate call is skipped.



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