You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by do...@apache.org on 2022/07/18 02:15:36 UTC

[inlong] branch master updated: [INLONG-5063][Dashboard] Support TDSQLPostgreSQL sink (#5075)

This is an automated email from the ASF dual-hosted git repository.

dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git


The following commit(s) were added to refs/heads/master by this push:
     new 7645ecafd [INLONG-5063][Dashboard] Support TDSQLPostgreSQL sink (#5075)
7645ecafd is described below

commit 7645ecafddea6610dbdccdf0e4e7720c1b0a24fd
Author: Lizhen <88...@users.noreply.github.com>
AuthorDate: Mon Jul 18 10:15:30 2022 +0800

    [INLONG-5063][Dashboard] Support TDSQLPostgreSQL sink (#5075)
---
 .../components/MetaData/StorageTDSQLPostgreSQL.tsx | 245 +++++++++++++++++++++
 inlong-dashboard/src/components/MetaData/index.ts  |   6 +
 inlong-dashboard/src/locales/cn.json               |   9 +
 inlong-dashboard/src/locales/en.json               |   9 +
 4 files changed, 269 insertions(+)

diff --git a/inlong-dashboard/src/components/MetaData/StorageTDSQLPostgreSQL.tsx b/inlong-dashboard/src/components/MetaData/StorageTDSQLPostgreSQL.tsx
new file mode 100644
index 000000000..c49b32d4d
--- /dev/null
+++ b/inlong-dashboard/src/components/MetaData/StorageTDSQLPostgreSQL.tsx
@@ -0,0 +1,245 @@
+/*
+ * 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 React from 'react';
+import {
+  getColsFromFields,
+  GetStorageColumnsType,
+  GetStorageFormFieldsType,
+} from '@/utils/metaData';
+import { ColumnsType } from 'antd/es/table';
+import EditableTable, { ColumnsItemProps } from '@/components/EditableTable';
+import i18n from '@/i18n';
+import { excludeObject } from '@/utils';
+import { sourceDataFields } from './SourceDataFields';
+
+// tdsqlpostgreSQLFieldTypes
+const tdsqlpostgreSQLFieldTypes = [
+  'SMALLINT',
+  'SMALLSERIAL',
+  'INT2',
+  'SERIAL2',
+  'INTEGER',
+  'SERIAL',
+  'BIGINT',
+  'BIGSERIAL',
+  'REAL',
+  'FLOAT4',
+  'FLOAT8',
+  'DOUBLE',
+  'NUMERIC',
+  'DECIMAL',
+  'BOOLEAN',
+  'DATE',
+  'TIME',
+  'TIMESTAMP',
+  'CHAR',
+  'CHARACTER',
+  'VARCHAR',
+  'TEXT',
+  'BYTEA',
+].map(item => ({
+  label: item,
+  value: item,
+}));
+
+const getForm: GetStorageFormFieldsType = (
+  type,
+  { currentValues, inlongGroupId, isEdit, dataType, form } = {} as any,
+) => {
+  const fileds = [
+    {
+      type: 'input',
+      label: 'JDBC URL',
+      name: 'jdbcUrl',
+      rules: [{ required: true }],
+      props: {
+        placeholder: 'jdbc:postgresql://127.0.0.1:5432/db_name',
+        disabled: isEdit && [110, 130].includes(currentValues?.status),
+        style: { width: 500 },
+      },
+    },
+    {
+      type: 'input',
+      label: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.SchemaName'),
+      name: 'schemaName',
+      rules: [{ required: true }],
+      props: {
+        disabled: isEdit && [110, 130].includes(currentValues?.status),
+      },
+      _inTable: true,
+    },
+    {
+      type: 'input',
+      label: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.TableName'),
+      name: 'tableName',
+      rules: [{ required: true }],
+      props: {
+        disabled: isEdit && [110, 130].includes(currentValues?.status),
+      },
+      _inTable: true,
+    },
+    {
+      type: 'input',
+      label: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.PrimaryKey'),
+      name: 'primaryKey',
+      rules: [{ required: true }],
+      props: {
+        disabled: isEdit && [110, 130].includes(currentValues?.status),
+      },
+      _inTable: true,
+    },
+    {
+      type: 'radio',
+      label: i18n.t('components.AccessHelper.StorageMetaData.EnableCreateResource'),
+      name: 'enableCreateResource',
+      rules: [{ required: true }],
+      initialValue: 1,
+      tooltip: i18n.t('components.AccessHelper.StorageMetaData.EnableCreateResourceHelp'),
+      props: {
+        disabled: isEdit && [110, 130].includes(currentValues?.status),
+        options: [
+          {
+            label: i18n.t('basic.Yes'),
+            value: 1,
+          },
+          {
+            label: i18n.t('basic.No'),
+            value: 0,
+          },
+        ],
+      },
+    },
+    {
+      type: 'input',
+      label: i18n.t('components.AccessHelper.StorageMetaData.Username'),
+      name: 'username',
+      rules: [{ required: true }],
+      props: {
+        disabled: isEdit && [110, 130].includes(currentValues?.status),
+      },
+      _inTable: true,
+    },
+    {
+      type: 'password',
+      label: i18n.t('components.AccessHelper.StorageMetaData.Password'),
+      name: 'password',
+      rules: [{ required: true }],
+      props: {
+        disabled: isEdit && [110, 130].includes(currentValues?.status),
+        style: {
+          maxWidth: 500,
+        },
+      },
+    },
+    {
+      type: (
+        <EditableTable
+          size="small"
+          columns={getFieldListColumns(dataType, currentValues)}
+          canDelete={(record, idx, isNew) => !isEdit || isNew}
+        />
+      ),
+      name: 'sinkFieldList',
+    },
+  ];
+
+  return type === 'col'
+    ? getColsFromFields(fileds)
+    : fileds.map(item => excludeObject(['_inTable'], item));
+};
+
+const getFieldListColumns: GetStorageColumnsType = (dataType, currentValues) => {
+  return [
+    ...sourceDataFields,
+    {
+      title: `TDSQLPOSTGRESQL${i18n.t(
+        'components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldName',
+      )}`,
+      dataIndex: 'fieldName',
+      initialValue: '',
+      rules: [
+        { required: true },
+        {
+          pattern: /^[a-z][0-9a-z_]*$/,
+          message: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldNameRule'),
+        },
+      ],
+      props: (text, record, idx, isNew) => ({
+        disabled: [110, 130].includes(currentValues?.status as number) && !isNew,
+      }),
+    },
+    {
+      title: `TDSQLPOSTGRESQL${i18n.t(
+        'components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldType',
+      )}`,
+      dataIndex: 'fieldType',
+      initialValue: tdsqlpostgreSQLFieldTypes[0].value,
+      type: 'select',
+      props: (text, record, idx, isNew) => ({
+        options: tdsqlpostgreSQLFieldTypes,
+        disabled: [110, 130].includes(currentValues?.status as number) && !isNew,
+      }),
+      rules: [{ required: true }],
+    },
+    {
+      title: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.IsMetaField'),
+      initialValue: 0,
+      dataIndex: 'isMetaField',
+      type: 'select',
+      props: (text, record, idx, isNew) => ({
+        options: [
+          {
+            label: i18n.t('basic.Yes'),
+            value: 1,
+          },
+          {
+            label: i18n.t('basic.No'),
+            value: 0,
+          },
+        ],
+      }),
+    },
+    {
+      title: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldFormat'),
+      dataIndex: 'fieldFormat',
+      initialValue: '',
+      type: 'autocomplete',
+      props: (text, record, idx, isNew) => ({
+        options: ['MICROSECONDS', 'MILLISECONDS', 'SECONDS', 'SQL', 'ISO_8601'].map(item => ({
+          label: item,
+          value: item,
+        })),
+      }),
+      visible: (text, record) =>
+        ['BIGINT', 'DATE', 'TIMESTAMP'].includes(record.fieldType as string),
+    },
+    {
+      title: i18n.t('components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldDescription'),
+      dataIndex: 'fieldComment',
+      initialValue: '',
+    },
+  ] as ColumnsItemProps[];
+};
+
+const tableColumns = getForm('col') as ColumnsType;
+
+export const StorageTDSQLPostgreSQL = {
+  getForm,
+  getFieldListColumns,
+  tableColumns,
+};
diff --git a/inlong-dashboard/src/components/MetaData/index.ts b/inlong-dashboard/src/components/MetaData/index.ts
index 0e83c0cb9..183f6809c 100644
--- a/inlong-dashboard/src/components/MetaData/index.ts
+++ b/inlong-dashboard/src/components/MetaData/index.ts
@@ -29,6 +29,7 @@ import { StorageMySQL } from './StorageMySQL';
 import { StorageOracle } from './StorageOracle';
 import { StoragePostgreSQL } from './StoragePostgreSQL';
 import { StorageSQLServer } from './StorageSQLServer';
+import { StorageTDSQLPostgreSQL } from './StorageTDSQLPostgreSQL';
 
 export interface StoragesType {
   label: string;
@@ -96,4 +97,9 @@ export const Storages: StoragesType[] = [
     value: 'SQLSERVER',
     ...StorageSQLServer,
   },
+  {
+    label: 'TDSQLPostgreSQL',
+    value: 'TDSQLPOSTGRESQL',
+    ...StorageTDSQLPostgreSQL,
+  },
 ];
diff --git a/inlong-dashboard/src/locales/cn.json b/inlong-dashboard/src/locales/cn.json
index 998d8cd4f..555f6fc92 100644
--- a/inlong-dashboard/src/locales/cn.json
+++ b/inlong-dashboard/src/locales/cn.json
@@ -163,6 +163,15 @@
   "components.AccessHelper.StorageMetaData.SQLServer.IsMetaField": "是否为元字段",
   "components.AccessHelper.StorageMetaData.SQLServer.FieldFormat": "字段格式",
   "components.AccessHelper.StorageMetaData.SQLServer.FieldDescription": "字段描述",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.SchemaName": "架构名称",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.TableName": "表名称",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.PrimaryKey": "主键",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldName": "字段名",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldNameRule": "以英文字母或下划线开头,只能包含英文字母、数字、下划线",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldType": "字段类型",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.IsMetaField": "是否为元字段",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldFormat": "字段格式",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldDescription": "字段描述",
   "components.AccessHelper.FieldsConfig.businessFields.Stripe/Second": "条/秒",
   "components.AccessHelper.FieldsConfig.businessFields.MessageMiddleware": "消息中间件",
   "components.AccessHelper.FieldsConfig.businessFields.AccessSize": "按天接入大小",
diff --git a/inlong-dashboard/src/locales/en.json b/inlong-dashboard/src/locales/en.json
index 1e64c1cb4..fb8c2105b 100644
--- a/inlong-dashboard/src/locales/en.json
+++ b/inlong-dashboard/src/locales/en.json
@@ -163,6 +163,15 @@
   "components.AccessHelper.StorageMetaData.SQLServer.IsMetaField": "IsMetaField",
   "components.AccessHelper.StorageMetaData.SQLServer.FieldFormat": "FieldFormat",
   "components.AccessHelper.StorageMetaData.SQLServer.FieldDescription": "FieldDescription",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.SchemaName": "SchemaName",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.TableName": "TableName",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.PrimaryKey": "PrimaryKey",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldName": "FieldName",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldNameRule": "At the beginning of English letters, only English letters, numbers, and underscores",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldType": "FieldType",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.IsMetaField": "IsMetaField",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldFormat": "FieldFormat",
+  "components.AccessHelper.StorageMetaData.TDSQLPostgreSQL.FieldDescription": "FieldDescription",
   "components.AccessHelper.FieldsConfig.businessFields.Stripe/Second": "Stripe / S",
   "components.AccessHelper.FieldsConfig.businessFields.MessageMiddleware": "Middleware",
   "components.AccessHelper.FieldsConfig.businessFields.AccessSize": "Access Size",