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
443f5011
Unverified
Commit
443f5011
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 (#3525)
Co-authored-by:
zackyoungh
<
zackyoungh@users.noreply.github.com
>
parent
4cfd123d
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
33 additions
and
28 deletions
+33
-28
CustomStringScalaCompiler.java
...rg/dinky/function/compiler/CustomStringScalaCompiler.java
+4
-2
JVMPackage.java
...src/main/java/org/dinky/function/compiler/JVMPackage.java
+1
-2
JavaCompiler.java
...c/main/java/org/dinky/function/compiler/JavaCompiler.java
+2
-1
PythonFunction.java
...main/java/org/dinky/function/compiler/PythonFunction.java
+9
-8
ScalaCompiler.java
.../main/java/org/dinky/function/compiler/ScalaCompiler.java
+1
-1
PathConstant.java
...c/main/java/org/dinky/function/constant/PathConstant.java
+6
-4
UDFUtil.java
...nction/src/main/java/org/dinky/function/util/UDFUtil.java
+1
-1
function.tsx
...rc/pages/DataStudio/RightContainer/JobConfig/function.tsx
+9
-9
No files found.
dinky-function/src/main/java/org/dinky/function/compiler/CustomStringScalaCompiler.java
View file @
443f5011
...
@@ -21,6 +21,8 @@ package org.dinky.function.compiler;
...
@@ -21,6 +21,8 @@ package org.dinky.function.compiler;
import
org.dinky.function.constant.PathConstant
;
import
org.dinky.function.constant.PathConstant
;
import
org.apache.flink.table.catalog.FunctionLanguage
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
scala.runtime.AbstractFunction1
;
import
scala.runtime.AbstractFunction1
;
import
scala.runtime.BoxedUnit
;
import
scala.runtime.BoxedUnit
;
...
@@ -40,12 +42,12 @@ public class CustomStringScalaCompiler {
...
@@ -40,12 +42,12 @@ public class CustomStringScalaCompiler {
}
}
}
}
public
static
IMain
getInterpreter
(
Integer
missionId
)
{
public
static
IMain
getInterpreter
()
{
GenericRunnerSettings
settings
=
new
GenericRunnerSettings
(
new
ErrorHandler
());
GenericRunnerSettings
settings
=
new
GenericRunnerSettings
(
new
ErrorHandler
());
settings
.
usejavacp
().
tryToSetFromPropertyValue
(
"true"
);
settings
.
usejavacp
().
tryToSetFromPropertyValue
(
"true"
);
settings
.
Yreploutdir
().
tryToSetFromPropertyValue
(
PathConstant
.
getUdfCompiler
JavaPath
(
missionId
));
settings
.
Yreploutdir
().
tryToSetFromPropertyValue
(
PathConstant
.
getUdfCompiler
Path
(
FunctionLanguage
.
JAVA
));
return
new
IMain
(
settings
);
return
new
IMain
(
settings
);
}
}
}
}
dinky-function/src/main/java/org/dinky/function/compiler/JVMPackage.java
View file @
443f5011
...
@@ -35,7 +35,6 @@ import cn.hutool.core.collection.CollUtil;
...
@@ -35,7 +35,6 @@ import cn.hutool.core.collection.CollUtil;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
/** @since 0.6.8 */
public
class
JVMPackage
implements
FunctionPackage
{
public
class
JVMPackage
implements
FunctionPackage
{
@Override
@Override
...
@@ -57,7 +56,7 @@ public class JVMPackage implements FunctionPackage {
...
@@ -57,7 +56,7 @@ public class JVMPackage implements FunctionPackage {
for
(
int
i
=
0
;
i
<
classNameList
.
size
();
i
++)
{
for
(
int
i
=
0
;
i
<
classNameList
.
size
();
i
++)
{
String
className
=
classNameList
.
get
(
i
);
String
className
=
classNameList
.
get
(
i
);
String
classFile
=
StrUtil
.
replace
(
className
,
"."
,
"/"
)
+
".class"
;
String
classFile
=
StrUtil
.
replace
(
className
,
"."
,
"/"
)
+
".class"
;
String
absoluteFilePath
=
PathConstant
.
getUdfCompiler
JavaPath
(
missionId
,
classFile
);
String
absoluteFilePath
=
PathConstant
.
getUdfCompiler
Path
(
FunctionLanguage
.
JAVA
,
classFile
);
clazzs
[
i
]
=
classFile
;
clazzs
[
i
]
=
classFile
;
fileInputStreams
[
i
]
=
FileUtil
.
getInputStream
(
absoluteFilePath
);
fileInputStreams
[
i
]
=
FileUtil
.
getInputStream
(
absoluteFilePath
);
...
...
dinky-function/src/main/java/org/dinky/function/compiler/JavaCompiler.java
View file @
443f5011
...
@@ -23,6 +23,7 @@ import org.dinky.function.constant.PathConstant;
...
@@ -23,6 +23,7 @@ import org.dinky.function.constant.PathConstant;
import
org.dinky.function.data.model.UDF
;
import
org.dinky.function.data.model.UDF
;
import
org.apache.flink.configuration.ReadableConfig
;
import
org.apache.flink.configuration.ReadableConfig
;
import
org.apache.flink.table.catalog.FunctionLanguage
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
...
@@ -46,7 +47,7 @@ public class JavaCompiler implements FunctionCompiler {
...
@@ -46,7 +47,7 @@ public class JavaCompiler implements FunctionCompiler {
// TODO 改为ProcessStep注释
// TODO 改为ProcessStep注释
log
.
info
(
"Compiling java code, class: {}"
,
udf
.
getClassName
());
log
.
info
(
"Compiling java code, class: {}"
,
udf
.
getClassName
());
CustomStringJavaCompiler
compiler
=
new
CustomStringJavaCompiler
(
udf
.
getCode
());
CustomStringJavaCompiler
compiler
=
new
CustomStringJavaCompiler
(
udf
.
getCode
());
boolean
res
=
compiler
.
compilerToTmpPath
(
PathConstant
.
getUdfCompiler
JavaPath
(
missionId
));
boolean
res
=
compiler
.
compilerToTmpPath
(
PathConstant
.
getUdfCompiler
Path
(
FunctionLanguage
.
JAVA
));
String
className
=
compiler
.
getFullClassName
();
String
className
=
compiler
.
getFullClassName
();
if
(
res
)
{
if
(
res
)
{
log
.
info
(
"class compiled successfully:{}"
,
className
);
log
.
info
(
"class compiled successfully:{}"
,
className
);
...
...
dinky-function/src/main/java/org/dinky/function/compiler/PythonFunction.java
View file @
443f5011
...
@@ -69,7 +69,8 @@ public class PythonFunction implements FunctionCompiler, FunctionPackage {
...
@@ -69,7 +69,8 @@ public class PythonFunction implements FunctionCompiler, FunctionPackage {
log
.
info
(
"正在编译 python 代码 , class: "
+
udf
.
getClassName
());
log
.
info
(
"正在编译 python 代码 , class: "
+
udf
.
getClassName
());
File
pyFile
=
FileUtil
.
writeUtf8String
(
File
pyFile
=
FileUtil
.
writeUtf8String
(
udf
.
getCode
(),
udf
.
getCode
(),
PathConstant
.
getUdfCompilerPythonPath
(
missionId
,
UDFUtil
.
getPyFileName
(
udf
.
getClassName
())
+
".py"
));
PathConstant
.
getUdfCompilerPath
(
FunctionLanguage
.
PYTHON
,
UDFUtil
.
getPyFileName
(
udf
.
getClassName
())
+
".py"
));
File
zipFile
=
ZipUtil
.
zip
(
pyFile
);
File
zipFile
=
ZipUtil
.
zip
(
pyFile
);
FileUtil
.
del
(
pyFile
);
FileUtil
.
del
(
pyFile
);
try
{
try
{
...
@@ -83,12 +84,12 @@ public class PythonFunction implements FunctionCompiler, FunctionPackage {
...
@@ -83,12 +84,12 @@ public class PythonFunction implements FunctionCompiler, FunctionPackage {
SystemConfiguration
.
getInstances
().
getPythonHome
());
SystemConfiguration
.
getInstances
().
getPythonHome
());
PythonFunctionFactory
.
getPythonFunction
(
udf
.
getClassName
(),
configuration
,
null
);
PythonFunctionFactory
.
getPythonFunction
(
udf
.
getClassName
(),
configuration
,
null
);
log
.
info
(
"Python udf
编译成功 ; className:"
+
udf
.
getClassName
());
log
.
info
(
"Python udf
compiled successfully; className:{}"
,
udf
.
getClassName
());
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"Python udf编译失败 ; className:"
log
.
error
(
+
udf
.
getClassName
()
"Python udf compilation failed; className:{}\n.reason: {}"
,
+
" 。 原因: "
udf
.
getClassName
(),
+
ExceptionUtil
.
getRootCauseMessage
(
e
));
ExceptionUtil
.
getRootCauseMessage
(
e
));
return
false
;
return
false
;
}
}
FileUtil
.
del
(
zipFile
);
FileUtil
.
del
(
zipFile
);
...
@@ -112,8 +113,8 @@ public class PythonFunction implements FunctionCompiler, FunctionPackage {
...
@@ -112,8 +113,8 @@ public class PythonFunction implements FunctionCompiler, FunctionPackage {
.
map
(
udf
->
{
.
map
(
udf
->
{
File
file
=
FileUtil
.
writeUtf8String
(
File
file
=
FileUtil
.
writeUtf8String
(
udf
.
getCode
(),
udf
.
getCode
(),
PathConstant
.
getUdfCompilerP
ythonP
ath
(
PathConstant
.
getUdfCompilerPath
(
missionId
,
UDFUtil
.
getPyFileName
(
udf
.
getClassName
())
+
".py"
));
FunctionLanguage
.
PYTHON
,
UDFUtil
.
getPyFileName
(
udf
.
getClassName
())
+
".py"
));
return
FileUtil
.
getInputStream
(
file
);
return
FileUtil
.
getInputStream
(
file
);
})
})
.
toArray
(
InputStream
[]::
new
);
.
toArray
(
InputStream
[]::
new
);
...
...
dinky-function/src/main/java/org/dinky/function/compiler/ScalaCompiler.java
View file @
443f5011
...
@@ -39,7 +39,7 @@ public class ScalaCompiler implements FunctionCompiler {
...
@@ -39,7 +39,7 @@ public class ScalaCompiler implements FunctionCompiler {
String
className
=
udf
.
getClassName
();
String
className
=
udf
.
getClassName
();
log
.
info
(
"正在编译 scala 代码 , class: "
+
className
);
log
.
info
(
"正在编译 scala 代码 , class: "
+
className
);
if
(
CustomStringScalaCompiler
.
getInterpreter
(
missionId
).
compileString
(
udf
.
getCode
()))
{
if
(
CustomStringScalaCompiler
.
getInterpreter
().
compileString
(
udf
.
getCode
()))
{
log
.
info
(
"scala class编译成功:"
+
className
);
log
.
info
(
"scala class编译成功:"
+
className
);
return
true
;
return
true
;
}
else
{
}
else
{
...
...
dinky-function/src/main/java/org/dinky/function/constant/PathConstant.java
View file @
443f5011
...
@@ -19,6 +19,8 @@
...
@@ -19,6 +19,8 @@
package
org
.
dinky
.
function
.
constant
;
package
org
.
dinky
.
function
.
constant
;
import
org.apache.flink.table.catalog.FunctionLanguage
;
import
java.io.File
;
import
java.io.File
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
...
@@ -58,12 +60,12 @@ public class PathConstant {
...
@@ -58,12 +60,12 @@ public class PathConstant {
return
StrUtil
.
join
(
File
.
separator
,
path
)
+
File
.
separator
;
return
StrUtil
.
join
(
File
.
separator
,
path
)
+
File
.
separator
;
}
}
public
static
String
getUdfCompiler
JavaPath
(
Integer
missionId
,
Object
...
path
)
{
public
static
String
getUdfCompiler
Path
(
FunctionLanguage
language
,
String
fileName
)
{
return
getPath
(
UDF_PATH
,
missionId
,
COMPILER
,
"java"
,
path
);
return
getPath
(
UDF_PATH
,
COMPILER
,
language
.
name
(),
fileName
);
}
}
public
static
String
getUdfCompilerP
ythonPath
(
Integer
missionId
,
Object
...
path
)
{
public
static
String
getUdfCompilerP
ath
(
FunctionLanguage
language
)
{
return
getPath
(
UDF_PATH
,
missionId
,
COMPILER
,
"python"
,
path
);
return
getPath
(
UDF_PATH
,
COMPILER
,
language
.
name
()
);
}
}
public
static
String
getUdfPackagePath
(
Integer
missionId
,
Object
...
path
)
{
public
static
String
getUdfPackagePath
(
Integer
missionId
,
Object
...
path
)
{
...
...
dinky-function/src/main/java/org/dinky/function/util/UDFUtil.java
View file @
443f5011
...
@@ -214,7 +214,7 @@ public class UDFUtil {
...
@@ -214,7 +214,7 @@ public class UDFUtil {
}
}
}
else
if
(
udf
.
getFunctionLanguage
()
==
FunctionLanguage
.
SCALA
)
{
}
else
if
(
udf
.
getFunctionLanguage
()
==
FunctionLanguage
.
SCALA
)
{
String
className
=
udf
.
getClassName
();
String
className
=
udf
.
getClassName
();
if
(
CustomStringScalaCompiler
.
getInterpreter
(
null
).
compileString
(
udf
.
getCode
()))
{
if
(
CustomStringScalaCompiler
.
getInterpreter
().
compileString
(
udf
.
getCode
()))
{
log
.
info
(
"scala class compile successful:{}"
,
className
);
log
.
info
(
"scala class compile successful:{}"
,
className
);
ClassPool
.
push
(
ClassEntity
.
build
(
className
,
udf
.
getCode
()));
ClassPool
.
push
(
ClassEntity
.
build
(
className
,
udf
.
getCode
()));
successList
.
add
(
className
);
successList
.
add
(
className
);
...
...
dinky-web/src/pages/DataStudio/RightContainer/JobConfig/function.tsx
View file @
443f5011
...
@@ -37,43 +37,43 @@ export const buildRunModelOptions = () => {
...
@@ -37,43 +37,43 @@ export const buildRunModelOptions = () => {
{
{
label
:
'Local'
,
label
:
'Local'
,
value
:
RUN_MODE
.
LOCAL
,
value
:
RUN_MODE
.
LOCAL
,
key
:
RUN_MODE
.
LOCAL
,
key
:
RUN_MODE
.
LOCAL
},
},
{
{
label
:
'Standalone'
,
label
:
'Standalone'
,
value
:
RUN_MODE
.
STANDALONE
,
value
:
RUN_MODE
.
STANDALONE
,
key
:
RUN_MODE
.
STANDALONE
,
key
:
RUN_MODE
.
STANDALONE
},
},
{
{
label
:
'Yarn Session'
,
label
:
'Yarn Session'
,
value
:
RUN_MODE
.
YARN_SESSION
,
value
:
RUN_MODE
.
YARN_SESSION
,
key
:
RUN_MODE
.
YARN_SESSION
,
key
:
RUN_MODE
.
YARN_SESSION
},
},
{
{
// flink弃用了 yarn per-job 模式 在这写个标签 带横线的 | flink deprecated yarn per-job mode, write a label here with a horizontal line
// flink弃用了 yarn per-job 模式 在这写个标签 带横线的 | flink deprecated yarn per-job mode, write a label here with a horizontal line
label
:
<
del
>
Yarn Per-Job (Deprecated)
</
del
>,
label
:
<
del
>
Yarn Per-Job (Deprecated)
</
del
>,
value
:
RUN_MODE
.
YARN_PER_JOB
,
value
:
RUN_MODE
.
YARN_PER_JOB
,
key
:
RUN_MODE
.
YARN_PER_JOB
,
key
:
RUN_MODE
.
YARN_PER_JOB
},
},
{
{
label
:
'Yarn Application'
,
label
:
'Yarn Application'
,
value
:
RUN_MODE
.
YARN_APPLICATION
,
value
:
RUN_MODE
.
YARN_APPLICATION
,
key
:
RUN_MODE
.
YARN_APPLICATION
,
key
:
RUN_MODE
.
YARN_APPLICATION
},
},
{
{
label
:
'Kubernetes Session'
,
label
:
'Kubernetes Session'
,
value
:
RUN_MODE
.
KUBERNETES_SESSION
,
value
:
RUN_MODE
.
KUBERNETES_SESSION
,
key
:
RUN_MODE
.
KUBERNETES_SESSION
,
key
:
RUN_MODE
.
KUBERNETES_SESSION
},
},
{
{
label
:
'Kubernetes Application'
,
label
:
'Kubernetes Application'
,
value
:
RUN_MODE
.
KUBERNETES_APPLICATION
,
value
:
RUN_MODE
.
KUBERNETES_APPLICATION
,
key
:
RUN_MODE
.
KUBERNETES_APPLICATION
,
key
:
RUN_MODE
.
KUBERNETES_APPLICATION
},
},
{
{
label
:
'Kubernetes Operator Application'
,
label
:
'Kubernetes Operator Application'
,
value
:
RUN_MODE
.
KUBERNETES_APPLICATION_OPERATOR
,
value
:
RUN_MODE
.
KUBERNETES_APPLICATION_OPERATOR
,
key
:
RUN_MODE
.
KUBERNETES_APPLICATION_OPERATOR
,
key
:
RUN_MODE
.
KUBERNETES_APPLICATION_OPERATOR
}
}
);
);
...
@@ -165,7 +165,7 @@ export const buildEnvOptions = (env: TaskInfo[] = []) => {
...
@@ -165,7 +165,7 @@ export const buildEnvOptions = (env: TaskInfo[] = []) => {
{
l
(
'button.disable'
)
}
{
l
(
'button.disable'
)
}
</
Space
>
</
Space
>
),
),
title
:
l
(
'button.disable'
),
title
:
l
(
'button.disable'
),
value
:
-
1
,
value
:
-
1
,
key
:
-
1
key
:
-
1
}
}
...
...
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