You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/07/07 03:59:16 UTC

[GitHub] [flink] HuangZhenQiu commented on a diff in pull request #20001: [FLINK-27659][table] Planner support to use jar which is registered by 'CREATE FUNTION USING JAR' syntax

HuangZhenQiu commented on code in PR #20001:
URL: https://github.com/apache/flink/pull/20001#discussion_r915435030


##########
flink-table/flink-sql-client/src/main/java/org/apache/flink/util/ClientMutableURLClassLoader.java:
##########
@@ -0,0 +1,115 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+
+package org.apache.flink.util;
+
+import org.apache.flink.configuration.Configuration;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+/**
+ * This class loader extands {@link MutableURLClassLoader}, upon the {@code addURL} method, it also
+ * exposes a {@code removeURL} method which used to remove unnecessary jar from current classloader
+ * path. This class loader wraps a {@link MutableURLClassLoader} and an old classloader list, the
+ * class load is delegated to the inner {@link MutableURLClassLoader}.
+ *
+ * <p>This is only used to SqlClient for supporting {@code REMOVE JAR} clause currently. When remove
+ * a jar, get the registered jar url list from current {@link MutableURLClassLoader} firstly, then
+ * create a new instance of {@link MutableURLClassLoader} which urls doesn't include the removed
+ * jar, and the currentClassLoader point to new instance object, the old object is added to list to
+ * be closed when close {@link ClientMutableURLClassLoader}.
+ *
+ * <p>Note: This classloader is not guaranteed to actually remove class or resource, any classes or
+ * resources in the removed jar that are already loaded, are still accessible.
+ */
+public class ClientMutableURLClassLoader extends MutableURLClassLoader {
+
+    private static final Logger LOG = LoggerFactory.getLogger(ClientMutableURLClassLoader.class);
+
+    static {
+        ClassLoader.registerAsParallelCapable();
+    }
+
+    private final Configuration configuration;

Review Comment:
   +1



##########
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/internal/TableEnvironmentImpl.java:
##########
@@ -822,6 +843,19 @@ private TableResultInternal executeQueryOperation(QueryOperation operation) {
         List<Transformation<?>> transformations =
                 translate(Collections.singletonList(sinkOperation));
         final String defaultJobName = "collect";
+
+        // Merge user jars to table configuration
+        if (!resourceManager.getJarResourceURLs().isEmpty()) {

Review Comment:
   move it to a private function?



-- 
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: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org