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
d6469275
Unverified
Commit
d6469275
authored
Nov 07, 2023
by
ZackYoung
Committed by
GitHub
Nov 07, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Fix][UDF]Fix udf python (#2504)
* fix_udf_python
parent
0b9aac20
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
10 deletions
+51
-10
UDFUtil.java
...nction/src/main/java/org/dinky/function/util/UDFUtil.java
+2
-2
getPyFuncList.py
dinky-function/src/main/resources/getPyFuncList.py
+49
-8
No files found.
dinky-function/src/main/java/org/dinky/function/util/UDFUtil.java
View file @
d6469275
...
@@ -394,7 +394,7 @@ public class UDFUtil {
...
@@ -394,7 +394,7 @@ public class UDFUtil {
continue
;
continue
;
}
}
Configuration
configuration
=
new
Configuration
();
Configuration
configuration
=
new
Configuration
();
configuration
.
set
(
PythonOptions
.
PYTHON_FILES
,
udfFile
+
".zip"
);
configuration
.
set
(
PythonOptions
.
PYTHON_FILES
,
udfFile
);
configuration
.
set
(
PythonOptions
.
PYTHON_CLIENT_EXECUTABLE
,
pythonPath
);
configuration
.
set
(
PythonOptions
.
PYTHON_CLIENT_EXECUTABLE
,
pythonPath
);
configuration
.
set
(
PythonOptions
.
PYTHON_EXECUTABLE
,
pythonPath
);
configuration
.
set
(
PythonOptions
.
PYTHON_EXECUTABLE
,
pythonPath
);
try
{
try
{
...
@@ -413,7 +413,7 @@ public class UDFUtil {
...
@@ -413,7 +413,7 @@ public class UDFUtil {
String
shell
=
String
shell
=
StrUtil
.
join
(
" "
,
Arrays
.
asList
(
Opt
.
ofBlankAble
(
pyPath
).
orElse
(
"python3"
),
pyFile
,
checkPyFile
));
StrUtil
.
join
(
" "
,
Arrays
.
asList
(
Opt
.
ofBlankAble
(
pyPath
).
orElse
(
"python3"
),
pyFile
,
checkPyFile
));
return
StrUtil
.
split
(
RuntimeUtil
.
execForStr
(
shell
),
","
);
return
StrUtil
.
split
(
StrUtil
.
trim
(
RuntimeUtil
.
execForStr
(
shell
)
),
","
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
throw
new
DinkyException
(
e
);
throw
new
DinkyException
(
e
);
}
}
...
...
dinky-function/src/main/resources/getPyFuncList.py
View file @
d6469275
# -*- coding: utf-8 -*-
import
hashlib
import
importlib
import
importlib
import
os
import
sys
import
sys
import
platform
import
uuid
import
zipfile
import
appdirs
import
shutil
import
pyflink
import
pyflink
# import ast
# import ast
...
@@ -41,9 +46,6 @@ import pyflink
...
@@ -41,9 +46,6 @@ import pyflink
# except Exception as e:
# except Exception as e:
# pass
# pass
import
os
if
len
(
sys
.
argv
)
<
2
:
if
len
(
sys
.
argv
)
<
2
:
raise
Exception
(
"Please enter the file path"
)
raise
Exception
(
"Please enter the file path"
)
...
@@ -52,23 +54,62 @@ project_path: str = sys.argv[1]
...
@@ -52,23 +54,62 @@ project_path: str = sys.argv[1]
udf_name_list
=
set
()
udf_name_list
=
set
()
def
get_file_md5
(
path
):
"""
获取文件内容的MD5值
:param path: 文件所在路径
:return:
"""
with
open
(
path
,
'rb'
)
as
file
:
data
=
file
.
read
()
diff_check
=
hashlib
.
md5
()
diff_check
.
update
(
data
)
md5_code
=
diff_check
.
hexdigest
()
return
md5_code
def
list_modules
(
root_dir
):
def
list_modules
(
root_dir
):
"""返回给定目录下所有模块和子模块的名称"""
"""返回给定目录下所有模块和子模块的名称"""
modules
=
[]
modules
=
[]
if
os
.
path
.
isdir
(
root_dir
):
sys
.
path
.
append
(
project_path
)
for
dirpath
,
_
,
filenames
in
os
.
walk
(
root_dir
):
for
dirpath
,
_
,
filenames
in
os
.
walk
(
root_dir
):
for
filename
in
filenames
:
for
filename
in
filenames
:
parse_file
(
dirpath
,
filename
,
modules
,
root_dir
)
else
:
file_dir
=
os
.
path
.
dirname
(
root_dir
)
sys
.
path
.
append
(
file_dir
)
parse_file
(
file_dir
,
root_dir
,
modules
,
file_dir
)
if
project_path
.
endswith
(
".py"
):
sys
.
path
.
append
(
file_dir
)
elif
project_path
.
endswith
(
".zip"
):
tmp_dir
=
appdirs
.
user_cache_dir
()
file
=
zipfile
.
ZipFile
(
project_path
)
unzip_file_path
=
os
.
path
.
normpath
(
tmp_dir
+
"/dinky/udf_parse/"
+
get_file_md5
(
project_path
))
if
os
.
path
.
exists
(
unzip_file_path
):
shutil
.
rmtree
(
unzip_file_path
)
file
.
extractall
(
unzip_file_path
)
sys
.
path
.
append
(
unzip_file_path
)
for
dirpath
,
_
,
filenames
in
os
.
walk
(
unzip_file_path
):
for
filename
in
filenames
:
parse_file
(
dirpath
,
filename
,
modules
,
unzip_file_path
)
file
.
close
()
return
modules
def
parse_file
(
dirpath
,
filename
,
modules
,
root_dir
):
root_dir
=
os
.
path
.
normpath
(
root_dir
)
if
filename
.
endswith
(
".py"
):
if
filename
.
endswith
(
".py"
):
p_
=
project_path
.
replace
(
os
.
sep
,
"."
)
p_
=
root_dir
.
replace
(
os
.
sep
,
"."
)
module_name
=
os
.
path
.
splitext
(
os
.
path
.
join
(
dirpath
,
filename
))[
0
]
.
replace
(
os
.
sep
,
"."
)
.
replace
(
module_name
=
os
.
path
.
splitext
(
os
.
path
.
join
(
dirpath
,
filename
))[
0
]
.
replace
(
os
.
sep
,
"."
)
.
replace
(
p_
+
"."
,
""
)
p_
+
"."
,
""
)
modules
.
append
(
module_name
.
replace
(
root_dir
,
""
))
modules
.
append
(
module_name
.
replace
(
root_dir
,
""
))
return
modules
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
modules
=
list_modules
(
project_path
)
modules
=
list_modules
(
project_path
)
sys
.
path
.
append
(
project_path
)
for
module_name
in
modules
:
for
module_name
in
modules
:
try
:
try
:
module
=
importlib
.
import_module
(
module_name
)
module
=
importlib
.
import_module
(
module_name
)
...
...
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