|
18 | 18 |
|
19 | 19 | package com.dtstack.flink.sql.exec; |
20 | 20 |
|
21 | | -import com.dtstack.flink.sql.parser.CreateFuncParser; |
22 | | -import com.dtstack.flink.sql.parser.CreateTmpTableParser; |
23 | | -import com.dtstack.flink.sql.parser.FlinkPlanner; |
24 | | -import com.dtstack.flink.sql.parser.InsertSqlParser; |
25 | | -import com.dtstack.flink.sql.parser.SqlParser; |
26 | | -import com.dtstack.flink.sql.parser.SqlTree; |
27 | | -import com.dtstack.flink.sql.util.TypeInfoDataTypeConverter; |
28 | | -import org.apache.flink.api.common.typeinfo.TypeInformation; |
29 | | -import org.apache.flink.api.java.typeutils.RowTypeInfo; |
30 | | -import org.apache.flink.streaming.api.datastream.DataStream; |
31 | | -import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; |
32 | | -import org.apache.flink.table.api.*; |
33 | | -import org.apache.flink.table.api.java.StreamTableEnvironment; |
34 | | -import org.apache.flink.table.api.java.internal.StreamTableEnvironmentImpl; |
35 | | -import org.apache.flink.table.sinks.TableSink; |
36 | | - |
37 | 21 | import com.dtstack.flink.sql.classloader.ClassLoaderManager; |
38 | 22 | import com.dtstack.flink.sql.enums.ClusterMode; |
39 | 23 | import com.dtstack.flink.sql.enums.ECacheType; |
|
43 | 27 | import com.dtstack.flink.sql.function.FunctionManager; |
44 | 28 | import com.dtstack.flink.sql.option.OptionParser; |
45 | 29 | import com.dtstack.flink.sql.option.Options; |
46 | | -import com.dtstack.flink.sql.side.SideSqlExec; |
| 30 | +import com.dtstack.flink.sql.parser.CreateFuncParser; |
| 31 | +import com.dtstack.flink.sql.parser.CreateTmpTableParser; |
| 32 | +import com.dtstack.flink.sql.parser.FlinkPlanner; |
| 33 | +import com.dtstack.flink.sql.parser.InsertSqlParser; |
| 34 | +import com.dtstack.flink.sql.parser.SqlParser; |
| 35 | +import com.dtstack.flink.sql.parser.SqlTree; |
47 | 36 | import com.dtstack.flink.sql.side.AbstractSideTableInfo; |
| 37 | +import com.dtstack.flink.sql.side.SideSqlExec; |
48 | 38 | import com.dtstack.flink.sql.sink.StreamSinkFactory; |
49 | 39 | import com.dtstack.flink.sql.source.StreamSourceFactory; |
50 | 40 | import com.dtstack.flink.sql.table.AbstractSourceTableInfo; |
51 | 41 | import com.dtstack.flink.sql.table.AbstractTableInfo; |
52 | 42 | import com.dtstack.flink.sql.table.AbstractTargetTableInfo; |
53 | 43 | import com.dtstack.flink.sql.util.DtStringUtil; |
54 | 44 | import com.dtstack.flink.sql.util.PluginUtil; |
| 45 | +import com.dtstack.flink.sql.util.TypeInfoDataTypeConverter; |
55 | 46 | import com.dtstack.flink.sql.watermarker.WaterMarkerAssigner; |
56 | 47 | import com.fasterxml.jackson.databind.ObjectMapper; |
57 | 48 | import com.google.common.base.Preconditions; |
|
63 | 54 | import org.apache.calcite.sql.SqlNode; |
64 | 55 | import org.apache.commons.io.Charsets; |
65 | 56 | import org.apache.commons.lang3.StringUtils; |
| 57 | +import org.apache.flink.api.common.typeinfo.TypeInformation; |
| 58 | +import org.apache.flink.api.java.typeutils.RowTypeInfo; |
| 59 | +import org.apache.flink.streaming.api.datastream.DataStream; |
| 60 | +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; |
| 61 | +import org.apache.flink.table.api.EnvironmentSettings; |
| 62 | +import org.apache.flink.table.api.Table; |
| 63 | +import org.apache.flink.table.api.TableConfig; |
| 64 | +import org.apache.flink.table.api.TableEnvironment; |
| 65 | +import org.apache.flink.table.api.java.StreamTableEnvironment; |
| 66 | +import org.apache.flink.table.api.java.internal.StreamTableEnvironmentImpl; |
| 67 | +import org.apache.flink.table.sinks.TableSink; |
66 | 68 | import org.apache.flink.table.types.DataType; |
67 | | -import org.apache.flink.table.types.utils.TypeConversions; |
68 | 69 | import org.slf4j.Logger; |
69 | 70 | import org.slf4j.LoggerFactory; |
70 | 71 |
|
|
74 | 75 | import java.net.URLClassLoader; |
75 | 76 | import java.net.URLDecoder; |
76 | 77 | import java.time.ZoneId; |
| 78 | +import java.util.ArrayList; |
77 | 79 | import java.util.Arrays; |
78 | 80 | import java.util.List; |
79 | 81 | import java.util.Map; |
80 | 82 | import java.util.Properties; |
81 | 83 | import java.util.Set; |
82 | 84 | import java.util.TimeZone; |
83 | | -import java.util.ArrayList; |
84 | 85 | import java.util.stream.Stream; |
85 | 86 |
|
86 | 87 | /** |
@@ -162,7 +163,7 @@ public static StreamExecutionEnvironment getStreamExecution(ParamsInfo paramsInf |
162 | 163 | Map<String, Table> registerTableCache = Maps.newHashMap(); |
163 | 164 |
|
164 | 165 | //register udf |
165 | | - ExecuteProcessHelper.registerUserDefinedFunction(sqlTree, paramsInfo.getJarUrlList(), tableEnv); |
| 166 | + ExecuteProcessHelper.registerUserDefinedFunction(sqlTree, paramsInfo.getJarUrlList(), tableEnv, paramsInfo.isGetPlan()); |
166 | 167 | //register table schema |
167 | 168 | Set<URL> classPathSets = ExecuteProcessHelper.registerTable(sqlTree, env, tableEnv, paramsInfo.getLocalSqlPluginPath(), |
168 | 169 | paramsInfo.getRemoteSqlPluginPath(), paramsInfo.getPluginLoadMode(), sideTableMap, registerTableCache); |
@@ -247,13 +248,19 @@ private static void sqlTranslation(String localSqlPluginPath, |
247 | 248 | } |
248 | 249 | } |
249 | 250 |
|
250 | | - public static void registerUserDefinedFunction(SqlTree sqlTree, List<URL> jarUrlList, TableEnvironment tableEnv) |
| 251 | + public static void registerUserDefinedFunction(SqlTree sqlTree, List<URL> jarUrlList, TableEnvironment tableEnv, boolean getPlan) |
251 | 252 | throws IllegalAccessException, InvocationTargetException { |
252 | 253 | // udf和tableEnv须由同一个类加载器加载 |
253 | 254 | ClassLoader levelClassLoader = tableEnv.getClass().getClassLoader(); |
254 | 255 | URLClassLoader classLoader = null; |
255 | 256 | List<CreateFuncParser.SqlParserResult> funcList = sqlTree.getFunctionList(); |
256 | 257 | for (CreateFuncParser.SqlParserResult funcInfo : funcList) { |
| 258 | + // 构建plan的情况下,udf和tableEnv不需要是同一个类加载器 |
| 259 | + if (getPlan) { |
| 260 | + URL[] urls = jarUrlList.toArray(new URL[0]); |
| 261 | + classLoader = URLClassLoader.newInstance(urls); |
| 262 | + } |
| 263 | + |
257 | 264 | //classloader |
258 | 265 | if (classLoader == null) { |
259 | 266 | classLoader = ClassLoaderManager.loadExtraJar(jarUrlList, (URLClassLoader) levelClassLoader); |
|
0 commit comments