@@ -5,6 +5,9 @@ const { getObjectsFromDatabase, getNewConnectionClientByDb } = require('./helper
55const getSampleDocSize = require ( '../helpers/getSampleDocSize' ) ;
66const { logAuthTokenInfo } = require ( '../helpers/logInfo' ) ;
77const { getConnection } = require ( './helpers/connection' ) ;
8+ const {
9+ queryForRetrievingTheTablesSelectedByTheUser,
10+ } = require ( '../queries/queryForRetrievingTheTablesSelectedByTheUser' ) ;
811
912const QUERY_REQUEST_TIMEOUT = 60000 ;
1013
@@ -253,32 +256,31 @@ const getViewsIndexes = async (connectionClient, dbName) => {
253256 ) ;
254257} ;
255258
256- const getPartitions = async ( connectionClient , dbName , logger ) => {
257- const currentDbConnectionClient = await getNewConnectionClientByDb ( connectionClient , dbName ) ;
258-
259+ const getPartitions = async ( { connectionClient, tablesInfo, dbName, logger } ) => {
259260 logger . log ( 'info' , { message : `Get '${ dbName } ' database partitions.` } , 'Reverse Engineering' ) ;
260-
261- return mapResponse (
262- await currentDbConnectionClient . query `
263- SELECT
264- sch.name AS schemaName,
265- tbl.name AS tableName,
261+ const currentDbConnectionClient = await getNewConnectionClientByDb ( connectionClient , dbName ) ;
262+ const tablesSelectedByTheUser = queryForRetrievingTheTablesSelectedByTheUser ( { schemaToTablesMap : tablesInfo } ) ;
263+ const queryForRetrievingThePartitions = `
264+ WITH user_selected_tables AS (${ tablesSelectedByTheUser . sql ( ) } )
265+ SELECT
266+ tbl.${ tablesSelectedByTheUser . projection . schemaName } AS schemaName,
267+ tbl.${ tablesSelectedByTheUser . projection . tableName } AS tableName,
266268 prt.partition_number,
267269 pf.boundary_value_on_right AS range,
268270 c.name AS name,
269271 rng.value AS value
270- FROM sys.schemas sch
271- INNER JOIN sys.tables tbl ON sch.schema_id = tbl.schema_id
272- INNER JOIN sys.partitions prt ON prt.object_id = tbl.object_id
272+ FROM user_selected_tables tbl
273+ INNER JOIN sys.partitions prt ON prt.object_id = tbl.${ tablesSelectedByTheUser . projection . tableId }
273274 INNER JOIN sys.indexes idx ON prt.object_id = idx.object_id AND prt.index_id = idx.index_id
274275 INNER JOIN sys.data_spaces ds ON idx.data_space_id = ds.[data_space_id]
275276 INNER JOIN sys.partition_schemes ps ON ds.data_space_id = ps.data_space_id
276277 INNER JOIN sys.partition_functions pf ON ps.function_id = pf.function_id
277278 INNER JOIN sys.index_columns ic ON ic.object_id = idx.object_id AND ic.index_id = idx.index_id AND ic.partition_ordinal >= 1
278- INNER JOIN sys.columns c ON tbl.object_id = c.object_id AND ic.column_id = c.column_id
279+ INNER JOIN sys.columns c ON tbl.${ tablesSelectedByTheUser . projection . tableId } = c.object_id AND ic.column_id = c.column_id
279280 LEFT JOIN sys.partition_range_values rng ON pf.function_id = rng.function_id AND rng.boundary_id = prt.partition_number
280- ` ,
281- ) ;
281+ ` ;
282+
283+ return mapResponse ( await currentDbConnectionClient . query ( queryForRetrievingThePartitions ) ) ;
282284} ;
283285
284286const getTableColumnsDescription = async ( connectionClient , dbName , tableName , schemaName ) => {
0 commit comments