From d2138c7dfacee8aff85a423b1a8f469558ba88f2 Mon Sep 17 00:00:00 2001 From: Amy0104 <97265214+Amy0104@users.noreply.github.com> Date: Wed, 23 Mar 2022 16:34:09 +0800 Subject: [PATCH] [Fix][UI Next][V1.0.0-Alpha]Fix the SQL Parameter and UDF function not shown when the datasource type is HIVE. (#9120) --- .../src/locales/modules/en_US.ts | 5 +- .../src/locales/modules/zh_CN.ts | 5 +- .../src/service/modules/resources/index.ts | 2 +- .../task/components/node/fields/use-sql.ts | 16 ++++- .../task/components/node/fields/use-udfs.ts | 59 +++++++++++++++++++ .../task/components/node/format-data.ts | 17 ++++-- .../task/components/node/tasks/use-sql.ts | 3 +- .../projects/task/components/node/types.ts | 4 ++ 8 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-udfs.ts diff --git a/dolphinscheduler-ui-next/src/locales/modules/en_US.ts b/dolphinscheduler-ui-next/src/locales/modules/en_US.ts index 2cdc8706a0..59569b9f20 100644 --- a/dolphinscheduler-ui-next/src/locales/modules/en_US.ts +++ b/dolphinscheduler-ui-next/src/locales/modules/en_US.ts @@ -914,7 +914,10 @@ const project = { title_tips: 'Please enter the title of email', alarm_group: 'Alarm group', alarm_group_tips: 'Alarm group required', - integer_tips: 'Please enter a positive integer' + integer_tips: 'Please enter a positive integer', + sql_parameter: 'SQL Parameter', + format_tips: 'Please enter format', + udf_function: 'UDF Function' } } diff --git a/dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts b/dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts index 180a8b15e2..dabacef8b5 100644 --- a/dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts +++ b/dolphinscheduler-ui-next/src/locales/modules/zh_CN.ts @@ -904,7 +904,10 @@ const project = { title_tips: '请输入邮件主题', alarm_group: '告警组', alarm_group_tips: '告警组必填', - integer_tips: '请输入一个正整数' + integer_tips: '请输入一个正整数', + sql_parameter: 'sql参数', + format_tips: '请输入格式为', + udf_function: 'UDF函数' } } diff --git a/dolphinscheduler-ui-next/src/service/modules/resources/index.ts b/dolphinscheduler-ui-next/src/service/modules/resources/index.ts index 28f395f2b0..2acf572ee7 100644 --- a/dolphinscheduler-ui-next/src/service/modules/resources/index.ts +++ b/dolphinscheduler-ui-next/src/service/modules/resources/index.ts @@ -142,7 +142,7 @@ export function queryUdfFuncListPaging(params: ListReq): any { }) } -export function queryUdfFuncList(params: IdReq & ListReq): any { +export function queryUdfFuncList(params: { type: 'HIVE' | 'SPARK' }): any { return axios({ url: '/resources/udf-func/list', method: 'get', diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-sql.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-sql.ts index 213f5f4e7e..48a92fcf5f 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-sql.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-sql.ts @@ -14,17 +14,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { ref, onMounted } from 'vue' +import { ref, onMounted, computed } from 'vue' import { useI18n } from 'vue-i18n' import { queryResourceList } from '@/service/modules/resources' import { removeUselessChildren } from '@/utils/tree-format' +import { useUdfs } from './use-udfs' import type { IJsonItem } from '../types' export function useSql(model: { [field: string]: any }): IJsonItem[] { const { t } = useI18n() const options = ref([]) - const loading = ref(false) + const hiveSpan = computed(() => (model.type === 'HIVE' ? 24 : 0)) const getResourceList = async () => { if (loading.value) return @@ -40,6 +41,16 @@ export function useSql(model: { [field: string]: any }): IJsonItem[] { }) return [ + { + type: 'input', + field: 'connParams', + name: t('project.node.sql_parameter'), + props: { + placeholder: + t('project.node.format_tips') + ' key1=value1;key2=value2...' + }, + span: hiveSpan + }, { type: 'editor', field: 'sql', @@ -50,6 +61,7 @@ export function useSql(model: { [field: string]: any }): IJsonItem[] { message: t('project.node.sql_empty_tips') } }, + useUdfs(model), { type: 'tree-select', field: 'resourceList', diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-udfs.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-udfs.ts new file mode 100644 index 0000000000..1fb0f549cb --- /dev/null +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/fields/use-udfs.ts @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { ref, watch, computed } from 'vue' +import { useI18n } from 'vue-i18n' +import { queryUdfFuncList } from '@/service/modules/resources' +import type { IJsonItem } from '../types' + +export function useUdfs(model: { [field: string]: any }): IJsonItem { + const { t } = useI18n() + const options = ref([]) + const loading = ref(false) + const span = computed(() => (['HIVE', 'SPARK'].includes(model.type) ? 24 : 0)) + + const getUdfs = async () => { + if (loading.value) return + loading.value = true + const res = await queryUdfFuncList({ type: model.type }) + options.value = res.map((udf: { id: number; funcName: string }) => ({ + value: udf.id, + label: udf.funcName + })) + loading.value = false + } + + watch( + () => model.type, + (value) => { + if (['HIVE', 'SPARK'].includes(value)) { + getUdfs() + } + } + ) + + return { + type: 'select', + field: 'udfs', + options: options, + name: t('project.node.udf_function'), + props: { + multiple: true, + loading + }, + span + } +} diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts index ce1c23c4f3..745c4c3d7b 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/format-data.ts @@ -181,8 +181,14 @@ export function formatParams(data: INodeData): { taskParams.postStatements = data.postStatements taskParams.sendEmail = data.sendEmail taskParams.displayRows = data.displayRows - taskParams.title = data.title - taskParams.groupId = data.groupId + if (data.sendEmail) { + taskParams.title = data.title + taskParams.groupId = data.groupId + } + if (data.type === 'HIVE') { + if (data.udfs) taskParams.udfs = data.udfs.join(',') + taskParams.connParams = data.connParams + } } if (data.taskType === 'PROCEDURE') { @@ -476,10 +482,13 @@ export function formatModel(data: ITaskData) { } if (data.taskParams?.conditionResult?.successNode?.length) { - params.successBranch = data.taskParams?.conditionResult.successNode[0] + params.successBranch = data.taskParams.conditionResult.successNode[0] } if (data.taskParams?.conditionResult?.failedNode?.length) { - params.failedBranch = data.taskParams?.conditionResult.failedNode[0] + params.failedBranch = data.taskParams.conditionResult.failedNode[0] + } + if (data.taskParams?.udfs) { + params.udfs = data.taskParams.udfs?.split(',') } return params } diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/tasks/use-sql.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/tasks/use-sql.ts index 2e8ccc7776..9c9fb1336f 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/tasks/use-sql.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/tasks/use-sql.ts @@ -49,7 +49,8 @@ export function useSql({ sql: '', sqlType: '0', preStatements: [], - postStatements: [] + postStatements: [], + udfs: [] } as INodeData) let extra: IJsonItem[] = [] diff --git a/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts b/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts index d6af9bba4b..52ffa87917 100644 --- a/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts +++ b/dolphinscheduler-ui-next/src/views/projects/task/components/node/types.ts @@ -284,6 +284,8 @@ interface ITaskParams { successNode?: number[] failedNode?: number[] } + udfs?: string + connParams?: string } interface INodeData @@ -296,6 +298,7 @@ interface INodeData | 'dependence' | 'sparkParameters' | 'conditionResult' + | 'udfs' >, ISqoopTargetData, ISqoopSourceData, @@ -332,6 +335,7 @@ interface INodeData definition?: object successBranch?: number failedBranch?: number + udfs?: string[] } interface ITaskData