|
18 | 18 |
|
19 | 19 | package com.dtstack.flink.sql.exec; |
20 | 20 |
|
| 21 | +import com.dtstack.flink.sql.GetPlan; |
21 | 22 | import com.dtstack.flink.sql.parser.CreateFuncParser; |
22 | 23 | import com.dtstack.flink.sql.parser.CreateTmpTableParser; |
23 | 24 | import com.dtstack.flink.sql.parser.FlinkPlanner; |
|
74 | 75 | import java.util.Arrays; |
75 | 76 | import java.util.List; |
76 | 77 | import java.util.Map; |
| 78 | +import java.util.Objects; |
77 | 79 | import java.util.Properties; |
78 | 80 | import java.util.Set; |
79 | 81 | import java.util.TimeZone; |
@@ -158,7 +160,7 @@ public static StreamExecutionEnvironment getStreamExecution(ParamsInfo paramsInf |
158 | 160 | Map<String, Table> registerTableCache = Maps.newHashMap(); |
159 | 161 |
|
160 | 162 | //register udf |
161 | | - ExecuteProcessHelper.registerUserDefinedFunction(sqlTree, paramsInfo.getJarUrlList(), tableEnv); |
| 163 | + ExecuteProcessHelper.registerUserDefinedFunction(sqlTree, paramsInfo.getJarUrlList(), tableEnv, paramsInfo.isGetPlan()); |
162 | 164 | //register table schema |
163 | 165 | Set<URL> classPathSets = ExecuteProcessHelper.registerTable(sqlTree, env, tableEnv, paramsInfo.getLocalSqlPluginPath(), |
164 | 166 | paramsInfo.getRemoteSqlPluginPath(), paramsInfo.getPluginLoadMode(), sideTableMap, registerTableCache); |
@@ -243,13 +245,19 @@ private static void sqlTranslation(String localSqlPluginPath, |
243 | 245 | } |
244 | 246 | } |
245 | 247 |
|
246 | | - public static void registerUserDefinedFunction(SqlTree sqlTree, List<URL> jarUrlList, TableEnvironment tableEnv) |
| 248 | + public static void registerUserDefinedFunction(SqlTree sqlTree, List<URL> jarUrlList, TableEnvironment tableEnv, boolean getPlan) |
247 | 249 | throws IllegalAccessException, InvocationTargetException { |
248 | 250 | // udf和tableEnv须由同一个类加载器加载 |
249 | 251 | ClassLoader levelClassLoader = tableEnv.getClass().getClassLoader(); |
250 | 252 | URLClassLoader classLoader = null; |
251 | 253 | List<CreateFuncParser.SqlParserResult> funcList = sqlTree.getFunctionList(); |
252 | 254 | for (CreateFuncParser.SqlParserResult funcInfo : funcList) { |
| 255 | + // 构建plan的情况下,udf和tableEnv不需要是同一个类加载器 |
| 256 | + if (getPlan) { |
| 257 | + URL[] urls = jarUrlList.toArray(new URL[0]); |
| 258 | + classLoader = URLClassLoader.newInstance(urls); |
| 259 | + } |
| 260 | + |
253 | 261 | //classloader |
254 | 262 | if (classLoader == null) { |
255 | 263 | classLoader = ClassLoaderManager.loadExtraJar(jarUrlList, (URLClassLoader) levelClassLoader); |
|
0 commit comments