-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-37222] Do not reuse views across TableEnvironments in SQL client
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...va/org/apache/flink/table/gateway/service/context/EnvironmentReusableInMemoryCatalog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.apache.flink.table.gateway.service.context; | ||
|
||
import org.apache.flink.table.api.TableEnvironment; | ||
import org.apache.flink.table.catalog.CatalogBaseTable; | ||
import org.apache.flink.table.catalog.CatalogView; | ||
import org.apache.flink.table.catalog.GenericInMemoryCatalog; | ||
import org.apache.flink.table.catalog.ObjectPath; | ||
import org.apache.flink.table.catalog.QueryOperationCatalogView; | ||
import org.apache.flink.table.catalog.ResolvedCatalogView; | ||
import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException; | ||
import org.apache.flink.table.catalog.exceptions.TableAlreadyExistException; | ||
|
||
import java.util.Optional; | ||
|
||
/** | ||
* An in-memory catalog that can be reused across different {@link TableEnvironment}. The SQL client | ||
* works against {@link TableEnvironment} design and reuses some of the components (e.g. | ||
* CatalogManager), but not all (e.g. Planner) which causes e.g. views registered in an in-memory | ||
* catalog to fail. This class is a workaround not to keep Planner bound parts of a view reused | ||
* across different {@link TableEnvironment}. | ||
*/ | ||
public class EnvironmentReusableInMemoryCatalog extends GenericInMemoryCatalog { | ||
public EnvironmentReusableInMemoryCatalog(String name, String defaultDatabase) { | ||
super(name, defaultDatabase); | ||
} | ||
|
||
@Override | ||
public void createTable(ObjectPath tablePath, CatalogBaseTable table, boolean ignoreIfExists) | ||
throws TableAlreadyExistException, DatabaseNotExistException { | ||
CatalogBaseTable tableToRegister = | ||
extractView(table) | ||
.flatMap(QueryOperationCatalogView::getOriginalView) | ||
.map(v -> (CatalogBaseTable) v) | ||
.orElse(table); | ||
super.createTable(tablePath, tableToRegister, ignoreIfExists); | ||
} | ||
|
||
private Optional<QueryOperationCatalogView> extractView(CatalogBaseTable table) { | ||
if (table instanceof ResolvedCatalogView) { | ||
final CatalogView origin = ((ResolvedCatalogView) table).getOrigin(); | ||
if (origin instanceof QueryOperationCatalogView) { | ||
return Optional.of((QueryOperationCatalogView) origin); | ||
} | ||
return Optional.empty(); | ||
} else if (table instanceof QueryOperationCatalogView) { | ||
return Optional.of((QueryOperationCatalogView) table); | ||
} | ||
return Optional.empty(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters