[Core] [Manager] Improve the clickhouse metadata management to obtain type

This commit is contained in:
qianmoQ 2023-05-17 18:53:09 +08:00
parent c15245c8a5
commit 8bdc9e932c
5 changed files with 210 additions and 4 deletions

View File

@ -19,7 +19,7 @@ WHERE
GROUP BY
table_type', 'Finds all table types under the database according to the database', 'H2', '[{"column":"database","type":"String","expression":"${database:String}"}]', TRUE),
('FindTableByDatabaseAndType', 'SELECT
TABLE_CATALOG AS DATABASE_NAME,
TABLE_CATALOG AS TABLE_CATALOG,
TABLE_NAME AS TABLE_NAME
FROM
INFORMATION_SCHEMA.TABLES
@ -281,3 +281,104 @@ ORDER BY
COLUMN_NAME', 'Gets a collection of related data based on the specified database, table, and data type', 'MySQL',
'[{"column":"database","type":"String","expression":"${database:String}"},{"column":"table","type":"String","expression":"${table:String}"},{"column":"type","type":"String","expression":"${type:String}"}]',
TRUE);
/* ClickHouse */
INSERT INTO template_sql(name, content, description, plugin, configure, `system`)
VALUES ('FindTableTypeByDatabase', 'SELECT
multiIf(
startsWith(engine, ''System''),
''system'',
endsWith(engine, ''View''),
''view'',
startsWith(engine, ''Kafka''),
''kafka'',
endsWith(engine, ''Log''),
''log'',
''table''
) AS TABLE_TYPE
FROM
system.tables
WHERE
database = ''${database:String}''
GROUP BY
TABLE_TYPE', 'Finds all table types under the database according to the database', 'ClickHouse', '[{"column":"database","type":"String","expression":"${database:String}"}]', TRUE),
('FindTableByDatabaseAndType', 'SELECT
`database` AS TABLE_CATALOG,
name AS TABLE_NAME
FROM
system.tables
WHERE
`database` = ''${database:String}''
AND multiIf(
startsWith(engine, ''System''),
''system'',
endsWith(engine, ''View''),
''view'',
startsWith(engine, ''Kafka''),
''kafka'',
endsWith(engine, ''Log''),
''log'',
''table''
) = ''${type:String}''
GROUP BY
TABLE_NAME,
`database`', 'Gets a collection of related data based on the specified database and data type', 'ClickHouse',
'[{"column":"database","type":"String","expression":"${database:String}"},{"column":"type","type":"String","expression":"${type:String}"}]', TRUE),
('FindColumnTypeByDatabaseAndTable', 'SELECT
''${database:String}'' AS TABLE_CATALOG,
COLUMN_TYPE
FROM
(
SELECT
CASE
WHEN (
is_in_primary_key = ''1''
AND is_in_partition_key = ''1''
) THEN ''index,primaryKey''
WHEN is_in_primary_key = ''1'' THEN ''primaryKey''
WHEN is_in_primary_key = ''1'' THEN ''index''
ELSE ''column''
END AS COLUMN_TYPE
FROM
system.columns col
WHERE
`database` = ''${database:String}''
AND `table` = ''${table:String}''
ORDER BY
`name`
) AS tmp
GROUP BY
COLUMN_TYPE', 'Gets the data column classification collection based on the provided database and data table', 'ClickHouse',
'[{"column":"database","type":"String","expression":"${database:String}"},{"column":"table","type":"String","expression":"${table:String}"}]', TRUE),
('FindColumnByDatabaseAndTableAndType', 'SELECT
COLUMN_NAME,
COLUMN_TYPE
FROM
(
SELECT
`name` AS COLUMN_NAME,
CASE
WHEN (
is_in_primary_key = ''1''
AND is_in_partition_key = ''1''
) THEN ''index,primaryKey''
WHEN is_in_primary_key = ''1'' THEN ''primaryKey''
WHEN is_in_primary_key = ''1'' THEN ''index''
ELSE ''column''
END AS COLUMN_TYPE
FROM
system.columns col
WHERE
`database` = ''${database:String}''
AND `table` = ''${table:String}''
ORDER BY
`name`
) AS tmp
WHERE
COLUMN_TYPE LIKE ''%${type:String}%''
GROUP BY
COLUMN_NAME,
COLUMN_TYPE
ORDER BY
COLUMN_NAME', 'Gets a collection of related data based on the specified database, table, and data type', 'ClickHouse',
'[{"column":"database","type":"String","expression":"${database:String}"},{"column":"table","type":"String","expression":"${table:String}"},{"column":"type","type":"String","expression":"${type:String}"}]',
TRUE);

View File

@ -566,3 +566,104 @@ ORDER BY
COLUMN_NAME', 'Gets a collection of related data based on the specified database, table, and data type', 'MySQL',
'[{"column":"database","type":"String","expression":"${database:String}"},{"column":"table","type":"String","expression":"${table:String}"},{"column":"type","type":"String","expression":"${type:String}"}]',
TRUE);
/* ClickHouse */
INSERT INTO template_sql(name, content, description, plugin, configure, `system`)
VALUES ('FindTableTypeByDatabase', 'SELECT
multiIf(
startsWith(engine, ''System''),
''system'',
endsWith(engine, ''View''),
''view'',
startsWith(engine, ''Kafka''),
''kafka'',
endsWith(engine, ''Log''),
''log'',
''table''
) AS TABLE_TYPE
FROM
system.tables
WHERE
database = ''${database:String}''
GROUP BY
TABLE_TYPE', 'Finds all table types under the database according to the database', 'ClickHouse', '[{"column":"database","type":"String","expression":"${database:String}"}]', TRUE),
('FindTableByDatabaseAndType', 'SELECT
`database` AS TABLE_CATALOG,
name AS TABLE_NAME
FROM
system.tables
WHERE
`database` = ''${database:String}''
AND multiIf(
startsWith(engine, ''System''),
''system'',
endsWith(engine, ''View''),
''view'',
startsWith(engine, ''Kafka''),
''kafka'',
endsWith(engine, ''Log''),
''log'',
''table''
) = ''${type:String}''
GROUP BY
TABLE_NAME,
`database`', 'Gets a collection of related data based on the specified database and data type', 'ClickHouse',
'[{"column":"database","type":"String","expression":"${database:String}"},{"column":"type","type":"String","expression":"${type:String}"}]', TRUE),
('FindColumnTypeByDatabaseAndTable', 'SELECT
''${database:String}'' AS TABLE_CATALOG,
COLUMN_TYPE
FROM
(
SELECT
CASE
WHEN (
is_in_primary_key = ''1''
AND is_in_partition_key = ''1''
) THEN ''index,primaryKey''
WHEN is_in_primary_key = ''1'' THEN ''primaryKey''
WHEN is_in_primary_key = ''1'' THEN ''index''
ELSE ''column''
END AS COLUMN_TYPE
FROM
system.columns col
WHERE
`database` = ''${database:String}''
AND `table` = ''${table:String}''
ORDER BY
`name`
) AS tmp
GROUP BY
COLUMN_TYPE', 'Gets the data column classification collection based on the provided database and data table', 'ClickHouse',
'[{"column":"database","type":"String","expression":"${database:String}"},{"column":"table","type":"String","expression":"${table:String}"}]', TRUE),
('FindColumnByDatabaseAndTableAndType', 'SELECT
COLUMN_NAME,
COLUMN_TYPE
FROM
(
SELECT
`name` AS COLUMN_NAME,
CASE
WHEN (
is_in_primary_key = ''1''
AND is_in_partition_key = ''1''
) THEN ''index,primaryKey''
WHEN is_in_primary_key = ''1'' THEN ''primaryKey''
WHEN is_in_primary_key = ''1'' THEN ''index''
ELSE ''column''
END AS COLUMN_TYPE
FROM
system.columns col
WHERE
`database` = ''${database:String}''
AND `table` = ''${table:String}''
ORDER BY
`name`
) AS tmp
WHERE
COLUMN_TYPE LIKE ''%${type:String}%''
GROUP BY
COLUMN_NAME,
COLUMN_TYPE
ORDER BY
COLUMN_NAME', 'Gets a collection of related data based on the specified database, table, and data type', 'ClickHouse',
'[{"column":"database","type":"String","expression":"${database:String}"},{"column":"table","type":"String","expression":"${table:String}"},{"column":"type","type":"String","expression":"${type:String}"}]',
TRUE);

View File

@ -107,5 +107,7 @@ export default {
upload: 'Upload',
view: 'View',
index: 'Index',
primaryKey: 'Primary Key'
primaryKey: 'Primary Key',
kafka: 'Kafka',
log: 'Log',
}

View File

@ -107,5 +107,7 @@ export default {
upload: '上传',
view: '视图',
index: '索引',
primaryKey: '主键'
primaryKey: '主键',
kafka: 'Kafka',
log: '日志',
}

View File

@ -46,7 +46,7 @@
<Button :disabled="currentPageNumber === 1" shape="circle" type="text"
size="small" icon="md-arrow-back" @click="handlerChangePage(false)"/>
<Input v-model="currentPageNumber" size="small" style="max-width: 50px;"/>
<Button :disabled="tableConfigure.columns.length < configure.limit" shape="circle" type="text"
<Button :disabled="tableConfigure?.columns.length < configure.limit" shape="circle" type="text"
size="small" icon="md-arrow-forward" @click="handlerChangePage(true)"/>
</Space>
</div>