Skip to content

Commit 85e2d8d

Browse files
committed
[fix-32161] 修复语法检查失败
1 parent 1e56647 commit 85e2d8d

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

core/src/main/java/com/dtstack/flink/sql/GetPlan.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@
2626
import org.slf4j.Logger;
2727
import org.slf4j.LoggerFactory;
2828

29+
import java.net.URL;
30+
import java.net.URLClassLoader;
31+
2932
/**
3033
* local模式获取sql任务的执行计划
3134
* Date: 2020/2/17
@@ -37,17 +40,23 @@ public class GetPlan {
3740
private static final Logger LOG = LoggerFactory.getLogger(GetPlan.class);
3841

3942
public static String getExecutionPlan(String[] args) {
43+
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
4044
try {
4145
long start = System.currentTimeMillis();
4246
ParamsInfo paramsInfo = ExecuteProcessHelper.parseParams(args);
4347
paramsInfo.setGetPlan(true);
48+
ClassLoader envClassLoader = StreamExecutionEnvironment.class.getClassLoader();
49+
ClassLoader plannerClassLoader = URLClassLoader.newInstance(new URL[0], envClassLoader);
50+
Thread.currentThread().setContextClassLoader(plannerClassLoader);
4451
StreamExecutionEnvironment env = ExecuteProcessHelper.getStreamExecution(paramsInfo);
4552
String executionPlan = env.getExecutionPlan();
4653
long end = System.currentTimeMillis();
4754
return ApiResult.createSuccessResultJsonStr(executionPlan, end - start);
4855
} catch (Exception e) {
4956
LOG.error("Get plan error", e);
5057
return ApiResult.createErrorResultJsonStr(ExceptionUtils.getFullStackTrace(e));
58+
} finally {
59+
Thread.currentThread().setContextClassLoader(currentClassLoader);
5160
}
5261
}
5362
}

core/src/main/java/com/dtstack/flink/sql/exec/ExecuteProcessHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,13 +249,13 @@ public static void registerUserDefinedFunction(SqlTree sqlTree, List<URL> jarUrl
249249
throws IllegalAccessException, InvocationTargetException {
250250
// udf和tableEnv须由同一个类加载器加载
251251
ClassLoader levelClassLoader = tableEnv.getClass().getClassLoader();
252+
ClassLoader currentClassLoader = Thread.currentThread().getContextClassLoader();
252253
URLClassLoader classLoader = null;
253254
List<CreateFuncParser.SqlParserResult> funcList = sqlTree.getFunctionList();
254255
for (CreateFuncParser.SqlParserResult funcInfo : funcList) {
255256
// 构建plan的情况下,udf和tableEnv不需要是同一个类加载器
256257
if (getPlan) {
257-
URL[] urls = jarUrlList.toArray(new URL[0]);
258-
classLoader = URLClassLoader.newInstance(urls);
258+
classLoader = ClassLoaderManager.loadExtraJar(jarUrlList, (URLClassLoader) currentClassLoader);
259259
}
260260

261261
//classloader

0 commit comments

Comments
 (0)