Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wangpeng
dinky
Commits
375df0c7
Unverified
Commit
375df0c7
authored
May 23, 2024
by
ZackYoung
Committed by
GitHub
May 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BugFix] [UDF] Fix the issue where UDF cannot find classes in Flink SQL tasks (#3523)
parent
695b78d4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
13 deletions
+24
-13
JobUDFBuilder.java
...re/src/main/java/org/dinky/job/builder/JobUDFBuilder.java
+9
-1
FunctionCompiler.java
...in/java/org/dinky/function/compiler/FunctionCompiler.java
+11
-0
JavaCompiler.java
...c/main/java/org/dinky/function/compiler/JavaCompiler.java
+3
-11
UDFUtil.java
...nction/src/main/java/org/dinky/function/util/UDFUtil.java
+1
-1
No files found.
dinky-core/src/main/java/org/dinky/job/builder/JobUDFBuilder.java
View file @
375df0c7
...
...
@@ -70,10 +70,10 @@ public class JobUDFBuilder extends JobBuilder {
List
<
File
>
jarFiles
=
new
ArrayList
<>(
jobManager
.
getUdfPathContextHolder
().
getAllFileSet
());
String
[]
userCustomUdfJarPath
=
UDFUtil
.
initJavaUDF
(
udfList
,
taskId
);
String
[]
jarPaths
=
CollUtil
.
removeNull
(
jarFiles
).
stream
()
.
map
(
File:
:
getAbsolutePath
)
.
toArray
(
String
[]::
new
);
if
(
GATEWAY_TYPE_MAP
.
get
(
SESSION
).
contains
(
runMode
))
{
config
.
setJarFiles
(
jarPaths
);
}
...
...
@@ -82,6 +82,7 @@ public class JobUDFBuilder extends JobBuilder {
String
[]
pyPaths
=
UDFUtil
.
initPythonUDF
(
udfList
,
runMode
,
config
.
getTaskId
(),
executor
.
getTableConfig
().
getConfiguration
());
executor
.
initUDF
(
userCustomUdfJarPath
);
executor
.
initUDF
(
jarPaths
);
if
(
ArrayUtil
.
isNotEmpty
(
pyPaths
))
{
...
...
@@ -91,6 +92,13 @@ public class JobUDFBuilder extends JobBuilder {
}
}
}
if
(
ArrayUtil
.
isNotEmpty
(
userCustomUdfJarPath
))
{
for
(
String
jarPath
:
userCustomUdfJarPath
)
{
if
(
StrUtil
.
isNotBlank
(
jarPath
))
{
jobManager
.
getUdfPathContextHolder
().
addUdfPath
(
new
File
(
jarPath
));
}
}
}
Set
<
File
>
pyUdfFile
=
jobManager
.
getUdfPathContextHolder
().
getPyUdfFile
();
executor
.
initPyUDF
(
...
...
dinky-function/src/main/java/org/dinky/function/compiler/FunctionCompiler.java
View file @
375df0c7
...
...
@@ -25,13 +25,16 @@ import org.dinky.function.exception.UDFCompilerException;
import
org.apache.flink.configuration.ReadableConfig
;
import
java.util.HashSet
;
import
java.util.List
;
import
java.util.Set
;
import
cn.hutool.core.lang.Singleton
;
import
cn.hutool.core.util.StrUtil
;
/** @since 0.6.8 */
public
interface
FunctionCompiler
{
Set
<
String
>
COMPILER_CACHE
=
new
HashSet
<>();
/**
* 函数代码在线动态编译
...
...
@@ -54,6 +57,11 @@ public interface FunctionCompiler {
static
boolean
getCompiler
(
UDF
udf
,
ReadableConfig
conf
,
Integer
missionId
)
{
Asserts
.
checkNull
(
udf
,
"udf为空"
);
Asserts
.
checkNull
(
udf
.
getCode
(),
"udf 代码为空"
);
String
key
=
udf
.
getClassName
()
+
udf
.
getFunctionLanguage
();
if
(
COMPILER_CACHE
.
contains
(
key
))
{
return
true
;
}
boolean
success
;
switch
(
udf
.
getFunctionLanguage
())
{
case
JAVA:
...
...
@@ -69,6 +77,9 @@ public interface FunctionCompiler {
throw
UDFCompilerException
.
notSupportedException
(
udf
.
getFunctionLanguage
().
name
());
}
if
(
success
)
{
COMPILER_CACHE
.
add
(
key
);
}
return
success
;
}
...
...
dinky-function/src/main/java/org/dinky/function/compiler/JavaCompiler.java
View file @
375df0c7
...
...
@@ -24,9 +24,6 @@ import org.dinky.function.data.model.UDF;
import
org.apache.flink.configuration.ReadableConfig
;
import
java.util.HashSet
;
import
java.util.Set
;
import
lombok.extern.slf4j.Slf4j
;
/**
...
...
@@ -34,7 +31,6 @@ import lombok.extern.slf4j.Slf4j;
*/
@Slf4j
public
class
JavaCompiler
implements
FunctionCompiler
{
private
static
final
Set
<
String
>
COMPILER_CACHE
=
new
HashSet
<>();
/**
* 函数代码在线动态编译
...
...
@@ -46,22 +42,18 @@ public class JavaCompiler implements FunctionCompiler {
*/
@Override
public
synchronized
boolean
compiler
(
UDF
udf
,
ReadableConfig
conf
,
Integer
missionId
)
{
String
key
=
udf
.
getClassName
()
+
udf
.
getFunctionLanguage
();
if
(
COMPILER_CACHE
.
contains
(
key
))
{
return
true
;
}
// TODO 改为ProcessStep注释
log
.
info
(
"Compiling java code, class: {}"
,
udf
.
getClassName
());
CustomStringJavaCompiler
compiler
=
new
CustomStringJavaCompiler
(
udf
.
getCode
());
boolean
res
=
compiler
.
compilerToTmpPath
(
PathConstant
.
getUdfCompilerJavaPath
(
missionId
));
String
className
=
compiler
.
getFullClassName
();
if
(
res
)
{
log
.
info
(
"class
编译成功
:{}"
,
className
);
log
.
info
(
"class
compiled successfully
:{}"
,
className
);
log
.
info
(
"compiler take time:{}"
,
compiler
.
getCompilerTakeTime
());
COMPILER_CACHE
.
add
(
key
);
return
true
;
}
else
{
log
.
error
(
"class
编译失败
:{}"
,
className
);
log
.
error
(
"class
compilation failed
:{}"
,
className
);
log
.
error
(
compiler
.
getCompilerMessage
());
return
false
;
}
...
...
dinky-function/src/main/java/org/dinky/function/util/UDFUtil.java
View file @
375df0c7
...
...
@@ -154,7 +154,7 @@ public class UDFUtil {
}
}
public
static
String
[]
initJavaUDF
(
List
<
UDF
>
udf
,
GatewayType
gatewayType
,
Integer
missionId
)
{
public
static
String
[]
initJavaUDF
(
List
<
UDF
>
udf
,
Integer
missionId
)
{
return
FunctionFactory
.
initUDF
(
CollUtil
.
newArrayList
(
CollUtil
.
filterNew
(
udf
,
x
->
x
.
getFunctionLanguage
()
!=
FunctionLanguage
.
PYTHON
)),
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment