Skip to content

Commit

Permalink
[INLONG-5004][Dashboard] Support PostgreSQL sink (apache#5022)
Browse files Browse the repository at this point in the history
  • Loading branch information
bluewang authored and bruceneenhl committed Aug 12, 2022
1 parent 953c2ea commit fed0522
Show file tree
Hide file tree
Showing 5 changed files with 267 additions and 2 deletions.
4 changes: 2 additions & 2 deletions inlong-dashboard/src/components/MetaData/StorageOracle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const oracleFieldTypes = [
'CLOB',
'RAW',
'BLOB',
// 'interval',
].map(item => ({
label: item,
value: item,
Expand All @@ -65,7 +64,7 @@ const getForm: GetStorageFormFieldsType = (
name: 'jdbcUrl',
rules: [{ required: true }],
props: {
placeholder: 'jdbc:oracle:thin://127.0.0.1:3306/write',
placeholder: 'jdbc:oracle:thin://127.0.0.1:1521/db_name',
disabled: isEdit && [110, 130].includes(currentValues?.status),
style: { width: 500 },
},
Expand Down Expand Up @@ -181,6 +180,7 @@ const getFieldListColumns: GetStorageColumnsType = (dataType, currentValues) =>
},
{
title: i18n.t('components.AccessHelper.StorageMetaData.Oracle.IsMetaField'),
initialValue: 0,
dataIndex: 'isMetaField',
type: 'select',
props: (text, record, idx, isNew) => ({
Expand Down
241 changes: 241 additions & 0 deletions inlong-dashboard/src/components/MetaData/StoragePostgreSQL.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,241 @@
/*
* 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';

// postgreSQLFieldTypes
const postgreSQLFieldTypes = [
'SMALLINT',
'INT2',
'SMALLSERIAL',
'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.PostgreSQL.DbName'),
name: 'dbName',
rules: [{ required: true }],
props: {
disabled: isEdit && [110, 130].includes(currentValues?.status),
},
_inTable: true,
},
{
type: 'input',
label: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.TableName'),
name: 'tableName',
rules: [{ required: true }],
props: {
disabled: isEdit && [110, 130].includes(currentValues?.status),
},
_inTable: true,
},
{
type: 'input',
label: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.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: `POSTGRESQL${i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.FieldName')}`,
dataIndex: 'fieldName',
initialValue: '',
rules: [
{ required: true },
{
pattern: /^[a-z][0-9a-z_]*$/,
message: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.FieldNameRule'),
},
],
props: (text, record, idx, isNew) => ({
disabled: [110, 130].includes(currentValues?.status as number) && !isNew,
}),
},
{
title: `POSTGRESQL${i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.FieldType')}`,
dataIndex: 'fieldType',
initialValue: postgreSQLFieldTypes[0].value,
type: 'select',
props: (text, record, idx, isNew) => ({
options: postgreSQLFieldTypes,
disabled: [110, 130].includes(currentValues?.status as number) && !isNew,
}),
rules: [{ required: true }],
},
{
title: i18n.t('components.AccessHelper.StorageMetaData.PostgreSQL.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.PostgreSQL.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.PostgreSQL.FieldDescription'),
dataIndex: 'fieldComment',
initialValue: '',
},
] as ColumnsItemProps[];
};

const tableColumns = getForm('col') as ColumnsType;

export const StoragePostgreSQL = {
getForm,
getFieldListColumns,
tableColumns,
};
6 changes: 6 additions & 0 deletions inlong-dashboard/src/components/MetaData/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { StorageEs } from './StorageEs';
import { StorageGreenplum } from './StorageGreenplum';
import { StorageMySQL } from './StorageMySQL';
import { StorageOracle } from './StorageOracle';
import { StoragePostgreSQL } from './StoragePostgreSQL';

export interface StoragesType {
label: string;
Expand Down Expand Up @@ -84,4 +85,9 @@ export const Storages: StoragesType[] = [
value: 'ORACLE',
...StorageOracle,
},
{
label: 'PostgreSQL',
value: 'POSTGRES',
...StoragePostgreSQL,
},
];
9 changes: 9 additions & 0 deletions inlong-dashboard/src/locales/cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@
"components.AccessHelper.StorageMetaData.Oracle.IsMetaField": "是否为元字段",
"components.AccessHelper.StorageMetaData.Oracle.FieldFormat": "字段格式",
"components.AccessHelper.StorageMetaData.Oracle.FieldDescription": "字段描述",
"components.AccessHelper.StorageMetaData.PostgreSQL.DbName": "DB名称",
"components.AccessHelper.StorageMetaData.PostgreSQL.TableName": "表名称",
"components.AccessHelper.StorageMetaData.PostgreSQL.PrimaryKey": "主键",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldName": "字段名",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldNameRule": "以英文字母或下划线开头,只能包含英文字母、数字、下划线",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldType": "字段类型",
"components.AccessHelper.StorageMetaData.PostgreSQL.IsMetaField": "是否为元字段",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldFormat": "字段格式",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldDescription": "字段描述",
"components.AccessHelper.FieldsConfig.businessFields.Stripe/Second": "条/秒",
"components.AccessHelper.FieldsConfig.businessFields.MessageMiddleware": "消息中间件",
"components.AccessHelper.FieldsConfig.businessFields.AccessSize": "按天接入大小",
Expand Down
9 changes: 9 additions & 0 deletions inlong-dashboard/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@
"components.AccessHelper.StorageMetaData.Oracle.IsMetaField": "IsMetaField",
"components.AccessHelper.StorageMetaData.Oracle.FieldFormat": "FieldFormat",
"components.AccessHelper.StorageMetaData.Oracle.FieldDescription": "FieldDescription",
"components.AccessHelper.StorageMetaData.PostgreSQL.DbName": "DbName",
"components.AccessHelper.StorageMetaData.PostgreSQL.TableName": "TableName",
"components.AccessHelper.StorageMetaData.PostgreSQL.PrimaryKey": "PrimaryKey",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldName": "FieldName",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldNameRule": "At the beginning of English letters, only English letters, numbers, and underscores",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldType": "FieldType",
"components.AccessHelper.StorageMetaData.PostgreSQL.IsMetaField": "IsMetaField",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldFormat": "FieldFormat",
"components.AccessHelper.StorageMetaData.PostgreSQL.FieldDescription": "FieldDescription",
"components.AccessHelper.FieldsConfig.businessFields.Stripe/Second": "Stripe / S",
"components.AccessHelper.FieldsConfig.businessFields.MessageMiddleware": "Middleware",
"components.AccessHelper.FieldsConfig.businessFields.AccessSize": "Access Size",
Expand Down

0 comments on commit fed0522

Please sign in to comment.