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
695b78d4
Unverified
Commit
695b78d4
authored
May 23, 2024
by
ZackYoung
Committed by
GitHub
May 23, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[BugFix]Fix udf compiler problem (#3518)
parent
67b7a7e7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
10 deletions
+30
-10
TaskServiceImpl.java
...src/main/java/org/dinky/service/impl/TaskServiceImpl.java
+13
-1
JavaCompiler.java
...c/main/java/org/dinky/function/compiler/JavaCompiler.java
+15
-9
UDF.java
...tion/src/main/java/org/dinky/function/data/model/UDF.java
+2
-0
No files found.
dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java
View file @
695b78d4
...
...
@@ -59,7 +59,9 @@ import org.dinky.data.result.SqlExplainResult;
import
org.dinky.explainer.lineage.LineageBuilder
;
import
org.dinky.explainer.lineage.LineageResult
;
import
org.dinky.explainer.sqllineage.SQLLineageBuilder
;
import
org.dinky.function.FunctionFactory
;
import
org.dinky.function.compiler.CustomStringJavaCompiler
;
import
org.dinky.function.data.model.UDF
;
import
org.dinky.function.pool.UdfCodePool
;
import
org.dinky.function.util.UDFUtil
;
import
org.dinky.gateway.enums.SavePointStrategy
;
...
...
@@ -101,6 +103,7 @@ import java.io.Reader;
import
java.nio.charset.StandardCharsets
;
import
java.util.ArrayList
;
import
java.util.Base64
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -561,7 +564,16 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
Integer
taskVersionId
=
taskVersionService
.
createTaskVersionSnapshot
(
task
);
task
.
setVersionId
(
taskVersionId
);
if
(
Dialect
.
isUDF
(
task
.
getDialect
()))
{
UdfCodePool
.
addOrUpdate
(
UDFUtils
.
taskToUDF
(
task
.
buildTask
()));
// compile udf class
UDF
udf
=
UDFUtils
.
taskToUDF
(
task
.
buildTask
());
try
{
FunctionFactory
.
initUDF
(
Collections
.
singletonList
(
udf
),
task
.
getId
());
}
catch
(
Throwable
e
)
{
throw
new
BusException
(
"UDF compilation failed and cannot be published. The error message is as follows:"
+
e
.
getMessage
());
}
UdfCodePool
.
addOrUpdate
(
udf
);
}
}
else
{
if
(
Dialect
.
isUDF
(
task
.
getDialect
())
...
...
dinky-function/src/main/java/org/dinky/function/compiler/JavaCompiler.java
View file @
695b78d4
...
...
@@ -24,38 +24,44 @@ 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
;
/**
* java 编译
*
* @since 0.6.8
*/
@Slf4j
public
class
JavaCompiler
implements
FunctionCompiler
{
private
static
final
Set
<
String
>
COMPILER_CACHE
=
new
HashSet
<>();
/**
* 函数代码在线动态编译
*
* @param udf udf
* @param conf flink-conf
* @param udf
udf
* @param conf
flink-conf
* @param missionId 任务id
* @return 是否成功
*/
@Override
public
boolean
compiler
(
UDF
udf
,
ReadableConfig
conf
,
Integer
missionId
)
{
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
(
"
正在编译 java 代码 , class: "
+
udf
.
getClassName
());
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
(
"compilerTakeTime:"
+
compiler
.
getCompilerTakeTime
());
log
.
info
(
"class编译成功:{}"
,
className
);
log
.
info
(
"compiler take time:{}"
,
compiler
.
getCompilerTakeTime
());
COMPILER_CACHE
.
add
(
key
);
return
true
;
}
else
{
log
.
error
(
"class编译失败:{}"
,
className
);
log
.
error
(
"class编译失败:"
+
className
);
log
.
error
(
compiler
.
getCompilerMessage
());
return
false
;
}
...
...
dinky-function/src/main/java/org/dinky/function/data/model/UDF.java
View file @
695b78d4
...
...
@@ -22,6 +22,7 @@ package org.dinky.function.data.model;
import
org.apache.flink.table.catalog.FunctionLanguage
;
import
lombok.Builder
;
import
lombok.EqualsAndHashCode
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -29,6 +30,7 @@ import lombok.Setter;
@Getter
@Setter
@Builder
@EqualsAndHashCode
public
class
UDF
{
/** 函数名 */
...
...
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