WeiZhong94 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_r292436200
########## File path: flink-python/pyflink/table/catalog.py ########## @@ -0,0 +1,904 @@ +################################################################################ +# 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 + + 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): + """ + Get a database from this catalog. + + :param database_name: Name of the database. + :return: The requested database. + """ + return CatalogDatabase(self._j_catalog.getDatabase(database_name)) + + def database_exists(self, database_name): + """ + Check if a database exists in this catalog. + + :param database_name: Name of the database. + :return: true if the given database exists in the catalog false otherwise. + """ + return self._j_catalog.databaseExists(database_name) + + def create_database(self, name, database, ignore_if_exists): + """ + Create a database. + + :param name: Name of the database to be created. + :param database: The database definition. Review comment: How about indicate the specific type of the non-basic type parameter in the document? e.g. we can add ":class:`CatalogDatabase`" here to avoid users' confusion. It will be parsed into a link to the target class in the generated sphinx document. ---------------------------------------------------------------- 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
