Browse Source

[Fix][UI Next][V1.0.0-Alpha]Fix the SQL Parameter and UDF function not shown when the datasource type is HIVE. (#9120)

Amy0104 3 years ago
parent
commit
d2138c7dfa

+ 4 - 1
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'
   }
 }
 

+ 4 - 1
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函数'
   }
 }
 

+ 1 - 1
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',

+ 14 - 2
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',

+ 59 - 0
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
+  }
+}

+ 13 - 4
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
 }

+ 2 - 1
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[] = []

+ 4 - 0
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