KurtYoung commented on a change in pull request #10454:
[FLINK-13195][sql-client] Add create(drop) table support for SqlClient
URL: https://github.com/apache/flink/pull/10454#discussion_r355093955
##########
File path:
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/local/ExecutionContext.java
##########
@@ -391,55 +431,119 @@ private static Executor lookupExecutor(
}
}
- private void initializeTableEnvironment() {
+ private void initializeTableEnvironment(SessionState sessionState) {
//--------------------------------------------------------------------------------------------------------------
// Step.1 Create environments
//--------------------------------------------------------------------------------------------------------------
+ createTableEnvironment(sessionState);
+
+ final boolean noInheritedState = sessionState == null;
+ if (noInheritedState) {
+
//--------------------------------------------------------------------------------------------------------------
+ // Step.2 Create modules and load them into the
TableEnvironment.
+
//--------------------------------------------------------------------------------------------------------------
+ // No need to register the modules info if already
inherit from the same session.
+ Map<String, Module> modules = new LinkedHashMap<>();
+ environment.getModules().forEach((name, entry) ->
+ modules.put(name,
createModule(entry.asMap(), classLoader))
+ );
+ if (!modules.isEmpty()) {
+ // unload core module first to respect whatever
users configure
+
tableEnv.unloadModule(CoreModuleDescriptorValidator.MODULE_TYPE_CORE);
+ modules.forEach(tableEnv::loadModule);
+ }
+
+
//--------------------------------------------------------------------------------------------------------------
+ // Step.3 create user-defined functions and temporal
tables then register them.
+
//--------------------------------------------------------------------------------------------------------------
+ // No need to register the functions if already inherit
from the same session.
+ registerFunctions();
+
+
//--------------------------------------------------------------------------------------------------------------
+ // Step.4 Create catalogs and register them.
+
//--------------------------------------------------------------------------------------------------------------
+ // No need to register the catalogs if already inherit
from the same session.
+ initializeCatalogs();
+ }
+ }
+
+ private void createTableEnvironment(SessionState sessionState) {
+ final EnvironmentSettings settings =
environment.getExecution().getEnvironmentSettings();
+ final boolean noInheritedState = sessionState == null;
+ CatalogManager catalogManager;
+ ModuleManager moduleManager;
+ FunctionCatalog functionCatalog;
+ if (noInheritedState) {
+ // Step 1.1 Initialize the CatalogManager if required.
+ catalogManager = new CatalogManager(
+ settings.getBuiltInCatalogName(),
+ new GenericInMemoryCatalog(
+
settings.getBuiltInCatalogName(),
+
settings.getBuiltInDatabaseName()));
+ // Step 1.2 Initialize the ModuleManager if required.
+ moduleManager = new ModuleManager();
+ // Step 1.3 Initialize the FunctionCatalog if required.
+ functionCatalog = new FunctionCatalog(catalogManager,
moduleManager);
+ // Step 1.4 Set up session state.
+ this.sessionState = SessionState.of(catalogManager,
moduleManager, functionCatalog);
+ } else {
+ catalogManager = sessionState.catalogManager;
+ moduleManager = sessionState.moduleManager;
+ functionCatalog = sessionState.functionCatalog;
+ // Set up session state.
+ this.sessionState = sessionState;
+ }
+ createTableEnvironment(settings, catalogManager, moduleManager,
functionCatalog);
+ }
+
+ private void createTableEnvironment(
Review comment:
you can put merge this method with previous one, then you don't have to
assign 3 parameters in the previous method and pass them to this one.
----------------------------------------------------------------
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