dawidwys commented on a change in pull request #8404: [FLINK-11476][table] Create CatalogManager to manage multiple catalogs URL: https://github.com/apache/flink/pull/8404#discussion_r286074850
########## File path: flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/TableEnvironment.java ########## @@ -280,6 +315,142 @@ */ void sqlUpdate(String stmt, QueryConfig config); + /** + * Gets the current default catalog name of the current session. + * + * @return The current default catalog name that is used for the path resolution. + * @see TableEnvironment#useCatalog(String) + */ + String getCurrentCatalog(); + + /** + * Sets the current catalog to the given value. It also sets the default + * database to the catalog's default one. To assign both catalog and database explicitly + * see {@link TableEnvironment#useDatabase(String, String)}. + * + * <p>This is used during the resolution of object paths. Both the catalog and database are optional + * when referencing catalog objects(tables, views etc.). The algorithm looks for requested objects in following + * paths in that order: + * <ol> + * <li>{@code [current-catalog].[current-database].[requested-path]}</li> + * <li>{@code [current-catalog].[requested-path]}</li> + * <li>{@code [requested-path]}</li> + * </ol> + * + * <p>Example: + * + * <p>Given structure with default catalog set to {@code default-catalog} and default database set to + * {@code default-database}. + * <pre> + * root: + * |- default-catalog + * |- default-database + * |- tab1 + * |- db1 + * |- tab1 + * |- cat1 + * |- db1 + * |- tab1 + * </pre> + * + * <p></p>The following table describes resolved paths: + * <table> + * <thead> + * <tr> + * <th>Requested path</th> + * <th>Resolved path</th> + * </tr> + * </thead> + * <tbody> + * <tr> + * <td>tab1</td> + * <td>default-catalog.default-database.tab1</td> + * </tr> + * <tr> + * <td>db1.tab1</td> + * <td>default-catalog.db1.tab1</td> + * </tr> + * <tr> + * <td>cat1.db1.tab1</td> + * <td>cat1.db1.tab1</td> + * </tr> + * </tbody> + * </table> + * + * @param catalogName The name of the catalog to set as the current default catalog. + * @throws CatalogException thrown if a catalog with given name could not be set as the default one + */ + void useCatalog(String catalogName); + + /** + * Gets the current default database name of the running session. + * + * @return The name of the current database of the current catalog. + * @see TableEnvironment#useDatabase(String, String) + */ + String getCurrentDatabase(); + + /** + * Sets the current default catalog and database. That path will be used as the default one + * when looking for unqualified object names. + * + * <p>This is used during the resolution of object paths. Both the catalog and database are optional + * when referencing catalog objects(tables, views etc.). The algorithm looks for requested objects in following + * paths in that order: + * <ol> + * <li>{@code [current-catalog].[current-database].[requested-path]}</li> + * <li>{@code [current-catalog].[requested-path]}</li> + * <li>{@code [requested-path]}</li> + * </ol> + * + * <p>Example: + * + * <p>Given structure with default catalog set to {@code default-catalog} and default database set to + * {@code default-database}. + * <pre> + * root: + * |- default-catalog + * |- default-database + * |- tab1 + * |- db1 + * |- tab1 + * |- cat1 + * |- db1 + * |- tab1 + * </pre> + * + * <p></p>The following table describes resolved paths: + * <table> + * <thead> + * <tr> + * <th>Requested path</th> + * <th>Resolved path</th> + * </tr> + * </thead> + * <tbody> + * <tr> + * <td>tab1</td> + * <td>default-catalog.default-database.tab1</td> + * </tr> + * <tr> + * <td>db1.tab1</td> + * <td>default-catalog.db1.tab1</td> + * </tr> + * <tr> + * <td>cat1.db1.tab1</td> + * <td>cat1.db1.tab1</td> + * </tr> + * </tbody> + * </table> + * + * @param catalogName The name of the catalog to set as the current catalog. + * @param databaseName The name of the database to set as the current database. + * @throws CatalogException thrown if the given catalog and database could not be set as the default ones + */ + void useDatabase( + String catalogName, Review comment: It is, sort of. Underneath they translate to: ``` useCatalog = CatalogManager.setCatalog useDatabase = CatalogManager.setCatalog + CatalogManager.setDatabase ``` I think it makes sense to leave it as it is, as the alternative would be to provide just `useDatabase(databaseName)`. I find this method error prone though. As the catalog name would be implicit. ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services