Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
D
dataease
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
njgzx
dataease
Commits
883eb91a
提交
883eb91a
authored
4月 29, 2021
作者:
taojinlong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 删除数据
上级
57c55515
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
34 行增加
和
31 行删除
+34
-31
ExtractDataService.java
.../java/io/dataease/service/dataset/ExtractDataService.java
+34
-31
没有找到文件。
backend/src/main/java/io/dataease/service/dataset/ExtractDataService.java
浏览文件 @
883eb91a
...
...
@@ -12,7 +12,10 @@ import io.dataease.commons.utils.LogUtil;
import
io.dataease.datasource.constants.DatasourceTypes
;
import
io.dataease.datasource.dto.DorisConfigration
;
import
io.dataease.datasource.dto.MysqlConfigration
;
import
io.dataease.datasource.dto.TableFiled
;
import
io.dataease.datasource.provider.DatasourceProvider
;
import
io.dataease.datasource.provider.JdbcProvider
;
import
io.dataease.datasource.provider.ProviderFactory
;
import
io.dataease.datasource.request.DatasourceRequest
;
import
io.dataease.dto.dataset.DataSetTaskLogDTO
;
import
io.dataease.dto.dataset.DataTableInfoDTO
;
...
...
@@ -91,8 +94,7 @@ public class ExtractDataService {
"PROPERTIES(\"replication_num\" = \"1\");"
;
private
static
String
shellScript
=
"curl --location-trusted -u %s:%s -H \"label:%s\" -H \"column_separator:%s\" -H \"columns:%s\" -H \"merge_type: %s\" -T %s -XPUT http://%s:%s/api/%s/%s/_stream_load\n"
+
// "rm -rf %s\n" +
"return $?"
;
"rm -rf %s\n"
;
private
String
createDorisTablColumnSql
(
List
<
DatasetTableField
>
datasetTableFields
){
String
Column_Fields
=
"dataease_uuid varchar(50),"
;
...
...
@@ -167,7 +169,7 @@ public class ExtractDataService {
createDorisTable
(
DorisTableUtils
.
dorisName
(
datasetTableId
),
dorisTablColumnSql
);
createDorisTable
(
DorisTableUtils
.
dorisTmpName
(
DorisTableUtils
.
dorisName
(
datasetTableId
)),
dorisTablColumnSql
);
generateTransFile
(
"all_scope"
,
datasetTable
,
datasource
,
tableName
,
datasetTableFields
,
null
);
generateJobFile
(
"all_scope"
,
datasetTable
,
datasetTableFields
);
generateJobFile
(
"all_scope"
,
datasetTable
,
String
.
join
(
","
,
datasetTableFields
.
stream
().
map
(
DatasetTableField:
:
getOriginName
).
collect
(
Collectors
.
toList
()))
);
extractData
(
datasetTable
,
"all_scope"
);
replaceTable
(
DorisTableUtils
.
dorisName
(
datasetTableId
));
datasetTableTaskLog
.
setStatus
(
JobStatus
.
Completed
.
name
());
...
...
@@ -194,8 +196,10 @@ public class ExtractDataService {
if
(
StringUtils
.
isNotEmpty
(
datasetTableIncrementalConfig
.
getIncrementalAdd
().
replace
(
" "
,
""
)))
{
String
sql
=
datasetTableIncrementalConfig
.
getIncrementalAdd
().
replace
(
lastUpdateTime
,
dataSetTaskLogDTOS
.
get
(
0
).
getStartTime
().
toString
()
.
replace
(
currentUpdateTime
,
Long
.
valueOf
(
System
.
currentTimeMillis
()).
toString
()));
//TODO sql column
generateTransFile
(
"incremental_add"
,
datasetTable
,
datasource
,
tableName
,
datasetTableFields
,
sql
);
generateJobFile
(
"incremental_add"
,
datasetTable
,
datasetTableFields
);
generateJobFile
(
"incremental_add"
,
datasetTable
,
fetchSqlField
(
sql
,
datasource
)
);
extractData
(
datasetTable
,
"incremental_add"
);
}
...
...
@@ -203,8 +207,10 @@ public class ExtractDataService {
if
(
StringUtils
.
isNotEmpty
(
datasetTableIncrementalConfig
.
getIncrementalDelete
()))
{
String
sql
=
datasetTableIncrementalConfig
.
getIncrementalDelete
().
replace
(
lastUpdateTime
,
dataSetTaskLogDTOS
.
get
(
0
).
getStartTime
().
toString
()
.
replace
(
currentUpdateTime
,
Long
.
valueOf
(
System
.
currentTimeMillis
()).
toString
()));
//TODO sql column
;
generateTransFile
(
"incremental_delete"
,
datasetTable
,
datasource
,
tableName
,
datasetTableFields
,
sql
);
generateJobFile
(
"incremental_delete"
,
datasetTable
,
datasetTableFields
);
generateJobFile
(
"incremental_delete"
,
datasetTable
,
fetchSqlField
(
sql
,
datasource
)
);
extractData
(
datasetTable
,
"incremental_delete"
);
}
datasetTableTaskLog
.
setStatus
(
JobStatus
.
Completed
.
name
());
...
...
@@ -289,44 +295,32 @@ public class ExtractDataService {
return
remoteSlaveServer
;
}
private
void
generateJobFile
(
String
extractType
,
DatasetTable
datasetTable
,
List
<
DatasetTableField
>
datasetTableFie
lds
)
throws
Exception
{
private
void
generateJobFile
(
String
extractType
,
DatasetTable
datasetTable
,
String
columnFei
lds
)
throws
Exception
{
String
dorisOutputTable
=
null
;
String
jobName
=
null
;
String
script
=
null
;
Datasource
dorisDatasource
=
(
Datasource
)
CommonBeanFactory
.
getBean
(
"DorisDatasource"
);
DorisConfigration
dorisConfigration
=
new
Gson
().
fromJson
(
dorisDatasource
.
getConfiguration
(),
DorisConfigration
.
class
);
String
columns
=
String
.
join
(
","
,
datasetTableFields
.
stream
().
map
(
DatasetTableField:
:
getOriginName
).
collect
(
Collectors
.
toList
()))
+
",dataease_uuid"
;
switch
(
extractType
)
{
case
"all_scope"
:
jobName
=
"job_"
+
datasetTable
.
getId
();
script
=
String
.
format
(
shellScript
,
dorisConfigration
.
getUsername
(),
dorisConfigration
.
getPassword
(),
String
.
valueOf
(
System
.
currentTimeMillis
()),
separator
,
columns
,
"APPEND"
,
root_path
+
dorisOutputTable
+
"."
+
extention
,
dorisConfigration
.
getHost
(),
dorisConfigration
.
getHttpPort
(),
dorisConfigration
.
getDataBase
(),
dorisOutputTable
,
root_path
+
dorisOutputTable
+
"."
+
extention
);
break
;
case
"incremental_add"
:
jobName
=
"job_add_"
+
datasetTable
.
getId
();
script
=
String
.
format
(
shellScript
,
dorisConfigration
.
getUsername
(),
dorisConfigration
.
getPassword
(),
String
.
valueOf
(
System
.
currentTimeMillis
()),
separator
,
columns
,
"APPEND"
,
root_path
+
dorisOutputTable
+
"."
+
extention
,
dorisConfigration
.
getHost
(),
dorisConfigration
.
getHttpPort
(),
dorisConfigration
.
getDataBase
(),
dorisOutputTable
,
root_path
+
dorisOutputTable
+
"."
+
extention
);
break
;
case
"incremental_delete"
:
script
=
String
.
format
(
shellScript
,
dorisConfigration
.
getUsername
(),
dorisConfigration
.
getPassword
(),
String
.
valueOf
(
System
.
currentTimeMillis
()),
separator
,
columns
,
"DELETE"
,
root_path
+
dorisOutputTable
+
"."
+
extention
,
dorisConfigration
.
getHost
(),
dorisConfigration
.
getHttpPort
(),
dorisConfigration
.
getDataBase
(),
dorisOutputTable
,
root_path
+
dorisOutputTable
+
"."
+
extention
);
jobName
=
"job_delete_"
+
datasetTable
.
getId
();
break
;
default
:
break
;
}
String
columns
=
columnFeilds
+
",dataease_uuid"
;
String
transName
=
null
;
switch
(
extractType
)
{
case
"all_scope"
:
transName
=
"trans_"
+
datasetTable
.
getId
();
dorisOutputTable
=
DorisTableUtils
.
dorisTmpName
(
DorisTableUtils
.
dorisName
(
datasetTable
.
getId
()));
jobName
=
"job_"
+
datasetTable
.
getId
();
script
=
String
.
format
(
shellScript
,
dorisConfigration
.
getUsername
(),
dorisConfigration
.
getPassword
(),
String
.
valueOf
(
System
.
currentTimeMillis
()),
separator
,
columns
,
"APPEND"
,
root_path
+
dorisOutputTable
+
"."
+
extention
,
dorisConfigration
.
getHost
(),
dorisConfigration
.
getHttpPort
(),
dorisConfigration
.
getDataBase
(),
dorisOutputTable
,
root_path
+
dorisOutputTable
+
"."
+
extention
);
break
;
case
"incremental_add"
:
transName
=
"trans_add_"
+
datasetTable
.
getId
();
dorisOutputTable
=
DorisTableUtils
.
dorisName
(
datasetTable
.
getId
());
jobName
=
"job_add_"
+
datasetTable
.
getId
();
script
=
String
.
format
(
shellScript
,
dorisConfigration
.
getUsername
(),
dorisConfigration
.
getPassword
(),
String
.
valueOf
(
System
.
currentTimeMillis
()),
separator
,
columns
,
"APPEND"
,
root_path
+
dorisOutputTable
+
"."
+
extention
,
dorisConfigration
.
getHost
(),
dorisConfigration
.
getHttpPort
(),
dorisConfigration
.
getDataBase
(),
dorisOutputTable
,
root_path
+
dorisOutputTable
+
"."
+
extention
);
break
;
case
"incremental_delete"
:
transName
=
"trans_delete_"
+
datasetTable
.
getId
();
dorisOutputTable
=
DorisTableUtils
.
dorisName
(
datasetTable
.
getId
());
dorisOutputTable
=
DorisTableUtils
.
dorisDeleteName
(
DorisTableUtils
.
dorisName
(
datasetTable
.
getId
()));
script
=
String
.
format
(
shellScript
,
dorisConfigration
.
getUsername
(),
dorisConfigration
.
getPassword
(),
String
.
valueOf
(
System
.
currentTimeMillis
()),
separator
,
columns
,
"DELETE"
,
root_path
+
dorisOutputTable
+
"."
+
extention
,
dorisConfigration
.
getHost
(),
dorisConfigration
.
getHttpPort
(),
dorisConfigration
.
getDataBase
(),
DorisTableUtils
.
dorisName
(
datasetTable
.
getId
()),
root_path
+
dorisOutputTable
+
"."
+
extention
);
jobName
=
"job_delete_"
+
datasetTable
.
getId
();
break
;
default
:
break
;
...
...
@@ -382,16 +376,25 @@ public class ExtractDataService {
greenHop
.
setEvaluation
(
true
);
jobMeta
.
addJobHop
(
greenHop
);
if
(!
extractType
.
equals
(
"incremental_delete"
)){
}
String
jobXml
=
jobMeta
.
getXML
();
File
file
=
new
File
(
root_path
+
jobName
+
".kjb"
);
FileUtils
.
writeStringToFile
(
file
,
jobXml
,
"UTF-8"
);
}
private
String
fetchSqlField
(
String
sql
,
Datasource
ds
)
throws
Exception
{
String
tmpSql
=
sql
;
DatasourceProvider
datasourceProvider
=
ProviderFactory
.
getProvider
(
ds
.
getType
());
DatasourceRequest
datasourceRequest
=
new
DatasourceRequest
();
datasourceRequest
.
setDatasource
(
ds
);
if
(
tmpSql
.
trim
().
endsWith
(
";"
)){
tmpSql
=
tmpSql
.
substring
(
0
,
tmpSql
.
length
()
-
1
)
+
" limit 0"
;
}
else
{
tmpSql
=
tmpSql
+
" limit 0"
;
}
datasourceRequest
.
setQuery
(
tmpSql
);
return
String
.
join
(
","
,
datasourceProvider
.
fetchResultField
(
datasourceRequest
).
stream
().
map
(
TableFiled:
:
getFieldName
).
collect
(
Collectors
.
toList
()));
}
private
void
generateTransFile
(
String
extractType
,
DatasetTable
datasetTable
,
Datasource
datasource
,
String
table
,
List
<
DatasetTableField
>
datasetTableFields
,
String
selectSQL
)
throws
Exception
{
TransMeta
transMeta
=
new
TransMeta
();
String
dorisOutputTable
=
null
;
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论