Mingcan Wang created FLINK-37093:
------------------------------------
Summary: The catalog that failed validation due to no type still
exists in catalogStoreHolder
Key: FLINK-37093
URL: https://issues.apache.org/jira/browse/FLINK-37093
Project: Flink
Issue Type: Bug
Components: Table SQL / API
Affects Versions: 2.0-preview, 1.20.0
Environment: mac os
Reporter: Mingcan Wang
Fix For: 2.0.0, 1.20.0
here's sql-client (1.20 & 2.0-preview1):
*Flink SQL> create catalog cat1;*
{color:#FF0000}[ERROR] Could not execute SQL statement. Reason:{color}
{color:#FF0000}org.apache.flink.table.api.ValidationException: Catalog options
do not contain an option key 'type' for discovering a catalog.{color}
*Flink SQL> show catalogs;*
+-----------------+
| catalog name |
+-----------------+
| cat1 |
| default_catalog |
+-----------------+
2 rows in set
*Flink SQL> use catalog cat1;*
{color:#FF0000}[ERROR] Could not execute SQL statement. Reason:{color}
{color:#FF0000}org.apache.flink.table.api.ValidationException: Catalog options
do not contain an option key 'type' for discovering a catalog.{color}
*Flink SQL> alter catalog cat1 comment 'no type';*
{color:#FF0000}[ERROR] Could not execute SQL statement. Reason:{color}
{color:#FF0000}org.apache.flink.table.api.ValidationException: Catalog options
do not contain an option key 'type' for discovering a catalog.{color}
*Flink SQL> create catalog cat1;*
{color:#FF0000}[ERROR] Could not execute SQL statement. Reason:{color}
{color:#FF0000}org.apache.flink.table.catalog.exceptions.CatalogException:
Catalog cat1 already exists.{color}
*Flink SQL> drop catalog cat1;*
[INFO] Execute statement succeeded.
*Flink SQL> show catalogs;*
+-----------------+
| catalog name |
+-----------------+
| default_catalog |
+-----------------+
1 row in set
When i create a catalog without type , the sql will parsed successfully.
According to the code :
```java
public void createCatalog(
String catalogName, CatalogDescriptor catalogDescriptor, boolean ignoreIfExists)
throws CatalogException {
checkArgument(
!StringUtils.isNullOrWhitespaceOnly(catalogName),
"Catalog name cannot be null or empty.");
checkNotNull(catalogDescriptor, "Catalog descriptor cannot be null");
boolean catalogExistsInStore =
catalogStoreHolder.catalogStore().contains(catalogName);
boolean catalogExistsInMemory = catalogs.containsKey(catalogName);
if (catalogExistsInStore || catalogExistsInMemory) {
if (!ignoreIfExists) {
throw new CatalogException(format("Catalog %s already exists.", catalogName));
}
} else {
// Store the catalog in the catalog store
catalogStoreHolder.catalogStore().storeCatalog(catalogName, catalogDescriptor);
// Initialize and store the catalog in memory
Catalog catalog = initCatalog(catalogName, catalogDescriptor);
catalog.open();
catalogs.put(catalogName, catalog);
}
}
```
the catalog will store in the catalog store first, then failed in initCatalog()
method.
the result is the catalog still exists in catalogStoreHolder. And I cannot use,
alter or create it again.
I noticed the alterCatalog() method, the proces is :
```java
Catalog newCatalog = initCatalog(catalogName, newDescriptor);
catalogStore.removeCatalog(catalogName, false);
if (catalogs.containsKey(catalogName)) {
catalogs.get(catalogName).close();
}
newCatalog.open();
catalogs.put(catalogName, newCatalog);
catalogStoreHolder.catalogStore().storeCatalog(catalogName, newDescriptor);
```
store in catalogStoreHolder should after initCatalog() and open().
--
This message was sent by Atlassian Jira
(v8.20.10#820010)