From f734f56b565b579615f3859db7f02a4f94b98c3a Mon Sep 17 00:00:00 2001 From: Nazar Kovtun Date: Thu, 14 Nov 2024 17:17:55 +0200 Subject: [PATCH] HCK-8696: add filtering of duplicated indexes columns for case with indexes on partitioned tables --- .../helpers/getUniqueIndexesColumns.js | 23 +++++++++++++++++++ .../reverseEngineeringService.js | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 reverse_engineering/reverseEngineeringService/helpers/getUniqueIndexesColumns.js diff --git a/reverse_engineering/reverseEngineeringService/helpers/getUniqueIndexesColumns.js b/reverse_engineering/reverseEngineeringService/helpers/getUniqueIndexesColumns.js new file mode 100644 index 0000000..39e4685 --- /dev/null +++ b/reverse_engineering/reverseEngineeringService/helpers/getUniqueIndexesColumns.js @@ -0,0 +1,23 @@ +const getColumnUniqueKey = ({ IndexName, TableName, schemaName, columnName }) => + `${schemaName}${IndexName}${TableName}${columnName}`; + +const getUniqueIndexesColumns = ({ indexesColumns }) => { + const uniqueKeysToColumns = {}; + + for (const indexesColumn of indexesColumns) { + const columnKey = getColumnUniqueKey(indexesColumn); + const isColumnUnique = !Boolean(uniqueKeysToColumns[columnKey]); + + if (!isColumnUnique) { + continue; + } + + uniqueKeysToColumns[columnKey] = indexesColumn; + } + + return Object.values(uniqueKeysToColumns); +}; + +module.exports = { + getUniqueIndexesColumns, +}; diff --git a/reverse_engineering/reverseEngineeringService/reverseEngineeringService.js b/reverse_engineering/reverseEngineeringService/reverseEngineeringService.js index 36c4b37..8e8fa90 100644 --- a/reverse_engineering/reverseEngineeringService/reverseEngineeringService.js +++ b/reverse_engineering/reverseEngineeringService/reverseEngineeringService.js @@ -41,6 +41,7 @@ const { getPeriodForSystemTime, } = require('./helpers'); const pipe = require('../helpers/pipe'); +const { getUniqueIndexesColumns } = require('./helpers/getUniqueIndexesColumns'); const mergeCollectionsWithViews = jsonSchemas => jsonSchemas.reduce((structuredJSONSchemas, jsonSchema) => { @@ -315,7 +316,8 @@ const reverseCollectionsToJSON = logger => async (dbConnectionClient, tablesInfo rawDatabaseIndexes.map(i => i.index_id), logger, ); - const databaseIndexes = addTotalBucketCountToDatabaseIndexes(rawDatabaseIndexes, indexesBucketCount); + const uniqueDatabaseIndexesColumns = getUniqueIndexesColumns({ indexesColumns: rawDatabaseIndexes }); + const databaseIndexes = addTotalBucketCountToDatabaseIndexes(uniqueDatabaseIndexesColumns, indexesBucketCount); return await Object.entries(tablesInfo).reduce(async (jsonSchemas, [schemaName, tableNames]) => { logger.log('info', { message: `Fetching '${dbName}' database information` }, 'Reverse Engineering');