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
78a179b1
Unverified
Commit
78a179b1
authored
Jan 24, 2024
by
ZackYoung
Committed by
GitHub
Jan 24, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Bug] [UDF] fix udf some bug (#3045)
parent
3de42d73
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
82 additions
and
100 deletions
+82
-100
AppConfig.java
dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
+1
-2
TaskServiceImpl.java
...src/main/java/org/dinky/service/impl/TaskServiceImpl.java
+8
-3
Submitter.java
...-base/src/main/java/org/dinky/app/flinksql/Submitter.java
+35
-48
CustomTableEnvironmentImpl.java
...n/java/org/dinky/executor/CustomTableEnvironmentImpl.java
+1
-20
CustomTableEnvironmentImpl.java
...n/java/org/dinky/executor/CustomTableEnvironmentImpl.java
+2
-23
CustomTableEnvironment.java
.../main/java/org/dinky/executor/CustomTableEnvironment.java
+1
-1
Executor.java
dinky-core/src/main/java/org/dinky/executor/Executor.java
+18
-0
JobManager.java
dinky-core/src/main/java/org/dinky/job/JobManager.java
+6
-0
UdfCodePool.java
...on/src/main/java/org/dinky/function/pool/UdfCodePool.java
+4
-0
UDFUtil.java
...nction/src/main/java/org/dinky/function/util/UDFUtil.java
+3
-3
KubernetesGateway.java
.../java/org/dinky/gateway/kubernetes/KubernetesGateway.java
+3
-0
No files found.
dinky-admin/src/main/java/org/dinky/configure/AppConfig.java
View file @
78a179b1
...
@@ -81,8 +81,7 @@ public class AppConfig implements WebMvcConfigurer {
...
@@ -81,8 +81,7 @@ public class AppConfig implements WebMvcConfigurer {
}))
}))
.
addPathPatterns
(
"/api/**"
)
.
addPathPatterns
(
"/api/**"
)
.
excludePathPatterns
(
.
excludePathPatterns
(
"/api/login"
,
"/api/ldap/ldapEnableStatus"
,
"/api/login"
,
"/api/ldap/ldapEnableStatus"
,
"/download/**"
,
"/druid/**"
,
"/openapi/**"
);
"/druid/**"
,
"/openapi/**"
);
registry
.
addInterceptor
(
new
TenantInterceptor
())
registry
.
addInterceptor
(
new
TenantInterceptor
())
.
addPathPatterns
(
"/api/**"
)
.
addPathPatterns
(
"/api/**"
)
...
...
dinky-admin/src/main/java/org/dinky/service/impl/TaskServiceImpl.java
View file @
78a179b1
...
@@ -596,17 +596,22 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
...
@@ -596,17 +596,22 @@ public class TaskServiceImpl extends SuperServiceImpl<TaskMapper, Task> implemen
task
.
setStatement
(
code
);
task
.
setStatement
(
code
);
}
}
}
}
String
className
=
""
;
// to compiler udf
// to compiler udf
if
(
Asserts
.
isNotNullString
(
task
.
getDialect
())
if
(
Asserts
.
isNotNullString
(
task
.
getDialect
())
&&
Dialect
.
JAVA
.
isDialect
(
task
.
getDialect
())
&&
Dialect
.
JAVA
.
isDialect
(
task
.
getDialect
())
&&
Asserts
.
isNotNullString
(
task
.
getStatement
()))
{
&&
Asserts
.
isNotNullString
(
task
.
getStatement
()))
{
CustomStringJavaCompiler
compiler
=
new
CustomStringJavaCompiler
(
task
.
getStatement
());
CustomStringJavaCompiler
compiler
=
new
CustomStringJavaCompiler
(
task
.
getStatement
());
task
.
setSavePointPath
(
compiler
.
getFullClassName
()
);
className
=
compiler
.
getFullClassName
(
);
}
else
if
(
Dialect
.
PYTHON
.
isDialect
(
task
.
getDialect
()))
{
}
else
if
(
Dialect
.
PYTHON
.
isDialect
(
task
.
getDialect
()))
{
task
.
setSavePointPath
(
task
.
getName
()
+
"."
+
UDFUtil
.
getPyUDFAttr
(
task
.
getStatement
()
));
className
=
task
.
getName
()
+
"."
+
UDFUtil
.
getPyUDFAttr
(
task
.
getStatement
(
));
}
else
if
(
Dialect
.
SCALA
.
isDialect
(
task
.
getDialect
()))
{
}
else
if
(
Dialect
.
SCALA
.
isDialect
(
task
.
getDialect
()))
{
task
.
setSavePointPath
(
UDFUtil
.
getScalaFullClassName
(
task
.
getStatement
()
));
className
=
UDFUtil
.
getScalaFullClassName
(
task
.
getStatement
(
));
}
}
if
(!
task
.
getConfigJson
().
getUdfConfig
().
getClassName
().
equals
(
className
))
{
UdfCodePool
.
remove
(
task
.
getConfigJson
().
getUdfConfig
().
getClassName
());
}
task
.
getConfigJson
().
getUdfConfig
().
setClassName
(
className
);
UdfCodePool
.
addOrUpdate
(
UDFUtils
.
taskToUDF
(
task
));
UdfCodePool
.
addOrUpdate
(
UDFUtils
.
taskToUDF
(
task
));
}
}
...
...
dinky-app/dinky-app-base/src/main/java/org/dinky/app/flinksql/Submitter.java
View file @
78a179b1
...
@@ -46,7 +46,6 @@ import org.dinky.utils.ZipUtils;
...
@@ -46,7 +46,6 @@ import org.dinky.utils.ZipUtils;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.io.FileUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.commons.lang3.StringUtils
;
import
org.apache.flink.configuration.PipelineOptions
;
import
org.apache.flink.configuration.ReadableConfig
;
import
org.apache.flink.configuration.ReadableConfig
;
import
org.apache.flink.core.execution.JobClient
;
import
org.apache.flink.core.execution.JobClient
;
import
org.apache.flink.python.PythonOptions
;
import
org.apache.flink.python.PythonOptions
;
...
@@ -56,13 +55,10 @@ import org.apache.flink.streaming.api.graph.StreamGraph;
...
@@ -56,13 +55,10 @@ import org.apache.flink.streaming.api.graph.StreamGraph;
import
org.apache.flink.table.api.TableResult
;
import
org.apache.flink.table.api.TableResult
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.lang.ref.WeakReference
;
import
java.lang.ref.WeakReference
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.net.URL
;
import
java.net.URLClassLoader
;
import
java.net.URLClassLoader
;
import
java.sql.SQLException
;
import
java.sql.SQLException
;
...
@@ -82,6 +78,7 @@ import cn.hutool.core.collection.CollUtil;
...
@@ -82,6 +78,7 @@ import cn.hutool.core.collection.CollUtil;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.ArrayUtil
;
import
cn.hutool.core.util.URLUtil
;
import
cn.hutool.core.util.URLUtil
;
import
cn.hutool.http.HttpUtil
;
import
lombok.SneakyThrows
;
import
lombok.SneakyThrows
;
/**
/**
...
@@ -126,8 +123,7 @@ public class Submitter {
...
@@ -126,8 +123,7 @@ public class Submitter {
executorConfig
,
new
WeakReference
<>(
DinkyClassLoader
.
build
()).
get
());
executorConfig
,
new
WeakReference
<>(
DinkyClassLoader
.
build
()).
get
());
// 加载第三方jar //TODO 这里有问题,需要修一修
// 加载第三方jar //TODO 这里有问题,需要修一修
// loadDep(appTask.getType(),
loadDep
(
appTask
.
getType
(),
config
.
getTaskId
(),
executorConfig
);
// config.getTaskId(),DBUtil.getSysConfig(Status.SYS_ENV_SETTINGS_DINKYADDR.getKey()), executorConfig);
log
.
info
(
"The job configuration is as follows: {}"
,
executorConfig
);
log
.
info
(
"The job configuration is as follows: {}"
,
executorConfig
);
String
[]
statements
=
String
[]
statements
=
...
@@ -169,7 +165,8 @@ public class Submitter {
...
@@ -169,7 +165,8 @@ public class Submitter {
return
sb
.
toString
();
return
sb
.
toString
();
}
}
private
static
void
loadDep
(
String
type
,
Integer
taskId
,
String
dinkyAddr
,
ExecutorConfig
executorConfig
)
{
private
static
void
loadDep
(
String
type
,
Integer
taskId
,
ExecutorConfig
executorConfig
)
{
String
dinkyAddr
=
SystemConfiguration
.
getInstances
().
getDinkyAddr
().
getValue
();
if
(
StringUtils
.
isBlank
(
dinkyAddr
))
{
if
(
StringUtils
.
isBlank
(
dinkyAddr
))
{
return
;
return
;
}
}
...
@@ -187,32 +184,35 @@ public class Submitter {
...
@@ -187,32 +184,35 @@ public class Submitter {
if
(
exists
)
{
if
(
exists
)
{
String
depPath
=
flinkHome
+
"/dep"
;
String
depPath
=
flinkHome
+
"/dep"
;
ZipUtils
.
unzip
(
depZip
,
depPath
);
ZipUtils
.
unzip
(
depZip
,
depPath
);
log
.
info
(
"download dep success, include :{}"
,
Arrays
.
stream
(
FileUtil
.
file
(
depPath
).
listFiles
())
.
map
(
File:
:
getName
)
.
collect
(
Collectors
.
joining
(
",\n"
)));
// move all jar
// move all jar
FileUtil
.
listFileNames
(
depPath
+
"/jar"
).
forEach
(
f
->
{
FileUtil
.
listFileNames
(
depPath
+
"/jar"
).
forEach
(
f
->
{
FileUtil
.
moveContent
(
FileUtil
.
move
(
FileUtil
.
file
(
depPath
+
"/jar/"
+
f
),
FileUtil
.
file
(
usrlib
+
"/"
+
f
),
true
);
FileUtil
.
file
(
depPath
+
"/jar/"
+
f
),
FileUtil
.
file
(
usrlib
+
"/"
+
f
),
true
);
});
});
URL
[]
jarUrls
=
FileUtil
.
listFileNames
(
usrlib
).
stream
()
if
(
FileUtil
.
isDirectory
(
usrlib
))
{
.
map
(
f
->
URLUtil
.
getURL
(
FileUtil
.
file
(
usrlib
,
f
)))
URL
[]
jarUrls
=
FileUtil
.
listFileNames
(
usrlib
).
stream
()
.
toArray
(
URL
[]::
new
);
.
map
(
f
->
URLUtil
.
getURL
(
FileUtil
.
file
(
usrlib
,
f
)))
URL
[]
pyUrls
=
FileUtil
.
listFileNames
(
depPath
+
"/py/"
).
stream
()
.
toArray
(
URL
[]::
new
);
.
map
(
f
->
URLUtil
.
getURL
(
FileUtil
.
file
(
depPath
+
"/py/"
,
f
)))
addURLs
(
jarUrls
);
.
toArray
(
URL
[]::
new
);
executor
.
getCustomTableEnvironment
()
.
addJar
(
FileUtil
.
file
(
usrlib
).
listFiles
());
addURLs
(
jarUrls
);
}
executorConfig
if
(
FileUtil
.
isDirectory
(
depPath
+
"/py/"
))
{
.
getConfig
()
URL
[]
pyUrls
=
FileUtil
.
listFileNames
(
depPath
+
"/py/"
).
stream
()
.
put
(
.
map
(
f
->
URLUtil
.
getURL
(
FileUtil
.
file
(
depPath
+
"/py/"
,
f
)))
PipelineOptions
.
JARS
.
key
(),
.
toArray
(
URL
[]::
new
);
Arrays
.
stream
(
jarUrls
).
map
(
URL:
:
toString
).
collect
(
Collectors
.
joining
(
";"
)));
if
(
ArrayUtil
.
isNotEmpty
(
pyUrls
))
{
if
(
ArrayUtil
.
isNotEmpty
(
pyUrls
))
{
executor
.
getCustomTableEnvironment
()
executorConfig
.
addConfiguration
(
.
getConfig
()
PythonOptions
.
PYTHON_FILES
,
.
put
(
Arrays
.
stream
(
pyUrls
)
PythonOptions
.
PYTHON_FILES
.
key
(),
.
map
(
URL:
:
toString
)
Arrays
.
stream
(
jarUrls
)
.
collect
(
Collectors
.
joining
(
","
)));
.
map
(
URL:
:
toString
)
}
.
collect
(
Collectors
.
joining
(
","
)));
}
}
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -220,11 +220,11 @@ public class Submitter {
...
@@ -220,11 +220,11 @@ public class Submitter {
throw
new
RuntimeException
(
e
);
throw
new
RuntimeException
(
e
);
}
}
}
}
executorConfig
.
getConfig
().
put
(
"python.files"
,
"./python_udf.zip"
);
}
}
private
static
void
addURLs
(
URL
[]
jarUrls
)
{
private
static
void
addURLs
(
URL
[]
jarUrls
)
{
URLClassLoader
urlClassLoader
=
(
URLClassLoader
)
ClassLoader
.
getSystemClassLoader
();
Thread
.
currentThread
().
setContextClassLoader
(
new
DinkyClassLoader
(
new
URL
[]
{}));
URLClassLoader
urlClassLoader
=
(
URLClassLoader
)
Thread
.
currentThread
().
getContextClassLoader
();
try
{
try
{
Method
add
=
URLClassLoader
.
class
.
getDeclaredMethod
(
"addURL"
,
URL
.
class
);
Method
add
=
URLClassLoader
.
class
.
getDeclaredMethod
(
"addURL"
,
URL
.
class
);
add
.
setAccessible
(
true
);
add
.
setAccessible
(
true
);
...
@@ -238,23 +238,10 @@ public class Submitter {
...
@@ -238,23 +238,10 @@ public class Submitter {
public
static
boolean
downloadFile
(
String
url
,
String
path
)
throws
IOException
{
public
static
boolean
downloadFile
(
String
url
,
String
path
)
throws
IOException
{
try
{
try
{
HttpURLConnection
conn
=
(
HttpURLConnection
)
new
URL
(
url
).
openConnection
();
HttpUtil
.
downloadFile
(
url
,
path
);
// 设置超时间为3秒
return
true
;
conn
.
setConnectTimeout
(
3
*
1000
);
// 获取输入流
try
(
InputStream
inputStream
=
conn
.
getInputStream
())
{
// 获取输出流
try
(
FileOutputStream
outputStream
=
new
FileOutputStream
(
path
))
{
// 每次下载1024位
byte
[]
b
=
new
byte
[
1024
];
int
len
=
-
1
;
while
((
len
=
inputStream
.
read
(
b
))
!=
-
1
)
{
outputStream
.
write
(
b
,
0
,
len
);
}
return
true
;
}
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
log
.
error
(
"download failed, Reason:"
,
e
);
return
false
;
return
false
;
}
}
}
}
...
...
dinky-client/dinky-client-1.14/src/main/java/org/dinky/executor/CustomTableEnvironmentImpl.java
View file @
78a179b1
...
@@ -62,23 +62,17 @@ import org.apache.flink.table.operations.Operation;
...
@@ -62,23 +62,17 @@ import org.apache.flink.table.operations.Operation;
import
org.apache.flink.table.operations.QueryOperation
;
import
org.apache.flink.table.operations.QueryOperation
;
import
org.apache.flink.table.planner.delegation.DefaultExecutor
;
import
org.apache.flink.table.planner.delegation.DefaultExecutor
;
import
java.io.File
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.InvocationTargetException
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ReflectUtil
;
import
cn.hutool.core.util.ReflectUtil
;
import
cn.hutool.core.util.URLUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
/**
/**
...
@@ -230,23 +224,10 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
...
@@ -230,23 +224,10 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
}
}
}
}
@Override
public
void
addJar
(
File
...
jarPath
)
{
Configuration
configuration
=
(
Configuration
)
getStreamExecutionEnvironment
().
getConfiguration
();
List
<
String
>
pathList
=
Arrays
.
stream
(
URLUtil
.
getURLs
(
jarPath
)).
map
(
URL:
:
toString
).
collect
(
Collectors
.
toList
());
List
<
String
>
jars
=
configuration
.
get
(
PipelineOptions
.
JARS
);
if
(
jars
!=
null
)
{
CollUtil
.
addAll
(
jars
,
pathList
);
}
Map
<
String
,
Object
>
flinkConfigurationMap
=
getFlinkConfigurationMap
();
flinkConfigurationMap
.
put
(
PipelineOptions
.
JARS
.
key
(),
jars
);
}
@Override
@Override
public
<
T
>
void
addConfiguration
(
ConfigOption
<
T
>
option
,
T
value
)
{
public
<
T
>
void
addConfiguration
(
ConfigOption
<
T
>
option
,
T
value
)
{
Map
<
String
,
Object
>
flinkConfigurationMap
=
getFlinkConfigurationMap
();
Map
<
String
,
Object
>
flinkConfigurationMap
=
getFlinkConfigurationMap
();
getConfig
().
addConfiguration
(
new
Configuration
().
set
(
option
,
value
));
flinkConfigurationMap
.
put
(
option
.
key
(),
value
);
flinkConfigurationMap
.
put
(
option
.
key
(),
value
);
}
}
...
...
dinky-client/dinky-client-1.15/src/main/java/org/dinky/executor/CustomTableEnvironmentImpl.java
View file @
78a179b1
...
@@ -62,22 +62,17 @@ import org.apache.flink.table.operations.ModifyOperation;
...
@@ -62,22 +62,17 @@ import org.apache.flink.table.operations.ModifyOperation;
import
org.apache.flink.table.operations.Operation
;
import
org.apache.flink.table.operations.Operation
;
import
org.apache.flink.table.operations.QueryOperation
;
import
org.apache.flink.table.operations.QueryOperation
;
import
java.io.File
;
import
java.lang.reflect.Field
;
import
java.lang.reflect.Field
;
import
java.net.URL
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Optional
;
import
java.util.Optional
;
import
java.util.stream.Collectors
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.core.JsonProcessingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.URLUtil
;
/**
/**
* CustomTableEnvironmentImpl
* CustomTableEnvironmentImpl
...
@@ -210,32 +205,16 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
...
@@ -210,32 +205,16 @@ public class CustomTableEnvironmentImpl extends AbstractCustomTableEnvironment {
}
}
}
}
@Override
public
void
addJar
(
File
...
jarPath
)
{
Configuration
configuration
=
(
Configuration
)
getStreamExecutionEnvironment
().
getConfiguration
();
List
<
String
>
pathList
=
Arrays
.
stream
(
URLUtil
.
getURLs
(
jarPath
)).
map
(
URL:
:
toString
).
collect
(
Collectors
.
toList
());
List
<
String
>
jars
=
configuration
.
get
(
PipelineOptions
.
JARS
);
if
(
jars
!=
null
)
{
CollUtil
.
addAll
(
jars
,
pathList
);
}
Map
<
String
,
Object
>
flinkConfigurationMap
=
getFlinkConfigurationMap
();
flinkConfigurationMap
.
put
(
PipelineOptions
.
JARS
.
key
(),
jars
);
}
@Override
@Override
public
<
T
>
void
addConfiguration
(
ConfigOption
<
T
>
option
,
T
value
)
{
public
<
T
>
void
addConfiguration
(
ConfigOption
<
T
>
option
,
T
value
)
{
Map
<
String
,
Object
>
flinkConfigurationMap
=
getFlinkConfigurationMap
();
Map
<
String
,
Object
>
flinkConfigurationMap
=
getFlinkConfigurationMap
();
getConfig
().
set
(
option
,
value
);
flinkConfigurationMap
.
put
(
option
.
key
(),
value
);
flinkConfigurationMap
.
put
(
option
.
key
(),
value
);
}
}
private
Map
<
String
,
Object
>
getFlinkConfigurationMap
()
{
private
Map
<
String
,
Object
>
getFlinkConfigurationMap
()
{
Field
configuration
=
null
;
try
{
try
{
configuration
=
StreamExecutionEnvironment
.
class
.
getDeclaredField
(
"configuration"
);
Configuration
o
=
getRootConfiguration
();
configuration
.
setAccessible
(
true
);
Configuration
o
=
(
Configuration
)
configuration
.
get
(
getStreamExecutionEnvironment
());
Field
confData
=
Configuration
.
class
.
getDeclaredField
(
"confData"
);
Field
confData
=
Configuration
.
class
.
getDeclaredField
(
"confData"
);
confData
.
setAccessible
(
true
);
confData
.
setAccessible
(
true
);
Map
<
String
,
Object
>
temp
=
(
Map
<
String
,
Object
>)
confData
.
get
(
o
);
Map
<
String
,
Object
>
temp
=
(
Map
<
String
,
Object
>)
confData
.
get
(
o
);
...
...
dinky-client/dinky-client-base/src/main/java/org/dinky/executor/CustomTableEnvironment.java
View file @
78a179b1
...
@@ -84,7 +84,7 @@ public interface CustomTableEnvironment
...
@@ -84,7 +84,7 @@ public interface CustomTableEnvironment
Arrays
.
stream
(
URLUtil
.
getURLs
(
jarPath
)).
map
(
URL:
:
toString
).
collect
(
Collectors
.
toList
());
Arrays
.
stream
(
URLUtil
.
getURLs
(
jarPath
)).
map
(
URL:
:
toString
).
collect
(
Collectors
.
toList
());
List
<
String
>
jars
=
configuration
.
get
(
PipelineOptions
.
JARS
);
List
<
String
>
jars
=
configuration
.
get
(
PipelineOptions
.
JARS
);
if
(
jars
==
null
)
{
if
(
jars
==
null
)
{
configuration
.
set
(
PipelineOptions
.
JARS
,
pathList
);
addConfiguration
(
PipelineOptions
.
JARS
,
pathList
);
}
else
{
}
else
{
CollUtil
.
addAll
(
jars
,
pathList
);
CollUtil
.
addAll
(
jars
,
pathList
);
}
}
...
...
dinky-core/src/main/java/org/dinky/executor/Executor.java
View file @
78a179b1
...
@@ -60,13 +60,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
...
@@ -60,13 +60,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ReflectUtil
;
import
cn.hutool.core.util.URLUtil
;
import
cn.hutool.core.util.URLUtil
;
import
lombok.extern.slf4j.Slf4j
;
/**
/**
* Executor
* Executor
*
*
* @since 2021/11/17
* @since 2021/11/17
*/
*/
@Slf4j
public
abstract
class
Executor
{
public
abstract
class
Executor
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Executor
.
class
);
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
Executor
.
class
);
...
@@ -133,7 +136,22 @@ public abstract class Executor {
...
@@ -133,7 +136,22 @@ public abstract class Executor {
return
getTableConfig
().
getLocalTimeZone
().
getId
();
return
getTableConfig
().
getLocalTimeZone
().
getId
();
}
}
private
void
initClassloader
(
DinkyClassLoader
classLoader
)
{
if
(
classLoader
!=
null
)
{
try
{
StreamExecutionEnvironment
env
=
this
.
environment
;
// Fix the Classloader in the env above to appClassLoader, causing ckp to fail to compile
ReflectUtil
.
setFieldValue
(
env
,
"userClassloader"
,
classLoader
);
env
.
configure
(
env
.
getConfiguration
(),
classLoader
);
}
catch
(
Throwable
e
)
{
log
.
warn
(
"The version of flink does not have a Classloader field and the classloader cannot be set."
,
e
);
}
}
}
protected
void
init
(
DinkyClassLoader
classLoader
)
{
protected
void
init
(
DinkyClassLoader
classLoader
)
{
initClassloader
(
classLoader
);
this
.
dinkyClassLoader
=
classLoader
;
this
.
dinkyClassLoader
=
classLoader
;
if
(
executorConfig
.
isValidParallelism
())
{
if
(
executorConfig
.
isValidParallelism
())
{
environment
.
setParallelism
(
executorConfig
.
getParallelism
());
environment
.
setParallelism
(
executorConfig
.
getParallelism
());
...
...
dinky-core/src/main/java/org/dinky/job/JobManager.java
View file @
78a179b1
...
@@ -79,6 +79,7 @@ import org.apache.flink.table.api.TableResult;
...
@@ -79,6 +79,7 @@ import org.apache.flink.table.api.TableResult;
import
org.apache.flink.yarn.configuration.YarnConfigOptions
;
import
org.apache.flink.yarn.configuration.YarnConfigOptions
;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.lang.ref.WeakReference
;
import
java.lang.ref.WeakReference
;
import
java.time.LocalDateTime
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -235,6 +236,11 @@ public class JobManager {
...
@@ -235,6 +236,11 @@ public class JobManager {
public
boolean
close
()
{
public
boolean
close
()
{
CustomTableEnvironmentContext
.
clear
();
CustomTableEnvironmentContext
.
clear
();
RowLevelPermissionsContext
.
clear
();
RowLevelPermissionsContext
.
clear
();
try
{
getExecutor
().
getDinkyClassLoader
().
close
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
return
true
;
return
true
;
}
}
...
...
dinky-function/src/main/java/org/dinky/function/pool/UdfCodePool.java
View file @
78a179b1
...
@@ -52,6 +52,10 @@ public class UdfCodePool {
...
@@ -52,6 +52,10 @@ public class UdfCodePool {
CODE_POOL
.
put
(
udf
.
getClassName
(),
udf
);
CODE_POOL
.
put
(
udf
.
getClassName
(),
udf
);
}
}
public
static
void
remove
(
String
className
)
{
CODE_POOL
.
remove
(
className
);
}
public
static
UDF
getUDF
(
String
className
)
{
public
static
UDF
getUDF
(
String
className
)
{
UDF
udf
=
CODE_POOL
.
get
(
className
);
UDF
udf
=
CODE_POOL
.
get
(
className
);
if
(
udf
==
null
)
{
if
(
udf
==
null
)
{
...
...
dinky-function/src/main/java/org/dinky/function/util/UDFUtil.java
View file @
78a179b1
...
@@ -95,7 +95,7 @@ import cn.hutool.json.JSONUtil;
...
@@ -95,7 +95,7 @@ import cn.hutool.json.JSONUtil;
public
class
UDFUtil
{
public
class
UDFUtil
{
public
static
final
String
FUNCTION_SQL_REGEX
=
public
static
final
String
FUNCTION_SQL_REGEX
=
"^CREATE\\s+(?:(?:TEMPORARY|TEMPORARY\\s+SYSTEM)\\s+)?FUNCTION\\s+(?:IF\\s+NOT\\s+EXISTS\\s+)?(\\S+)\\s+AS\\s+'(\\S+)'\\s*(?:LANGUAGE\\s+(?:JAVA|SCALA|PYTHON)\\s
+
)?(?:USING\\s+JAR\\s+'(\\S+)'\\s*(?:,\\s*JAR\\s+'(\\S+)'\\s*)*)?"
;
"^CREATE\\s+(?:(?:TEMPORARY|TEMPORARY\\s+SYSTEM)\\s+)?FUNCTION\\s+(?:IF\\s+NOT\\s+EXISTS\\s+)?(\\S+)\\s+AS\\s+'(\\S+)'\\s*(?:LANGUAGE\\s+(?:JAVA|SCALA|PYTHON)\\s
*
)?(?:USING\\s+JAR\\s+'(\\S+)'\\s*(?:,\\s*JAR\\s+'(\\S+)'\\s*)*)?"
;
public
static
final
Pattern
PATTERN
=
Pattern
.
compile
(
FUNCTION_SQL_REGEX
,
Pattern
.
CASE_INSENSITIVE
);
public
static
final
Pattern
PATTERN
=
Pattern
.
compile
(
FUNCTION_SQL_REGEX
,
Pattern
.
CASE_INSENSITIVE
);
public
static
final
String
SESSION
=
"SESSION"
;
public
static
final
String
SESSION
=
"SESSION"
;
...
@@ -118,7 +118,7 @@ public class UDFUtil {
...
@@ -118,7 +118,7 @@ public class UDFUtil {
*/
*/
protected
static
final
Map
<
String
,
Integer
>
UDF_MD5_MAP
=
new
HashMap
<>();
protected
static
final
Map
<
String
,
Integer
>
UDF_MD5_MAP
=
new
HashMap
<>();
public
static
final
String
PYTHON_UDF_ATTR
=
"(\\S
)\\s+=\\s+
ud(?:f|tf|af|taf)"
;
public
static
final
String
PYTHON_UDF_ATTR
=
"(\\S
+)\\s*=\\s*
ud(?:f|tf|af|taf)"
;
public
static
final
String
PYTHON_UDF_DEF
=
"@ud(?:f|tf|af|taf).*\\n+def\\s+(.*)\\(.*\\):"
;
public
static
final
String
PYTHON_UDF_DEF
=
"@ud(?:f|tf|af|taf).*\\n+def\\s+(.*)\\(.*\\):"
;
public
static
final
String
SCALA_UDF_CLASS
=
"class\\s+(\\w+)(\\s*\\(.*\\)){0,1}\\s+extends"
;
public
static
final
String
SCALA_UDF_CLASS
=
"class\\s+(\\w+)(\\s*\\(.*\\)){0,1}\\s+extends"
;
public
static
final
String
SCALA_UDF_PACKAGE
=
"package\\s+(.*);"
;
public
static
final
String
SCALA_UDF_PACKAGE
=
"package\\s+(.*);"
;
...
@@ -343,7 +343,7 @@ public class UDFUtil {
...
@@ -343,7 +343,7 @@ public class UDFUtil {
String
gitPackage
=
UdfCodePool
.
getGitPackage
(
className
);
String
gitPackage
=
UdfCodePool
.
getGitPackage
(
className
);
if
(
StrUtil
.
isNotBlank
(
gitPackage
)
&&
FileUtil
.
exist
(
gitPackage
))
{
if
(
StrUtil
.
isNotBlank
(
gitPackage
)
&&
FileUtil
.
exist
(
gitPackage
))
{
if
(
FileUtil
.
getSuffix
(
gitPackage
).
equals
(
"jar"
))
{
if
(
"jar"
.
equals
(
FileUtil
.
getSuffix
(
gitPackage
)
))
{
udfPathContextHolder
.
addUdfPath
(
new
File
(
gitPackage
));
udfPathContextHolder
.
addUdfPath
(
new
File
(
gitPackage
));
}
else
{
}
else
{
udfPathContextHolder
.
addPyUdfPath
(
new
File
(
gitPackage
));
udfPathContextHolder
.
addPyUdfPath
(
new
File
(
gitPackage
));
...
...
dinky-gateway/src/main/java/org/dinky/gateway/kubernetes/KubernetesGateway.java
View file @
78a179b1
...
@@ -40,6 +40,7 @@ import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
...
@@ -40,6 +40,7 @@ import org.apache.flink.kubernetes.configuration.KubernetesConfigOptions;
import
org.apache.flink.kubernetes.kubeclient.Fabric8FlinkKubeClient
;
import
org.apache.flink.kubernetes.kubeclient.Fabric8FlinkKubeClient
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClient
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClient
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClientFactory
;
import
org.apache.flink.kubernetes.kubeclient.FlinkKubeClientFactory
;
import
org.apache.flink.python.PythonOptions
;
import
org.apache.http.util.TextUtils
;
import
org.apache.http.util.TextUtils
;
import
java.lang.reflect.Method
;
import
java.lang.reflect.Method
;
...
@@ -101,6 +102,8 @@ public abstract class KubernetesGateway extends AbstractGateway {
...
@@ -101,6 +102,8 @@ public abstract class KubernetesGateway extends AbstractGateway {
preparPodTemplate
(
k8sConfig
.
getKubeConfig
(),
KubernetesConfigOptions
.
KUBE_CONFIG_FILE
);
preparPodTemplate
(
k8sConfig
.
getKubeConfig
(),
KubernetesConfigOptions
.
KUBE_CONFIG_FILE
);
if
(
getType
().
isApplicationMode
())
{
if
(
getType
().
isApplicationMode
())
{
// remove python file
configuration
.
removeConfig
(
PythonOptions
.
PYTHON_FILES
);
resetCheckpointInApplicationMode
(
flinkConfig
.
getJobName
());
resetCheckpointInApplicationMode
(
flinkConfig
.
getJobName
());
}
}
}
}
...
...
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