HyukjinKwon commented on code in PR #39162:
URL: https://github.com/apache/spark/pull/39162#discussion_r1054969939


##########
python/pyspark/sql/connect/catalog.py:
##########
@@ -0,0 +1,46 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from typing import NamedTuple, Optional, TYPE_CHECKING, List
+
+if TYPE_CHECKING:
+    from pyspark.sql.connect.session import SparkSession
+
+
+class Database(NamedTuple):
+    name: str
+    catalog: Optional[str]
+    description: Optional[str]
+    locationUri: str
+
+
+class Catalog:
+    """
+    User-facing catalog API, accessible through `SparkSession.catalog`.
+    """
+
+    def __init__(self, sparkSession: "SparkSession") -> None:
+        self._sparkSession = sparkSession
+
+    def listDatabases(self) -> List[Database]:
+        rows = self._sparkSession.sql("SHOW DATABASES").collect()
+        databases = []
+        for row in rows:
+            databases.append(
+                Database(name=row["namespace"], catalog=None, 
description=None, locationUri="")

Review Comment:
   The issue is that it would be pretty inefficient if there are many databases 
because we have to invoke `sql` multiple times. From a cursory look, there are 
many places like this (e.g., listing tables).
   
   We could implement these fast as the first version without adding a lot of 
protobuf messages vs it would be pretty slow due to multiple sql invocations. 
e.g., 1000 tables, it takes around 7~8 secs in my local with pure Spark.
   
   My suggestion is to quickly implement this, and switch it in the future but 
let me know if you guys have a different through @hvanhovell @grundprinzip 



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