lsyldliu commented on code in PR #20001:
URL: https://github.com/apache/flink/pull/20001#discussion_r922148341
##########
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/gateway/context/SessionContext.java:
##########
@@ -235,69 +231,58 @@ public static SessionContext create(DefaultContext
defaultContext, String sessio
settings.getBuiltInDatabaseName()))
.build();
- FunctionCatalog functionCatalog =
- new FunctionCatalog(configuration, catalogManager,
moduleManager, classLoader);
- SessionState sessionState =
- new SessionState(catalogManager, moduleManager,
functionCatalog);
+ final FunctionCatalog functionCatalog =
+ new FunctionCatalog(configuration, resourceManager,
catalogManager, moduleManager);
+ final SessionState sessionState =
+ new SessionState(catalogManager, moduleManager,
resourceManager, functionCatalog);
//
--------------------------------------------------------------------------------------------------------------
// Init ExecutionContext
//
--------------------------------------------------------------------------------------------------------------
ExecutionContext executionContext =
- new ExecutionContext(configuration, classLoader, sessionState);
+ new ExecutionContext(configuration, userClassLoader,
sessionState);
return new SessionContext(
defaultContext,
sessionId,
configuration,
- classLoader,
+ userClassLoader,
sessionState,
executionContext);
}
public void addJar(String jarPath) {
- URL jarURL = getURLFromPath(jarPath, "SQL Client only supports to add
local jars.");
- if (dependencies.contains(jarURL)) {
- return;
+ checkJarPath(jarPath, "SQL Client only supports to add local jars.");
+ try {
+ sessionState.resourceManager.registerJarResource(
+ Collections.singletonList(new
ResourceUri(ResourceType.JAR, jarPath)));
+ } catch (IOException e) {
+ LOG.warn(String.format("Could not register the specified jar
[%s].", jarPath), e);
}
-
- // merge the jars in config with the jars maintained in session
- Set<URL> jarsInConfig = getJarsInConfig();
-
- Set<URL> newDependencies = new HashSet<>(dependencies);
- newDependencies.addAll(jarsInConfig);
- newDependencies.add(jarURL);
- updateClassLoaderAndDependencies(newDependencies);
-
- // renew the execution context
- executionContext = new ExecutionContext(sessionConfiguration,
classLoader, sessionState);
}
public void removeJar(String jarPath) {
- URL jarURL = getURLFromPath(jarPath, "SQL Client only supports to
remove local jars.");
- if (!dependencies.contains(jarURL)) {
+ // if is relative path, convert to absolute path
+ URL jarURL = checkJarPath(jarPath, "SQL Client only supports to remove
local jars.");
+ // remove jar from resource manager
+ jarURL =
sessionState.resourceManager.unregisterJarResource(jarURL.getPath());
+ if (jarURL == null) {
LOG.warn(
String.format(
- "Could not remove the specified jar because the
jar path(%s) is not found in session classloader.",
+ "Could not remove the specified jar because the
jar path [%s] hadn't registered to classloader.",
jarPath));
return;
}
-
- Set<URL> newDependencies = new HashSet<>(dependencies);
- // merge the jars in config with the jars maintained in session
- Set<URL> jarsInConfig = getJarsInConfig();
- newDependencies.addAll(jarsInConfig);
- newDependencies.remove(jarURL);
-
- updateClassLoaderAndDependencies(newDependencies);
-
- // renew the execution context
- executionContext = new ExecutionContext(sessionConfiguration,
classLoader, sessionState);
+ // remove jar from classloader
+ classLoader.removeURL(jarURL);
}
public List<String> listJars() {
- return
dependencies.stream().map(URL::getPath).collect(Collectors.toList());
+ return sessionState.resourceManager.getResources().keySet().stream()
Review Comment:
I think here should return the user registered uri instead of local url.
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]