vinodkc commented on code in PR #53466:
URL: https://github.com/apache/spark/pull/53466#discussion_r2617331541


##########
sql/core/src/main/scala/org/apache/spark/sql/execution/command/ShowNamespacesCommand.scala:
##########
@@ -75,3 +84,56 @@ object ShowNamespacesCommand {
     )
   }
 }
+
+/**
+ * The command for `SHOW DATABASES AS JSON` / `SHOW SCHEMAS AS JSON`.
+ *
+ * Example output:
+ * {{{
+ * {
+ *   "databases": [
+ *     {"name": "default"},
+ *     {"name": "test_db"}
+ *   ]
+ * }
+ * }}}
+ */
+case class ShowNamespacesJsonCommand(
+    child: LogicalPlan,
+    pattern: Option[String],
+    override val output: Seq[AttributeReference] = 
ShowNamespacesJsonCommand.output)
+  extends UnaryRunnableCommand {
+
+  override def run(sparkSession: SparkSession): Seq[Row] = {
+    val filteredNamespaces = ShowNamespacesCommand(child, pattern)
+      .getFilteredNamespaces(sparkSession)
+
+    val databasesJson = filteredNamespaces.map { name =>
+      JObject("name" -> JString(name))
+    }
+
+    val jsonOutput = JObject(
+      (if (SQLConf.get.legacyOutputSchema) "databases" else "namespaces") ->
+        JArray(databasesJson.toList))
+
+    Seq(Row(compact(render(jsonOutput))))
+  }
+
+  override protected def withNewChildInternal(newChild: LogicalPlan): 
LogicalPlan = {
+    copy(child = newChild)
+  }
+}
+
+object ShowNamespacesJsonCommand {
+  def output: Seq[AttributeReference] = {
+    val (columnName, comment) = if (SQLConf.get.legacyOutputSchema) {
+      ("databaseName", "JSON list of databases")
+    } else {
+      ("namespace", "JSON list of namespaces")

Review Comment:
   @pan3793  `SHOW databases` returns the same name. For consistency, `SHOW 
databases AS JSON` also followed the same.
   Do you have any suggestions on name value?



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