55
55
import org .apache .calcite .sql .SqlInsert ;
56
56
import org .apache .calcite .sql .SqlNode ;
57
57
import org .apache .commons .io .Charsets ;
58
+ import org .apache .commons .lang3 .SerializationUtils ;
58
59
import org .apache .commons .lang3 .StringUtils ;
59
60
import org .apache .flink .api .common .typeinfo .TypeInformation ;
60
61
import org .apache .flink .api .java .typeutils .RowTypeInfo ;
79
80
import java .time .ZoneId ;
80
81
import java .util .ArrayList ;
81
82
import java .util .Arrays ;
83
+ import java .util .HashMap ;
82
84
import java .util .List ;
83
85
import java .util .Map ;
84
86
import java .util .Objects ;
@@ -244,7 +246,11 @@ private static void sqlTranslation(String localSqlPluginPath,
244
246
scope ++;
245
247
}
246
248
249
+ final Map <String , AbstractSideTableInfo > tmpTableMap = new HashMap <>();
247
250
for (InsertSqlParser .SqlParseResult result : sqlTree .getExecSqlList ()) {
251
+ // prevent current sql use last sql's sideTableInfo
252
+ sideTableMap .forEach ((s , abstractSideTableInfo ) -> tmpTableMap .put (s , SerializationUtils .clone (abstractSideTableInfo )));
253
+
248
254
if (LOG .isInfoEnabled ()) {
249
255
LOG .info ("exe-sql:\n " + result .getExecSql ());
250
256
}
@@ -257,17 +263,17 @@ private static void sqlTranslation(String localSqlPluginPath,
257
263
SqlNode sqlNode = flinkPlanner .getParser ().parse (realSql );
258
264
String tmpSql = ((SqlInsert ) sqlNode ).getSource ().toString ();
259
265
tmp .setExecSql (tmpSql );
260
- sideSqlExec .exec (tmp .getExecSql (), sideTableMap , tableEnv , registerTableCache , tmp , scope + "" );
266
+ sideSqlExec .exec (tmp .getExecSql (), tmpTableMap , tableEnv , registerTableCache , tmp , scope + "" );
261
267
} else {
262
268
for (String sourceTable : result .getSourceTableList ()) {
263
- if (sideTableMap .containsKey (sourceTable )) {
269
+ if (tmpTableMap .containsKey (sourceTable )) {
264
270
isSide = true ;
265
271
break ;
266
272
}
267
273
}
268
274
if (isSide ) {
269
275
//sql-dimensional table contains the dimension table of execution
270
- sideSqlExec .exec (result .getExecSql (), sideTableMap , tableEnv , registerTableCache , null , String .valueOf (scope ));
276
+ sideSqlExec .exec (result .getExecSql (), tmpTableMap , tableEnv , registerTableCache , null , String .valueOf (scope ));
271
277
} else {
272
278
LOG .info ("----------exec sql without dimension join-----------" );
273
279
LOG .info ("----------real sql exec is--------------------------\n {}" , result .getExecSql ());
@@ -280,26 +286,17 @@ private static void sqlTranslation(String localSqlPluginPath,
280
286
281
287
scope ++;
282
288
}
289
+ tmpTableMap .clear ();
283
290
}
284
291
}
285
292
286
293
public static void registerUserDefinedFunction (SqlTree sqlTree , List <URL > jarUrlList , TableEnvironment tableEnv , boolean getPlan )
287
294
throws IllegalAccessException , InvocationTargetException {
288
295
// udf和tableEnv须由同一个类加载器加载
289
- ClassLoader levelClassLoader = tableEnv .getClass ().getClassLoader ();
290
296
ClassLoader currentClassLoader = Thread .currentThread ().getContextClassLoader ();
291
- URLClassLoader classLoader = null ;
297
+ URLClassLoader classLoader = ClassLoaderManager . loadExtraJar ( jarUrlList , ( URLClassLoader ) currentClassLoader ) ;
292
298
List <CreateFuncParser .SqlParserResult > funcList = sqlTree .getFunctionList ();
293
299
for (CreateFuncParser .SqlParserResult funcInfo : funcList ) {
294
- // 构建plan的情况下,udf和tableEnv不需要是同一个类加载器
295
- if (getPlan ) {
296
- classLoader = ClassLoaderManager .loadExtraJar (jarUrlList , (URLClassLoader ) currentClassLoader );
297
- }
298
-
299
- //classloader
300
- if (classLoader == null ) {
301
- classLoader = ClassLoaderManager .loadExtraJar (jarUrlList , (URLClassLoader ) levelClassLoader );
302
- }
303
300
FunctionManager .registerUDF (funcInfo .getType (), funcInfo .getClassName (), funcInfo .getName (), tableEnv , classLoader );
304
301
}
305
302
}
0 commit comments