amaliujia commented on PR #36968:
URL: https://github.com/apache/spark/pull/36968#issuecomment-1165955298

   @schuermannator 
   
   Could you BTW change the `listDatabases` behavior in this PR? I just 
realized it is not correct given the changes that we are making. It is better 
to be done by your PR because it will rely on your current `getDatabase` change.
   
   
   It could be as the following code 
   ```
     override def listDatabases(): Dataset[Database] = {
       val catalog = currentCatalog()
       val plan = ShowNamespaces(UnresolvedNamespace(Seq(catalog)), None)
       val ret = sparkSession.sessionState.executePlan(plan).toRdd.collect()
       val databases = ret
         .map(row => catalog + "." + row.getString(0))
         .map(getDatabase)
       CatalogImpl.makeDataset(databases, sparkSession)
     }
   ```
   
   You can use this code to test it:
   ```
     test("list databases with current catalog") {
       spark.catalog.setCurrentCatalog("testcat")
       sql(s"CREATE NAMESPACE testcat.my_db")
       sql(s"CREATE NAMESPACE testcat.my_db2")
       assert(spark.catalog.listDatabases().collect().map(_.name).toSet == 
Set("my_db", "my_db2"))
     }
   ```
   
   


-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to