From f8a86fa3272ee4c858b14f8cf3c2310e49eae016 Mon Sep 17 00:00:00 2001 From: lzq986 <2719916844@qq.com> Date: Mon, 10 Aug 2026 16:04:51 +0800 Subject: [PATCH] fix(semantic): rewrite dedup SQL with correlated subquery for DB compatibility --- .../mapper/ColumnSemanticInfoMapper.xml | 38 ++++++++--------- .../mapper/LogicalTableRelationMapper.xml | 41 +++++++++---------- .../main/resources/mapper/TableInfoMapper.xml | 37 ++++++++--------- 3 files changed, 56 insertions(+), 60 deletions(-) diff --git a/data-agent-backend/src/main/resources/mapper/ColumnSemanticInfoMapper.xml b/data-agent-backend/src/main/resources/mapper/ColumnSemanticInfoMapper.xml index 580b667..92b2c14 100644 --- a/data-agent-backend/src/main/resources/mapper/ColumnSemanticInfoMapper.xml +++ b/data-agent-backend/src/main/resources/mapper/ColumnSemanticInfoMapper.xml @@ -18,25 +18,25 @@ - SELECT * - FROM ( - SELECT - column_info.*, - ROW_NUMBER() OVER ( - PARTITION BY datasource_id, LOWER(table_name), LOWER(column_name) - ORDER BY - CASE - WHEN column_description IS NOT NULL AND column_description <> '' THEN 0 - WHEN is_visible = 0 THEN 0 - ELSE 1 - END ASC, - update_time DESC, - create_time DESC, - id DESC - ) AS row_num - FROM column_info - ) deduplicated_columns - WHERE row_num = 1 + SELECT t.* + FROM column_info t + WHERE t.id = ( + SELECT t2.id + FROM column_info t2 + WHERE t2.datasource_id = t.datasource_id + AND LOWER(t2.table_name) = LOWER(t.table_name) + AND LOWER(t2.column_name) = LOWER(t.column_name) + ORDER BY + CASE + WHEN t2.column_description IS NOT NULL AND t2.column_description <> '' THEN 0 + WHEN t2.is_visible = 0 THEN 0 + ELSE 1 + END ASC, + t2.update_time DESC, + t2.create_time DESC, + t2.id DESC + LIMIT 1 + ) diff --git a/data-agent-backend/src/main/resources/mapper/TableInfoMapper.xml b/data-agent-backend/src/main/resources/mapper/TableInfoMapper.xml index 5a1c021..e86f9a2 100644 --- a/data-agent-backend/src/main/resources/mapper/TableInfoMapper.xml +++ b/data-agent-backend/src/main/resources/mapper/TableInfoMapper.xml @@ -16,25 +16,24 @@ - SELECT * - FROM ( - SELECT - table_info.*, - ROW_NUMBER() OVER ( - PARTITION BY datasource_id, LOWER(table_name) - ORDER BY - CASE - WHEN table_description IS NOT NULL AND table_description <> '' THEN 0 - WHEN is_visible = 0 THEN 0 - ELSE 1 - END ASC, - update_time DESC, - create_time DESC, - id DESC - ) AS row_num - FROM table_info - ) deduplicated_tables - WHERE row_num = 1 + SELECT t.* + FROM table_info t + WHERE t.id = ( + SELECT t2.id + FROM table_info t2 + WHERE t2.datasource_id = t.datasource_id + AND LOWER(t2.table_name) = LOWER(t.table_name) + ORDER BY + CASE + WHEN t2.table_description IS NOT NULL AND t2.table_description <> '' THEN 0 + WHEN t2.is_visible = 0 THEN 0 + ELSE 1 + END ASC, + t2.update_time DESC, + t2.create_time DESC, + t2.id DESC + LIMIT 1 + )