sunjincheng121 commented on a change in pull request #8623: [FLINK-12719][python] Add the Python catalog API URL: https://github.com/apache/flink/pull/8623#discussion_r293222312
########## File path: flink-python/pyflink/table/catalog.py ########## @@ -0,0 +1,965 @@ +################################################################################ +# 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 py4j.java_gateway import java_import + +from pyflink.java_gateway import get_gateway +from pyflink.table.table_schema import TableSchema + +__all__ = ['Catalog', 'CatalogDatabase', 'CatalogBaseTable', 'CatalogPartition', 'CatalogFunction', + 'ObjectPath', 'CatalogPartitionSpec', 'CatalogTableStatistics', + 'CatalogColumnStatistics', 'HiveCatalog', 'HiveCatalogDatabase', 'HiveCatalogFunction', + 'HiveCatalogPartition', 'HiveCatalogTable', 'HiveCatalogView'] + + +class Catalog(object): + """ + Catalog is responsible for reading and writing metadata such as database/table/views/UDFs + from a registered catalog. It connects a registered catalog and Flink's Table API. + """ + + def __init__(self, j_catalog): + self._j_catalog = j_catalog + + @staticmethod + def _get(j_catalog): + if j_catalog.getClass().getName() == "org.apache.flink.table.catalog.hive.HiveCatalog": + return HiveCatalog(j_hive_catalog=j_catalog) + else: + return Catalog(j_catalog) + + def get_default_database(self): + """ + Get the name of the default database for this catalog. The default database will be the + current database for the catalog when user's session doesn't specify a current database. + The value probably comes from configuration, will not change for the life time of the + catalog instance. + + :return: The name of the current database. + """ + return self._j_catalog.getDefaultDatabase() + + def list_databases(self): + """ + Get the names of all databases in this catalog. + + :return: A list of the names of all databases. + """ + return list(self._j_catalog.listDatabases()) + + def get_database(self, database_name): Review comment: In JAVA we can throw `DatabaseNotExistException`, I think for python w also need to tell the user this method may throw an Exception. What do you think? ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected] With regards, Apache Git Services
