Skip to content

Commit 0a926e0

Browse files
committed
RE: add logs to identify the size of fetched json columns, add logs to identify types of columns of table
1 parent 452379f commit 0a926e0

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

reverse_engineering/helpers/postgresService.js

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,12 @@ module.exports = {
287287
const tableForeignKeys = await db.queryTolerant(queryConstants.GET_TABLE_FOREIGN_KEYS, [tableOid]);
288288
const triggers = await this._getTriggers(schemaName, tableName, schemaOid, tableOid, ignoreUdfUdpTriggers);
289289

290+
logger.info('Table data retrieved', {
291+
schemaName,
292+
tableName,
293+
columnTypes: tableColumns.map(column => column.data_type),
294+
});
295+
290296
const partitioning = prepareTablePartition(partitionResult, tableColumns);
291297
const tableLevelProperties = prepareTableLevelData(tableLevelData, tableToastOptions);
292298
const description = getDescriptionFromResult(descriptionResult);
@@ -352,7 +358,7 @@ module.exports = {
352358
tableOid,
353359
]);
354360

355-
return _.map(tableColumns, (columnData, index) => {
361+
return _.map(tableColumns, columnData => {
356362
return {
357363
...columnData,
358364
...(_.find(tableColumnsAdditionalData, { name: columnData.column_name }) || {}),
@@ -368,13 +374,23 @@ module.exports = {
368374
(await db.queryTolerant(queryConstants.GET_ROWS_COUNT(fullTableName), [], true))?.quantity || 0;
369375
const limit = getLimit(quantity, recordSamplingSettings);
370376

371-
const jsonColumns = _.chain(attributes)
372-
.filter(({ type }) => _.includes(['json', 'jsonb'], type))
373-
.map('name')
374-
.join(', ')
375-
.value();
377+
const jsonColumns = attributes.filter(({ type }) => _.includes(['json', 'jsonb'], type));
378+
379+
const jsonColumnsString = _.map(jsonColumns, 'name').join(', ');
380+
381+
const samplingDataSize = await db.queryTolerant(
382+
queryConstants.GET_SAMPLED_DATA_SIZE(fullTableName, jsonColumnsString),
383+
[limit],
384+
true,
385+
);
386+
387+
logger.info('Sampling table', {
388+
tableName,
389+
jsonColumnsNumber: jsonColumns.length,
390+
samplingDataSize: samplingDataSize?._hackolade_tmp_sampling_tbl_size,
391+
});
376392

377-
return await db.queryTolerant(queryConstants.GET_SAMPLED_DATA(fullTableName, jsonColumns), [limit]);
393+
return await db.queryTolerant(queryConstants.GET_SAMPLED_DATA(fullTableName, jsonColumnsString), [limit]);
378394
},
379395

380396
async _retrieveSingleViewData(schemaOid, schemaName, ignoreUdfUdpTriggers, viewName) {

reverse_engineering/helpers/queryConstants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ const queryConstants = {
154154
GET_DESCRIPTION_BY_OID: `SELECT obj_description($1)`,
155155
GET_ROWS_COUNT: fullTableName => `SELECT COUNT(*) AS quantity FROM ${fullTableName};`,
156156
GET_SAMPLED_DATA: (fullTableName, jsonColumns) => `SELECT ${jsonColumns} FROM ${fullTableName} LIMIT $1;`,
157+
GET_SAMPLED_DATA_SIZE: (fullTableName, jsonColumns) => `
158+
SELECT sum(pg_column_size(_hackolade_tmp_sampling_tbl.*)) AS _hackolade_tmp_sampling_tbl_size
159+
FROM (SELECT ${jsonColumns} FROM ${fullTableName} LIMIT $1) AS _hackolade_tmp_sampling_tbl;`,
157160
GET_INHERITS_PARENT_TABLE_NAME: `
158161
SELECT pc.relname AS parent_table_name FROM pg_catalog.pg_inherits AS pi
159162
INNER JOIN pg_catalog.pg_class AS pc

0 commit comments

Comments
 (0)