Browse Source

[Improvement-3933][db operation] Improve the performance of sql query (#3940)

* optimize select * case

* emove redundancy

* bug fixed

* Update en_US.js

* Update startup.sh

* optimize

* optimize code

* optimize

* bug fixed

* add ut

* bug fixed

* bug fixed

* bug fixed

* bug fixed

* Delete WorkFlowLineageMapper.xml

* Delete createTenement.vue

* recove wrongly deleted file

* Update WorkFlowLineageMapper.xml

* Update createTenement.vue
pull/3/MERGE
Yarlung 4 years ago committed by GitHub
parent
commit
bd156b312d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      docker/build/Dockerfile
  2. 6
      dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapper.java
  3. 5
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AccessTokenMapper.xml
  4. 23
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml
  5. 9
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertMapper.xml
  6. 13
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml
  7. 60
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/DataSourceMapper.xml
  8. 3
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/DataSourceUserMapper.xml
  9. 42
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml
  10. 21
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionVersionMapper.xml
  11. 12
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapMapper.xml
  12. 64
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml
  13. 54
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml
  14. 16
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapper.xml
  15. 17
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/QueueMapper.xml
  16. 67
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.xml
  17. 29
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml
  18. 11
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/SessionMapper.xml
  19. 45
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml
  20. 38
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TenantMapper.xml
  21. 56
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapper.xml
  22. 17
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.xml
  23. 67
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml
  24. 2
      dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapper.xml
  25. 97
      dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java
  26. 6
      dolphinscheduler-ui/src/js/conf/home/pages/security/pages/tenement/_source/createTenement.vue

2
docker/build/Dockerfile

@ -42,7 +42,7 @@ ADD ./apache-dolphinscheduler-incubating-${VERSION}-dolphinscheduler-bin.tar.gz
RUN mv /opt/apache-dolphinscheduler-incubating-${VERSION}-dolphinscheduler-bin/ /opt/dolphinscheduler/
ENV DOLPHINSCHEDULER_HOME /opt/dolphinscheduler
#4. install database, if use mysql as your backend database, you should append `mysql-client` at the end of the sentence
#4. install database, if use mysql as your backend database, the `mysql-client` package should be installed
RUN apk add --update --no-cache postgresql postgresql-contrib
#5. modify nginx

6
dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapper.java

@ -24,9 +24,9 @@ import java.util.Set;
public interface WorkFlowLineageMapper {
public List<WorkFlowLineage> queryByName(@Param("searchVal") String searchVal, @Param("projectId") int projectId);
List<WorkFlowLineage> queryByName(@Param("searchVal") String searchVal, @Param("projectId") int projectId);
public List<WorkFlowLineage> queryByIds(@Param("ids") Set<Integer> ids, @Param("projectId") int projectId);
List<WorkFlowLineage> queryByIds(@Param("ids") Set<Integer> ids, @Param("projectId") int projectId);
public List<WorkFlowRelation> querySourceTarget(@Param("id") int id);
List<WorkFlowRelation> querySourceTarget(@Param("id") int id);
}

5
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AccessTokenMapper.xml

@ -19,7 +19,8 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.AccessTokenMapper">
<select id="selectAccessTokenPage" resultType="org.apache.dolphinscheduler.dao.entity.AccessToken">
select * from t_ds_access_token t
select t.id, t.user_id, t.token, t.expire_time, t.create_time, t.update_time
from t_ds_access_token t
left join t_ds_user u on t.user_id = u.id
where 1 = 1
<if test="userName != null and userName != ''">
@ -30,4 +31,4 @@
</if>
order by t.update_time desc
</select>
</mapper>
</mapper>

23
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertGroupMapper.xml

@ -18,8 +18,13 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.AlertGroupMapper">
<sql id="baseSql">
id, group_name, group_type, description, create_time, update_time
</sql>
<select id="queryAlertGroupPage" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup">
select * from t_ds_alertgroup
select
<include refid="baseSql"/>
from t_ds_alertgroup
where 1 = 1
<if test="groupName != null and groupName != ''">
and group_name like concat('%', #{groupName}, '%')
@ -27,21 +32,27 @@
order by update_time desc
</select>
<select id="queryByGroupName" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup">
select * from t_ds_alertgroup
select
<include refid="baseSql"/>
from t_ds_alertgroup
where group_name=#{groupName}
</select>
<select id="queryByUserId" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup">
select * from t_ds_alertgroup t
select t.id, t.group_name, t.group_type, t.description, t.create_time, t.update_time
from t_ds_alertgroup t
left join t_ds_relation_user_alertgroup r on t.id=r.alertgroup_id
where r.user_id=#{userId}
</select>
<select id="queryByAlertType" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup">
select * from t_ds_alertgroup
select
<include refid="baseSql"/>
from t_ds_alertgroup
where group_type=#{alertType}
</select>
<select id="queryAllGroupList" resultType="org.apache.dolphinscheduler.dao.entity.AlertGroup">
select *
select
<include refid="baseSql"/>
from t_ds_alertgroup
order by update_time desc
</select>
</mapper>
</mapper>

9
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/AlertMapper.xml

@ -18,9 +18,14 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.AlertMapper">
<sql id="baseSql">
id, title, show_type, content, alert_type, alert_status, log,
alertgroup_id, receivers, receivers_cc, create_time, update_time
</sql>
<select id="listAlertByStatus" resultType="org.apache.dolphinscheduler.dao.entity.Alert">
select *
select
<include refid="baseSql"/>
from t_ds_alert
where alert_status = #{alertStatus}
</select>
</mapper>
</mapper>

13
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/CommandMapper.xml

@ -19,10 +19,13 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.CommandMapper">
<select id="getOneToRun" resultType="org.apache.dolphinscheduler.dao.entity.Command">
select command.* from t_ds_command command
join t_ds_process_definition definition on command.process_definition_id = definition.id
select cmd.id, cmd.command_type, cmd.process_definition_id, cmd.command_param, cmd.task_depend_type, cmd.failure_strategy,
cmd.warning_type, cmd.warning_group_id, cmd.schedule_time, cmd.start_time, cmd.executor_id, cmd.dependence, cmd.update_time,
cmd.process_instance_priority, cmd.worker_group
from t_ds_command cmd
join t_ds_process_definition definition on cmd.process_definition_id = definition.id
where definition.release_state = 1 AND definition.flag = 1
order by command.update_time asc
order by cmd.update_time asc
limit 1
</select>
<select id="countCommandState" resultType="org.apache.dolphinscheduler.dao.entity.CommandCount">
@ -30,7 +33,7 @@
from t_ds_command cmd, t_ds_process_definition process
where cmd.process_definition_id = process.id
<if test="projectIdArray != null and projectIdArray.length != 0">
and process.project_id in
and process.project_id in
<foreach collection="projectIdArray" index="index" item="i" open="(" close=")" separator=",">
#{i}
</foreach>
@ -40,4 +43,4 @@
</if>
group by cmd.command_type
</select>
</mapper>
</mapper>

60
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/DataSourceMapper.xml

@ -18,30 +18,34 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.DataSourceMapper">
<sql id="baseSql">
id, name, note, type, user_id, connection_params, create_time, update_time
</sql>
<select id="queryDataSourceByType" resultType="org.apache.dolphinscheduler.dao.entity.DataSource">
select *
select
<include refid="baseSql"/>
from t_ds_datasource
where type=#{type}
<if test="userId != 0">
and id in
(select datasource_id
from t_ds_relation_datasource_user
where user_id=#{userId}
union select id as datasource_id
from t_ds_datasource
where user_id=#{userId}
)
and id in
(select datasource_id
from t_ds_relation_datasource_user
where user_id=#{userId}
union select id as datasource_id
from t_ds_datasource
where user_id=#{userId}
)
</if>
</select>
<select id="selectPaging" resultType="org.apache.dolphinscheduler.dao.entity.DataSource">
select *
select
<include refid="baseSql"/>
from t_ds_datasource
where 1 =1
<if test="userId != 0">
and id in
(select datasource_id
and id in
(select datasource_id
from t_ds_relation_datasource_user
where user_id=#{userId}
union select id as datasource_id
@ -50,36 +54,40 @@
)
</if>
<if test="name != null and name != ''">
and name like concat ('%', #{name}, '%')
</if>
order by update_time desc
and name like concat ('%', #{name}, '%')
</if>
order by update_time desc
</select>
<select id="queryDataSourceByName" resultType="org.apache.dolphinscheduler.dao.entity.DataSource">
select *
select
<include refid="baseSql"/>
from t_ds_datasource
where name=#{name}
</select>
<select id="queryAuthedDatasource" resultType="org.apache.dolphinscheduler.dao.entity.DataSource">
select datasource.*
from t_ds_datasource datasource, t_ds_relation_datasource_user rel
where datasource.id = rel.datasource_id AND rel.user_id = #{userId}
select ds.id, ds.name, ds.note, ds.type, ds.user_id, ds.connection_params, ds.create_time, ds.update_time
from t_ds_datasource ds, t_ds_relation_datasource_user rel
where ds.id = rel.datasource_id AND rel.user_id = #{userId}
</select>
<select id="queryDatasourceExceptUserId" resultType="org.apache.dolphinscheduler.dao.entity.DataSource">
select *
select
<include refid="baseSql"/>
from t_ds_datasource
where user_id <![CDATA[ <> ]]> #{userId}
</select>
<select id="listAllDataSourceByType" resultType="org.apache.dolphinscheduler.dao.entity.DataSource">
select *
select
<include refid="baseSql"/>
from t_ds_datasource
where type = #{type}
</select>
<select id="listAuthorizedDataSource" resultType="org.apache.dolphinscheduler.dao.entity.DataSource">
select *
select
<include refid="baseSql"/>
from t_ds_datasource
where
id in (select datasource_id from t_ds_relation_datasource_user where user_id=#{userId}
union select id as datasource_id from t_ds_datasource where user_id=#{userId})
union select id as datasource_id from t_ds_datasource where user_id=#{userId})
<if test="dataSourceIds != null and dataSourceIds != ''">
and id in
<foreach collection="dataSourceIds" item="i" open="(" close=")" separator=",">
@ -87,6 +95,4 @@
</foreach>
</if>
</select>
</mapper>
</mapper>

3
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/DataSourceUserMapper.xml

@ -21,10 +21,9 @@
<delete id="deleteByUserId">
delete from t_ds_relation_datasource_user
where user_id = #{userId}
</delete>
<delete id="deleteByDatasourceId">
delete from t_ds_relation_datasource_user
where datasource_id = #{datasourceId}
</delete>
</mapper>
</mapper>

42
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml

@ -18,14 +18,24 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionMapper">
<sql id="baseSql">
id, name, version, release_state, project_id, user_id, process_definition_json, description,
global_params, flag, locations, connects, receivers, receivers_cc, create_time, timeout,
tenant_id, update_time, modify_by, resource_ids
</sql>
<select id="verifyByDefineName" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select pd.*
select pd.id, pd.name, pd.version, pd.release_state, pd.project_id, pd.user_id, pd.process_definition_json, pd.description,
pd.global_params, pd.flag, pd.locations, pd.connects, pd.receivers, pd.receivers_cc, pd.create_time, pd.timeout,
pd.tenant_id, pd.update_time, pd.modify_by, pd.resource_ids
from t_ds_process_definition pd
WHERE pd.project_id = #{projectId}
and pd.name = #{processDefinitionName}
</select>
<select id="queryByDefineName" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select pd.*,u.user_name,p.name as project_name,t.tenant_code,q.queue,q.queue_name
select pd.id, pd.name, pd.version, pd.release_state, pd.project_id, pd.user_id, pd.process_definition_json, pd.description,
pd.global_params, pd.flag, pd.locations, pd.connects, pd.receivers, pd.receivers_cc, pd.create_time, pd.timeout,
pd.tenant_id, pd.update_time, pd.modify_by, pd.resource_ids,
u.user_name,p.name as project_name,t.tenant_code,q.queue,q.queue_name
from t_ds_process_definition pd
JOIN t_ds_user u ON pd.user_id = u.id
JOIN t_ds_project p ON pd.project_id = p.id
@ -35,12 +45,14 @@
and pd.name = #{processDefinitionName}
</select>
<select id="queryDefineListPaging" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
SELECT td.id, td.name, td.version, td.release_state, td.project_id, td.user_id, td.description, td.global_params,
td.flag, td.receivers, td.receivers_cc, td.timeout, td.tenant_id, td.modify_by, td.update_time, td.create_time,
sc.schedule_release_state, tu.user_name
SELECT td.id, td.name, td.version, td.release_state, td.project_id, td.user_id, td.description,
td.global_params,
td.flag, td.receivers, td.receivers_cc, td.timeout, td.tenant_id, td.modify_by, td.update_time, td.create_time,
sc.schedule_release_state, tu.user_name
FROM t_ds_process_definition td
left join (select process_definition_id,release_state as schedule_release_state from t_ds_schedules group by process_definition_id,release_state) sc on sc.process_definition_id = td.id
left join t_ds_user tu on td.user_id = tu.id
left join (select process_definition_id,release_state as schedule_release_state from t_ds_schedules group by
process_definition_id,release_state) sc on sc.process_definition_id = td.id
left join t_ds_user tu on td.user_id = tu.id
where td.project_id = #{projectId}
<if test=" searchVal != null and searchVal != ''">
and td.name like concat('%', #{searchVal}, '%')
@ -52,18 +64,21 @@
</select>
<select id="queryAllDefinitionList" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select *
select
<include refid="baseSql"/>
from t_ds_process_definition
where project_id = #{projectId}
order by create_time desc
</select>
<select id="queryDefinitionListByTenant" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select *
select
<include refid="baseSql"/>
from t_ds_process_definition
where tenant_id = #{tenantId}
</select>
<select id="queryDefinitionListByIdList" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
select *
select
<include refid="baseSql"/>
from t_ds_process_definition
where id in
<foreach collection="ids" index="index" item="i" open="(" separator="," close=")">
@ -85,7 +100,10 @@
</select>
<select id="queryByDefineId" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinition">
SELECT
pd.*, u.user_name,
pd.id, pd.name, pd.version, pd.release_state, pd.project_id, pd.user_id, pd.process_definition_json, pd.description,
pd.global_params, pd.flag, pd.locations, pd.connects, pd.receivers, pd.receivers_cc, pd.create_time, pd.timeout,
pd.tenant_id, pd.update_time, pd.modify_by, pd.resource_ids,
u.user_name,
p.name AS project_name
FROM
t_ds_process_definition pd,
@ -114,4 +132,4 @@
set version = #{version}
where id = #{processDefinitionId}
</update>
</mapper>
</mapper>

21
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionVersionMapper.xml

@ -18,24 +18,32 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProcessDefinitionVersionMapper">
<sql id="baseSql">
id, process_definition_id, version, process_definition_json, description, global_params,locations,connects, receivers,
receivers_cc, create_time, timeout, resource_ids
</sql>
<select id="queryMaxVersionByProcessDefinitionId" resultType="java.lang.Long">
select max(version)
from t_ds_process_definition_version
where process_definition_id = #{processDefinitionId}
</select>
<select id="queryProcessDefinitionVersionsPaging" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion">
select *
<select id="queryProcessDefinitionVersionsPaging"
resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion">
select
<include refid="baseSql"/>
from t_ds_process_definition_version
where process_definition_id = #{processDefinitionId}
order by version desc
</select>
<select id="queryByProcessDefinitionIdAndVersion" resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion">
select *
<select id="queryByProcessDefinitionIdAndVersion"
resultType="org.apache.dolphinscheduler.dao.entity.ProcessDefinitionVersion">
select
<include refid="baseSql"/>
from t_ds_process_definition_version
where process_definition_id = #{processDefinitionId}
and version = #{version}
and version = #{version}
</select>
<delete id="deleteByProcessDefinitionIdAndVersion">
@ -44,4 +52,5 @@
where process_definition_id = #{processDefinitionId}
and version = #{version}
</delete>
</mapper>
</mapper>

12
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapMapper.xml

@ -18,20 +18,24 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapMapper">
<sql id="baseSql">
id, parent_process_instance_id, parent_task_instance_id, process_instance_id
</sql>
<delete id="deleteByParentProcessId">
delete
from t_ds_relation_process_instance
where parent_process_instance_id=#{parentProcessId}
</delete>
<select id="queryByParentId" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstanceMap">
select *
select
<include refid="baseSql"/>
from t_ds_relation_process_instance
where parent_process_instance_id = #{parentProcessId}
and parent_task_instance_id = #{parentTaskId}
</select>
<select id="queryBySubProcessId" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstanceMap">
select *
select
<include refid="baseSql"/>
from t_ds_relation_process_instance
where process_instance_id = #{subProcessId}
</select>
@ -40,4 +44,4 @@
from t_ds_relation_process_instance
where parent_process_instance_id = #{parentInstanceId}
</select>
</mapper>
</mapper>

64
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessInstanceMapper.xml

@ -18,13 +18,22 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProcessInstanceMapper">
<sql id="baseSql">
id, name, process_definition_id, state, recovery, start_time, end_time, run_times,host,
command_type, command_param, task_depend_type, max_try_times, failure_strategy, warning_type,
warning_group_id, schedule_time, command_start_time, global_params, process_instance_json, flag,
update_time, is_sub_process, executor_id, locations, connects, history_cmd, dependence_schedule_times,
process_instance_priority, worker_group, timeout, tenant_id, var_pool
</sql>
<select id="queryDetailById" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select inst.*
from t_ds_process_instance inst
where inst.id = #{processId}
select
<include refid="baseSql"/>
from t_ds_process_instance
where id = #{processId}
</select>
<select id="queryByHostAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where 1=1
<if test="host != null and host != ''">
@ -38,7 +47,8 @@
</select>
<select id="queryTopNProcessInstance" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where state = #{status}
and start_time between
@ -48,7 +58,8 @@
</select>
<select id="queryByTenantIdAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where 1=1
<if test="tenantId != -1">
@ -62,7 +73,8 @@
</select>
<select id="queryByWorkerGroupIdAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where 1=1
<if test="workerGroupId != -1">
@ -76,10 +88,17 @@
</select>
<select id="queryProcessInstanceListPaging" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select instance.id,instance.name,instance.process_definition_id,instance.state,instance.recovery,instance.start_time,instance.end_time,instance.run_times,instance.host,instance.command_type,instance.command_param,
instance.task_depend_type,instance.max_try_times,instance.failure_strategy,instance.warning_type,instance.warning_group_id,instance.schedule_time,instance.command_start_time,instance.global_params,instance.flag,
instance.update_time,instance.is_sub_process,instance.executor_id,instance.locations,instance.connects,instance.history_cmd,instance.dependence_schedule_times,instance.process_instance_priority,instance.worker_group,
instance.timeout,instance.tenant_id
select
instance.id, instance.name, instance.process_definition_id, instance.state, instance.recovery,
instance.start_time, instance.end_time, instance.run_times, instance.host,
instance.command_type, instance.command_param, instance.task_depend_type, instance.max_try_times,
instance.failure_strategy, instance.warning_type,
instance.warning_group_id, instance.schedule_time, instance.command_start_time, instance.global_params,
instance.process_instance_json, instance.flag,
instance.update_time, instance.is_sub_process, instance.executor_id, instance.locations, instance.connects,
instance.history_cmd, instance.dependence_schedule_times,
instance.process_instance_priority, instance.worker_group, instance.timeout, instance.tenant_id,
instance.var_pool
from t_ds_process_instance instance
join t_ds_process_definition define ON instance.process_definition_id = define.id
where 1=1
@ -89,7 +108,7 @@
and instance.process_definition_id = #{processDefinitionId}
</if>
<if test="searchVal != null and searchVal != ''">
and instance.name like concat('%', #{searchVal}, '%')
and instance.name like concat('%', #{searchVal}, '%')
</if>
<if test="startTime != null ">
and instance.start_time > #{startTime} and instance.start_time <![CDATA[ <=]]> #{endTime}
@ -142,7 +161,7 @@
where 1 = 1
and t.is_sub_process = 0
<if test="startTime != null and endTime != null">
and t.start_time <![CDATA[ >= ]]> #{startTime} and t.start_time <![CDATA[ <= ]]> #{endTime}
and t.start_time <![CDATA[ >= ]]> #{startTime} and t.start_time <![CDATA[ <= ]]> #{endTime}
</if>
<if test="projectIds != null and projectIds.length != 0">
and p.id in
@ -153,22 +172,25 @@
group by t.state
</select>
<select id="queryByProcessDefineId" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_id=#{processDefinitionId}
order by start_time desc limit #{size}
</select>
<select id="queryLastSchedulerProcess" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_id=#{processDefinitionId}
<if test="startTime!=null and endTime != null ">
and schedule_time <![CDATA[ >= ]]> #{startTime} and schedule_time <![CDATA[ <= ]]> #{endTime}
and schedule_time <![CDATA[ >= ]]> #{startTime} and schedule_time <![CDATA[ <= ]]> #{endTime}
</if>
order by end_time desc limit 1
</select>
<select id="queryLastRunningProcess" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_id=#{processDefinitionId}
<if test="states !=null and states.length != 0">
@ -179,12 +201,13 @@
</if>
<if test="startTime!=null and endTime != null ">
and (schedule_time <![CDATA[ >= ]]> #{startTime} and schedule_time <![CDATA[ <= ]]> #{endTime}
or start_time <![CDATA[ >= ]]> #{startTime} and start_time <![CDATA[ <= ]]> #{endTime})
or start_time <![CDATA[ >= ]]> #{startTime} and start_time <![CDATA[ <= ]]> #{endTime})
</if>
order by start_time desc limit 1
</select>
<select id="queryLastManualProcess" resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_id=#{processDefinitionId}
and schedule_time is null
@ -195,7 +218,8 @@
</select>
<select id="queryByProcessDefineIdAndStatus"
resultType="org.apache.dolphinscheduler.dao.entity.ProcessInstance">
select *
select
<include refid="baseSql"/>
from t_ds_process_instance
where process_definition_id=#{processDefinitionId}
and state in

54
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectMapper.xml

@ -18,30 +18,52 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProjectMapper">
<sql id="baseSql">
id, name, description, user_id, flag, create_time, update_time
</sql>
<sql id="baseSqlV2">
${alias}.id, ${alias}.name, ${alias}.description, ${alias}.user_id, ${alias}.flag, ${alias}.create_time, ${alias}.update_time
</sql>
<select id="queryDetailById" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.*,u.user_name as user_name
select
<include refid="baseSqlV2">
<property name="alias" value="p"/>
</include>
,
u.user_name as user_name
from t_ds_project p
join t_ds_user u on p.user_id = u.id
where p.id = #{projectId}
</select>
<select id="queryByName" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.*,u.user_name as user_name
select
<include refid="baseSqlV2">
<property name="alias" value="p"/>
</include>
,
u.user_name as user_name
from t_ds_project p
join t_ds_user u on p.user_id = u.id
where p.name = #{projectName}
limit 1
</select>
<select id="queryProjectListPaging" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.*,u.user_name as user_name,
select
<include refid="baseSqlV2">
<property name="alias" value="p"/>
</include>
,
u.user_name as user_name,
(SELECT COUNT(*) FROM t_ds_process_definition AS def WHERE def.project_id = p.id) AS def_count,
(SELECT COUNT(*) FROM t_ds_process_definition def, t_ds_process_instance inst WHERE def.id = inst.process_definition_id AND def.project_id = p.id AND inst.state=1 ) as inst_running_count
(SELECT COUNT(*) FROM t_ds_process_definition def, t_ds_process_instance inst WHERE def.id =
inst.process_definition_id AND def.project_id = p.id AND inst.state=1 ) as inst_running_count
from t_ds_project p
join t_ds_user u on u.id=p.user_id
where 1=1
<if test="userId != 0">
and p.id in
(select project_id from t_ds_relation_project_user where user_id=#{userId}
union select id as project_id from t_ds_project where user_id=#{userId}
(select project_id from t_ds_relation_project_user where user_id=#{userId}
union select id as project_id from t_ds_project where user_id=#{userId}
)
</if>
<if test="searchName!=null and searchName != ''">
@ -50,23 +72,29 @@
order by p.create_time desc
</select>
<select id="queryAuthedProjectListByUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select p.*
select
<include refid="baseSqlV2">
<property name="alias" value="p"/>
</include>
,
from t_ds_project p,t_ds_relation_project_user rel
where p.id = rel.project_id and rel.user_id= #{userId}
</select>
<select id="queryProjectExceptUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select *
select
<include refid="baseSql"/>
from t_ds_project
where user_id <![CDATA[ <> ]]> #{userId}
</select>
<select id="queryProjectCreatedByUser" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select *
select
<include refid="baseSql"/>
from t_ds_project
where user_id = #{userId}
</select>
<select id="queryProjectCreatedAndAuthorizedByUserId" resultType="org.apache.dolphinscheduler.dao.entity.Project">
select * from t_ds_project where id in (select project_id from t_ds_relation_project_user where user_id=#{userId}
union select id as project_id from t_ds_project where user_id=#{userId})
select * from t_ds_project where id in
(select project_id from t_ds_relation_project_user where user_id=#{userId}
union select id as project_id from t_ds_project where user_id=#{userId})
</select>
</mapper>
</mapper>

16
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProjectUserMapper.xml

@ -18,6 +18,9 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper">
<sql id="baseSql">
id, user_id, project_id, perm, create_time, update_time
</sql>
<delete id="deleteProjectRelation">
delete from t_ds_relation_project_user
where 1=1
@ -27,10 +30,11 @@
</if>
</delete>
<select id="queryProjectRelation" resultType="org.apache.dolphinscheduler.dao.entity.ProjectUser">
select *
from t_ds_relation_project_user
where project_id = #{projectId}
and user_id = #{userId}
limit 1
select
<include refid="baseSql"/>
from t_ds_relation_project_user
where project_id = #{projectId}
and user_id = #{userId}
limit 1
</select>
</mapper>
</mapper>

17
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/QueueMapper.xml

@ -18,19 +18,24 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.QueueMapper">
<sql id="baseSql">
id, queue_name, queue, create_time, update_time
</sql>
<select id="queryQueuePaging" resultType="org.apache.dolphinscheduler.dao.entity.Queue">
select *
select
<include refid="baseSql"/>
from t_ds_queue
where 1= 1
where 1= 1
<if test="searchVal != null and searchVal != ''">
and queue_name like concat('%', #{searchVal}, '%')
</if>
order by update_time desc
order by update_time desc
</select>
<select id="queryAllQueueList" resultType="org.apache.dolphinscheduler.dao.entity.Queue">
select *
select
<include refid="baseSql"/>
from t_ds_queue
where 1=1
where 1=1
<if test="queue != null and queue != ''">
and queue = #{queue}
</if>
@ -39,4 +44,4 @@
</if>
</select>
</mapper>
</mapper>

67
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ResourceMapper.xml

@ -18,8 +18,17 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ResourceMapper">
<sql id="baseSql">
id, alias, file_name, description, user_id, type, size, create_time, update_time,
pid, full_name, is_directory
</sql>
<sql id="baseSqlV2">
${alias}.id, ${alias}.alias, ${alias}.file_name, ${alias}.description, ${alias}.user_id, ${alias}.type, ${alias}.size, ${alias}.create_time, ${alias}.update_time,
${alias}.pid, ${alias}.full_name, ${alias}.is_directory
</sql>
<select id="queryResourceList" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
select
<include refid="baseSql"/>
from t_ds_resources
where 1= 1
<if test="fullName != null and fullName != ''">
@ -33,42 +42,48 @@
</if>
</select>
<select id="queryResourceListAuthored" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
select
<include refid="baseSql"/>
from t_ds_resources
where 1 = 1
<if test="type != -1">
and type=#{type}
</if>
<if test="userId != 0 and perm != 0">
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId} and perm=#{perm}
union select id as resources_id from t_ds_resources where user_id=#{userId})
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId} and perm=#{perm}
union select id as resources_id from t_ds_resources where user_id=#{userId})
</if>
<if test="userId != 0 and perm == 0">
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId}
union select id as resources_id from t_ds_resources where user_id=#{userId})
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId}
union select id as resources_id from t_ds_resources where user_id=#{userId})
</if>
</select>
<select id="queryResourcePaging" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
select
<include refid="baseSql"/>
from t_ds_resources
where type=#{type} and pid=#{id}
<if test="userId != 0">
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId}
union select id as resources_id from t_ds_resources where user_id=#{userId})
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId}
union select id as resources_id from t_ds_resources where user_id=#{userId})
</if>
<if test="searchVal != null and searchVal != ''">
and alias like concat('%', #{searchVal}, '%')
and alias like concat('%', #{searchVal}, '%')
</if>
order by update_time desc
</select>
<select id="queryAuthorizedResourceList" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select r.*
from t_ds_resources r,t_ds_relation_resources_user rel
select
<include refid="baseSqlV2">
<property name="alias" value="r"/>
</include>
from t_ds_resources r,t_ds_relation_resources_user rel
where r.id = rel.resources_id AND rel.user_id = #{userId} and perm=7
</select>
<select id="queryResourceExceptUserId" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
from t_ds_resources
select
<include refid="baseSql"/>
from t_ds_resources
where user_id <![CDATA[ <> ]]> #{userId}
</select>
<select id="queryTenantCodeByResourceName" resultType="java.lang.String">
@ -78,11 +93,12 @@
and res.full_name= #{resName}
</select>
<select id="listAuthorizedResource" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
select
<include refid="baseSql"/>
from t_ds_resources
where type=0
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId} and perm=7
union select id as resources_id from t_ds_resources where user_id=#{userId})
and id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId} and perm=7
union select id as resources_id from t_ds_resources where user_id=#{userId})
<if test="resNames != null and resNames != ''">
and full_name in
<foreach collection="resNames" item="i" open="(" close=")" separator=",">
@ -91,10 +107,11 @@
</if>
</select>
<select id="listAuthorizedResourceById" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
select
<include refid="baseSql"/>
from t_ds_resources
where id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId} and perm=7
union select id as resources_id from t_ds_resources where user_id=#{userId})
where id in (select resources_id from t_ds_relation_resources_user where user_id=#{userId} and perm=7
union select id as resources_id from t_ds_resources where user_id=#{userId})
<if test="resIds != null and resIds != ''">
and id in
<foreach collection="resIds" item="i" open="(" close=")" separator=",">
@ -102,7 +119,7 @@
</foreach>
</if>
</select>
<delete id="deleteIds" parameterType="java.lang.Integer">
delete from t_ds_resources where id in
<foreach collection="resIds" item="i" open="(" close=")" separator=",">
@ -117,14 +134,15 @@
</select>
<select id="queryResource" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
select
<include refid="baseSql"/>
from t_ds_resources
where type = #{type}
and full_name = #{fullName}
</select>
<update id="batchUpdateResource" parameterType="java.util.List">
<foreach collection="resourceList" item="resource" index="index" open="" close="" separator =";">
<foreach collection="resourceList" item="resource" index="index" open="" close="" separator=";">
update t_ds_resources
<set>
full_name=#{resource.fullName},
@ -137,7 +155,8 @@
</update>
<select id="listResourceByIds" resultType="org.apache.dolphinscheduler.dao.entity.Resource">
select *
select
<include refid="baseSql"/>
from t_ds_resources
where id in
<foreach collection="resIds" item="i" open="(" close=")" separator=",">

29
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ScheduleMapper.xml

@ -18,8 +18,19 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.ScheduleMapper">
<sql id="baseSql">
id, process_definition_id, start_time, end_time, crontab, failure_strategy, user_id, release_state,
warning_type, warning_group_id, process_instance_priority, worker_group, create_time, update_time
</sql>
<sql id="baseSqlV2">
${alias}.id, ${alias}.process_definition_id, ${alias}.start_time, ${alias}.end_time, ${alias}.crontab, ${alias}.failure_strategy, ${alias}.user_id, ${alias}.release_state,
${alias}.warning_type, ${alias}.warning_group_id, ${alias}.process_instance_priority, ${alias}.worker_group, ${alias}.create_time, ${alias}.update_time
</sql>
<select id="queryByProcessDefineIdPaging" resultType="org.apache.dolphinscheduler.dao.entity.Schedule">
select p_f.name as process_definition_name, p.name as project_name,u.user_name,s.*
select p_f.name as process_definition_name, p.name as project_name,u.user_name,
<include refid="baseSqlV2">
<property name="alias" value="s"/>
</include>
from t_ds_schedules s
join t_ds_process_definition p_f on s.process_definition_id = p_f.id
join t_ds_project as p on p_f.project_id = p.id
@ -39,9 +50,10 @@
where p.name = #{projectName}
</select>
<select id="selectAllByProcessDefineArray" resultType="org.apache.dolphinscheduler.dao.entity.Schedule">
select *
select
<include refid="baseSql"/>
from t_ds_schedules
where 1= 1
where 1= 1
<if test="processDefineIds != null and processDefineIds.length != 0 ">
and process_definition_id in
<foreach collection="processDefineIds" index="index" item="i" open="(" separator="," close=")">
@ -51,13 +63,16 @@
and release_state = 1
</select>
<select id="queryByProcessDefinitionId" resultType="org.apache.dolphinscheduler.dao.entity.Schedule">
select *
select
<include refid="baseSql"/>
from t_ds_schedules
where process_definition_id =#{processDefinitionId}
</select>
<select id="queryReleaseSchedulerListByProcessDefinitionId" resultType="org.apache.dolphinscheduler.dao.entity.Schedule">
select *
<select id="queryReleaseSchedulerListByProcessDefinitionId"
resultType="org.apache.dolphinscheduler.dao.entity.Schedule">
select
<include refid="baseSql"/>
from t_ds_schedules
where process_definition_id =#{processDefinitionId} and release_state = 1
</select>
</mapper>
</mapper>

11
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/SessionMapper.xml

@ -18,15 +18,20 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.SessionMapper">
<sql id="baseSql">
id, user_id, ip, last_login_time
</sql>
<select id="queryByUserId" resultType="org.apache.dolphinscheduler.dao.entity.Session">
select *
select
<include refid="baseSql"/>
from t_ds_session
where user_id = #{userId}
</select>
<select id="queryByUserIdAndIp" resultType="org.apache.dolphinscheduler.dao.entity.Session">
select *
select
<include refid="baseSql"/>
from t_ds_session
where user_id = #{userId} AND ip = #{ip}
</select>
</mapper>
</mapper>

45
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TaskInstanceMapper.xml

@ -18,6 +18,18 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper">
<sql id="baseSql">
id, name, task_type, process_definition_id, process_instance_id, task_json, state, submit_time,
start_time, end_time, host, execute_path, log_path, alert_flag, retry_times, pid, app_link,
flag, retry_interval, max_retry_times, task_instance_priority, worker_group, executor_id,
first_submit_time, delay_time, var_pool
</sql>
<sql id="baseSqlV2">
${alias}.id, ${alias}.name, ${alias}.task_type, ${alias}.process_definition_id, ${alias}.process_instance_id, ${alias}.task_json, ${alias}.state, ${alias}.submit_time,
${alias}.start_time, ${alias}.end_time, ${alias}.host, ${alias}.execute_path, ${alias}.log_path, ${alias}.alert_flag, ${alias}.retry_times, ${alias}.pid, ${alias}.app_link,
${alias}.flag, ${alias}.retry_interval, ${alias}.max_retry_times, ${alias}.task_instance_priority, ${alias}.worker_group, ${alias}.executor_id,
${alias}.first_submit_time, ${alias}.delay_time, ${alias}.var_pool
</sql>
<update id="setFailoverByHostAndStateArray">
update t_ds_task_instance
set state = #{destStatus}
@ -35,14 +47,16 @@
and flag = 1
</select>
<select id="findValidTaskListByProcessId" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select *
select
<include refid="baseSql"/>
from t_ds_task_instance
WHERE process_instance_id = #{processInstanceId}
WHERE process_instance_id = #{processInstanceId}
and flag = #{flag}
order by start_time desc
</select>
<select id="queryByHostAndStatus" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select *
select
<include refid="baseSql"/>
from t_ds_task_instance
where 1 = 1
<if test="host != null and host != ''">
@ -56,9 +70,9 @@
</if>
</select>
<select id="countTaskInstanceStateByUser" resultType="org.apache.dolphinscheduler.dao.entity.ExecuteStatusCount">
select state, count(0) as count
select state, count(0) as count
from t_ds_task_instance t
left join t_ds_process_definition d on d.id=t.process_definition_id
left join t_ds_process_definition d on d.id=t.process_definition_id
left join t_ds_project p on p.id=d.project_id
where 1=1
<if test="projectIds != null and projectIds.length != 0">
@ -73,7 +87,8 @@
group by t.state
</select>
<select id="queryByInstanceIdAndName" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select *
select
<include refid="baseSql"/>
from t_ds_task_instance
where process_instance_id = #{processInstanceId}
and name = #{name}
@ -98,11 +113,15 @@
</if>
</select>
<select id="queryTaskInstanceListPaging" resultType="org.apache.dolphinscheduler.dao.entity.TaskInstance">
select instance.id,instance.name,instance.task_type,instance.process_definition_id,instance.process_instance_id,instance.state,instance.submit_time,instance.start_time,instance.end_time,
instance.host,instance.execute_path,instance.log_path,instance.alert_flag,instance.retry_times,instance.pid,instance.app_link,instance.flag,instance.retry_interval,instance.max_retry_times,instance.task_instance_priority,instance.worker_group,instance.executor_id,process.name as process_instance_name
select
<include refid="baseSqlV2">
<property name="alias" value="instance"/>
</include>
,
process.name as process_instance_name
from t_ds_task_instance instance
join t_ds_process_definition define ON instance.process_definition_id = define.id
join t_ds_process_instance process on process.id=instance.process_instance_id
join t_ds_process_definition define on instance.process_definition_id = define.id
join t_ds_process_instance process on process.id=instance.process_instance_id
where define.project_id = #{projectId}
<if test="startTime != null">
and instance.start_time > #{startTime} and instance.start_time <![CDATA[ <=]]> #{endTime}
@ -111,13 +130,13 @@
and instance.process_instance_id = #{processInstanceId}
</if>
<if test="searchVal != null and searchVal != ''">
and instance.name like concat('%', #{searchVal}, '%')
and instance.name like concat('%', #{searchVal}, '%')
</if>
<if test="taskName != null and taskName != ''">
and instance.name=#{taskName}
</if>
<if test="states != null and states.length != 0">
and instance.state in
and instance.state in
<foreach collection="states" index="index" item="i" open="(" separator="," close=")">
#{i}
</foreach>
@ -129,7 +148,7 @@
and instance.executor_id = #{executorId}
</if>
<if test="processInstanceName != null and processInstanceName != ''">
and process.name like concat('%', #{processInstanceName}, '%')
and process.name like concat('%', #{processInstanceName}, '%')
</if>
order by instance.start_time desc
</select>

38
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/TenantMapper.xml

@ -18,24 +18,40 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.TenantMapper">
<sql id="baseSql">
id, tenant_code, description, queue_id, create_time, update_time
</sql>
<sql id="baseSqlV2">
${alias}.id, ${alias}.tenant_code, ${alias}.description, ${alias}.queue_id, ${alias}.create_time, ${alias}.update_time
</sql>
<select id="queryById" resultType="org.apache.dolphinscheduler.dao.entity.Tenant">
SELECT t.*,q.queue_name,q.queue
FROM t_ds_tenant t,t_ds_queue q
WHERE t.queue_id = q.id
and t.id = #{tenantId}
SELECT
<include refid="baseSqlV2">
<property name="alias" value="t"/>
</include>
,
q.queue_name,q.queue
FROM t_ds_tenant t,t_ds_queue q
WHERE t.queue_id = q.id
and t.id = #{tenantId}
</select>
<select id="queryByTenantCode" resultType="org.apache.dolphinscheduler.dao.entity.Tenant">
select *
from t_ds_tenant
where tenant_code = #{tenantCode}
select
<include refid="baseSql"/>
from t_ds_tenant
where tenant_code = #{tenantCode}
</select>
<select id="queryTenantPaging" resultType="org.apache.dolphinscheduler.dao.entity.Tenant">
SELECT t.*,q.queue_name
SELECT
<include refid="baseSqlV2">
<property name="alias" value="t"/>
</include>
, q.queue_name
FROM t_ds_tenant t,t_ds_queue q
WHERE t.queue_id = q.id
<if test="searchVal != null and searchVal != ''">
and t.tenant_code like concat('%', #{searchVal}, '%')
and t.tenant_code like concat('%', #{searchVal}, '%')
</if>
order by t.update_time desc
order by t.update_time desc
</select>
</mapper>
</mapper>

56
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UdfFuncMapper.xml

@ -19,13 +19,17 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.UdfFuncMapper">
<select id="selectUdfById" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
select *
select
id, user_id, func_name, class_name, type, arg_types,
database, description, resource_id, resource_name, create_time, update_time
from t_ds_udfs
where id = #{id}
</select>
<select id="queryUdfByIdStr" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
select *
select
id, user_id, func_name, class_name, type, arg_types,
database, description, resource_id, resource_name, create_time, update_time
from t_ds_udfs
where 1 = 1
<if test="ids != null and ids != ''">
@ -40,7 +44,7 @@
order by id asc
</select>
<select id="queryUdfFuncPaging" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
select *
select id, user_id, func_name, class_name, type, arg_types, database, description, resource_id, resource_name, create_time, update_time
from t_ds_udfs
where 1=1
<if test="searchVal!= null and searchVal != ''">
@ -48,38 +52,46 @@
</if>
<if test="userId != 0">
and id in (
select udf_id from t_ds_relation_udfs_user where user_id=#{userId}
union select id as udf_id from t_ds_udfs where user_id=#{userId})
select udf_id from t_ds_relation_udfs_user where user_id=#{userId}
union select id as udf_id from t_ds_udfs where user_id=#{userId})
</if>
order by create_time desc
</select>
<select id="getUdfFuncByType" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
select *
select
id, user_id, func_name, class_name, type, arg_types,
database, description, resource_id, resource_name, create_time, update_time
from t_ds_udfs
where type=#{type}
<if test="userId != 0">
and id in (
select udf_id from t_ds_relation_udfs_user where user_id=#{userId}
union select id as udf_id from t_ds_udfs where user_id=#{userId})
union select id as udf_id from t_ds_udfs where user_id=#{userId})
</if>
</select>
<select id="queryUdfFuncExceptUserId" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
select *
select
id, user_id, func_name, class_name, type, arg_types,
database, description, resource_id, resource_name, create_time, update_time
from t_ds_udfs
where user_id <![CDATA[ <> ]]> #{userId}
</select>
<select id="queryAuthedUdfFunc" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
SELECT u.*
SELECT
u.id, u.user_id, u.func_name, u.class_name, u.type, u.arg_types,
u.database, u.description, u.resource_id, u.resource_name, u.create_time, u.update_time
from t_ds_udfs u,t_ds_relation_udfs_user rel
WHERE u.id = rel.udf_id
AND rel.user_id = #{userId}
</select>
<select id="listAuthorizedUdfFunc" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
select *
from t_ds_udfs
select
u.id, u.user_id, u.func_name, u.class_name, u.type, u.arg_types,
u.database, u.description, u.resource_id, u.resource_name, u.create_time, u.update_time
from t_ds_udfs u
where
id in (select udf_id from t_ds_relation_udfs_user where user_id=#{userId}
union select id as udf_id from t_ds_udfs where user_id=#{userId})
union select id as udf_id from t_ds_udfs where user_id=#{userId})
<if test="udfIds != null and udfIds != ''">
and id in
<foreach collection="udfIds" item="i" open="(" close=")" separator=",">
@ -88,8 +100,10 @@
</if>
</select>
<select id="listUdfByResourceId" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
select *
from t_ds_udfs
select
u.id, u.user_id, u.func_name, u.class_name, u.type, u.arg_types,
u.database, u.description, u.resource_id, u.resource_name, u.create_time, u.update_time
from t_ds_udfs u
where 1=1
<if test="resourceIds != null and resourceIds != ''">
and resource_id in
@ -99,11 +113,13 @@
</if>
</select>
<select id="listAuthorizedUdfByResourceId" resultType="org.apache.dolphinscheduler.dao.entity.UdfFunc">
select *
from t_ds_udfs
select
u.id, u.user_id, u.func_name, u.class_name, u.type, u.arg_types,
u.database, u.description, u.resource_id, u.resource_name, u.create_time, u.update_time
from t_ds_udfs u
where
id in (select udf_id from t_ds_relation_udfs_user where user_id=#{userId}
union select id as udf_id from t_ds_udfs where user_id=#{userId})
union select id as udf_id from t_ds_udfs where user_id=#{userId})
<if test="resourceIds != null and resourceIds != ''">
and resource_id in
<foreach collection="resourceIds" item="i" open="(" close=")" separator=",">
@ -111,9 +127,8 @@
</foreach>
</if>
</select>
<update id="batchUpdateUdfFunc" parameterType="java.util.List">
<foreach collection="udfFuncList" item="udf" index="index" open="" close="" separator =";">
<foreach collection="udfFuncList" item="udf" index="index" open="" close="" separator=";">
update t_ds_udfs
<set>
resource_name=#{udf.resourceName},
@ -124,4 +139,5 @@
</where>
</foreach>
</update>
</mapper>
</mapper>

17
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserAlertGroupMapper.xml

@ -18,14 +18,21 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.UserAlertGroupMapper">
<sql id="baseSql">
${alias}.id, ${alias}.user_name, ${alias}.user_password, ${alias}.user_type, ${alias}.email, ${alias}.phone, ${alias}.tenant_id,
${alias}.create_time, ${alias}.update_time, ${alias}.queue, ${alias}.state
</sql>
<delete id="deleteByAlertgroupId">
delete from t_ds_relation_user_alertgroup
where alertgroup_id = #{alertgroupId}
</delete>
<select id="listUserByAlertgroupId" resultType="org.apache.dolphinscheduler.dao.entity.User">
SELECT u.*
FROM t_ds_relation_user_alertgroup g_u
JOIN t_ds_user u on g_u.user_id = u.id
WHERE g_u.alertgroup_id = #{alertgroupId}
SELECT
<include refid="baseSql">
<property name="alias" value="u"/>
</include>
FROM t_ds_relation_user_alertgroup g_u
JOIN t_ds_user u on g_u.user_id = u.id
WHERE g_u.alertgroup_id = #{alertgroupId}
</select>
</mapper>
</mapper>

67
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/UserMapper.xml

@ -18,16 +18,29 @@
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="org.apache.dolphinscheduler.dao.mapper.UserMapper">
<sql id="baseSql">
id, user_name, user_password, user_type, email, phone, tenant_id, create_time, update_time, queue, state
</sql>
<sql id="baseSqlV2">
${alias}.id, ${alias}.user_name, ${alias}.user_password, ${alias}.user_type, ${alias}.email, ${alias}.phone, ${alias}.tenant_id,
${alias}.create_time, ${alias}.update_time, ${alias}.queue, ${alias}.state
</sql>
<select id="queryAllGeneralUser" resultType="org.apache.dolphinscheduler.dao.entity.User">
select * from t_ds_user
select
<include refid="baseSql"/>
from t_ds_user
where user_type=1;
</select>
<select id="queryByUserNameAccurately" resultType="org.apache.dolphinscheduler.dao.entity.User">
select * from t_ds_user
select
<include refid="baseSql"/>
from t_ds_user
where user_name=#{userName}
</select>
<select id="queryUserByNamePassword" resultType="org.apache.dolphinscheduler.dao.entity.User">
select * from t_ds_user
select
<include refid="baseSql"/>
from t_ds_user
where user_name=#{userName} and user_password = #{password}
</select>
<select id="queryUserPaging" resultType="org.apache.dolphinscheduler.dao.entity.User">
@ -38,13 +51,17 @@
left join t_ds_tenant t on u.tenant_id=t.id
left join t_ds_queue q on t.queue_id = q.id
where 1=1
<if test="userName!=null and userName != ''" >
and u.user_name like concat ('%', #{userName}, '%')
<if test="userName!=null and userName != ''">
and u.user_name like concat ('%', #{userName}, '%')
</if>
order by u.update_time desc
</select>
<select id="queryDetailsById" resultType="org.apache.dolphinscheduler.dao.entity.User">
select u.*, t.tenant_code,
select
<include refid="baseSqlV2">
<property name="alias" value="u"/>
</include>
,
case when u.queue <![CDATA[ <> ]]> '' then u.queue else q.queue_name end as queue_name
from t_ds_user u
left join t_ds_tenant t on u.tenant_id=t.id
@ -52,33 +69,45 @@
WHERE u.id = #{userId}
</select>
<select id="queryUserListByAlertGroupId" resultType="org.apache.dolphinscheduler.dao.entity.User">
select u.*
from t_ds_user u, t_ds_relation_user_alertgroup rel
where u.id = rel.user_id AND rel.alertgroup_id = #{alertgroupId}
select
<include refid="baseSqlV2">
<property name="alias" value="u"/>
</include>
from t_ds_user u, t_ds_relation_user_alertgroup rel
where u.id = rel.user_id AND rel.alertgroup_id = #{alertgroupId}
</select>
<select id="queryUserListByTenant" resultType="org.apache.dolphinscheduler.dao.entity.User">
select *
from t_ds_user
where tenant_id = #{tenantId}
select
<include refid="baseSql"/>
from t_ds_user
where tenant_id = #{tenantId}
</select>
<select id="queryTenantCodeByUserId" resultType="org.apache.dolphinscheduler.dao.entity.User">
SELECT u.*,t.tenant_code
FROM t_ds_user u, t_ds_tenant t
SELECT
<include refid="baseSqlV2">
<property name="alias" value="u"/>
</include>
, t.tenant_code
FROM t_ds_user u, t_ds_tenant t
WHERE u.tenant_id = t.id AND u.id = #{userId}
</select>
<select id="queryUserByToken" resultType="org.apache.dolphinscheduler.dao.entity.User">
select u.*
select
<include refid="baseSqlV2">
<property name="alias" value="u"/>
</include>
from t_ds_user u ,t_ds_access_token t
where u.id = t.user_id and token=#{token} and t.expire_time > NOW()
</select>
<select id="queryUserListByQueue" resultType="org.apache.dolphinscheduler.dao.entity.User">
select *
from t_ds_user
where queue = #{queueName}
select
<include refid="baseSql"/>
from t_ds_user
where queue = #{queueName}
</select>
<update id="updateUserQueue" parameterType="java.lang.String">
update t_ds_user
set queue = #{newQueue}
where queue = #{oldQueue}
</update>
</mapper>
</mapper>

2
dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/WorkFlowLineageMapper.xml

@ -100,4 +100,4 @@
where source_id = #{id}::text;
</select>
</mapper>
</mapper>

97
dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java

@ -134,6 +134,43 @@ public class ProcessDefinitionMapperTest {
Assert.assertNotEquals(dataSources.size(), 0);
}
/**
* test verifyByDefineName
*/
@Test
public void testVerifyByDefineName() {
Project project = new Project();
project.setName("ut project");
project.setUserId(4);
projectMapper.insert(project);
Queue queue = new Queue();
queue.setQueue("queue");
queue.setQueueName("queue name");
queueMapper.insert(queue);
Tenant tenant = new Tenant();
tenant.setTenantCode("tenant");
tenant.setQueueId(queue.getId());
tenant.setDescription("t");
tenantMapper.insert(tenant);
User user = new User();
user.setUserName("hello");
user.setUserPassword("pwd");
user.setUserType(UserType.GENERAL_USER);
user.setTenantId(tenant.getId());
userMapper.insert(user);
//insertOne
ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setName("def 1");
processDefinition.setProjectId(project.getId());
processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date());
processDefinition.setTenantId(tenant.getId());
processDefinition.setUserId(user.getId());
processDefinitionMapper.insert(processDefinition);
ProcessDefinition definition = processDefinitionMapper.verifyByDefineName(10, "xxx");
Assert.assertEquals(definition, null);
}
/**
* test query by definition name
*/
@ -178,6 +215,64 @@ public class ProcessDefinitionMapperTest {
Assert.assertNotEquals(processDefinition1, null);
}
/**
* test queryDefinitionListByTenant
*/
@Test
public void testQueryDefinitionListByTenant() {
ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setName("def 1");
processDefinition.setProjectId(888);
processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date());
processDefinition.setTenantId(999);
processDefinition.setUserId(1234);
processDefinitionMapper.insert(processDefinition);
List<ProcessDefinition> definitions = processDefinitionMapper.queryDefinitionListByTenant(999);
Assert.assertNotEquals(definitions.size(), 0);
}
/**
* test queryByDefineId
*/
@Test
public void testQueryByDefineId() {
Project project = new Project();
project.setName("ut project");
project.setUserId(4);
projectMapper.insert(project);
Queue queue = new Queue();
queue.setQueue("queue");
queue.setQueueName("queue name");
queueMapper.insert(queue);
Tenant tenant = new Tenant();
tenant.setTenantCode("tenant");
tenant.setQueueId(queue.getId());
tenant.setDescription("t");
tenantMapper.insert(tenant);
User user = new User();
user.setUserName("hello");
user.setUserPassword("pwd");
user.setUserType(UserType.GENERAL_USER);
user.setTenantId(tenant.getId());
userMapper.insert(user);
//insertOne
ProcessDefinition processDefinition = new ProcessDefinition();
processDefinition.setName("def 1");
processDefinition.setProjectId(project.getId());
processDefinition.setUpdateTime(new Date());
processDefinition.setCreateTime(new Date());
processDefinition.setTenantId(tenant.getId());
processDefinition.setUserId(user.getId());
processDefinitionMapper.insert(processDefinition);
ProcessDefinition definition = processDefinitionMapper.queryByDefineId(333);
Assert.assertEquals(definition, null);
}
/**
* test page
*/
@ -275,4 +370,4 @@ public class ProcessDefinitionMapperTest {
ProcessDefinition processDefinition1 = processDefinitionMapper.selectById(processDefinition.getId());
Assert.assertEquals(expectedVersion, processDefinition1.getVersion());
}
}
}

6
dolphinscheduler-ui/src/js/conf/home/pages/security/pages/tenement/_source/createTenement.vue

@ -68,7 +68,6 @@
import store from '@/conf/home/store'
import mPopup from '@/module/components/popup/popup'
import mListBoxF from '@/module/components/listBoxF/listBoxF'
export default {
name: 'create-tenement',
data () {
@ -120,17 +119,14 @@
},
_verification () {
let isEn = /^[0-9a-zA-Z_.-]{1,}$/
if (!this.tenantCode.replace(/\s*/g,"")) {
this.$message.warning(`${i18n.$t('Please enter the tenant code in English')}`)
return false
}
if (!isEn.test(this.tenantCode) || _.startsWith(this.tenantCode, '_', 0) || _.startsWith(this.tenantCode, '.', 0)) {
this.$message.warning(`${i18n.$t('Please enter tenant code in English')}`)
return false
}
return true
},
_submit () {
@ -143,7 +139,6 @@
if (this.item) {
param.id = this.item.id
}
this.$refs['popup'].spinnerLoading = true
this.store.dispatch(`security/${this.item ? 'updateQueue' : 'createQueue'}`, param).then(res => {
this.$emit('onUpdate')
@ -171,7 +166,6 @@
})
},
mounted () {
},
components: { mPopup, mListBoxF }
}

Loading…
Cancel
Save