Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HCK-8696: add filtering of duplicated indexes columns for case with indexes on partitioned tables #121

Original file line number Diff line number Diff line change
@@ -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 = !uniqueKeysToColumns[columnKey];

if (!isColumnUnique) {
continue;
}

uniqueKeysToColumns[columnKey] = indexesColumn;
}

return Object.values(uniqueKeysToColumns);
};

module.exports = {
getUniqueIndexesColumns,
};
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const {
getPeriodForSystemTime,
} = require('./helpers');
const pipe = require('../helpers/pipe');
const { getUniqueIndexesColumns } = require('./helpers/getUniqueIndexesColumns');

const mergeCollectionsWithViews = ({ jsonSchemas }) => {
const [viewSchemas, collectionSchemas] = partition(jsonSchemas, jsonSchema => jsonSchema.relatedTables);
Expand Down Expand Up @@ -309,7 +310,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');
Expand Down