Skip to content

Commit de17849

Browse files
authored
Merge pull request #65 from dannleed/fix/HCK-3553-standardization-of-sampling-restrictions
HCK-3553: standardize record sampling limitation
2 parents 224f7f8 + b706a98 commit de17849

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

reverse_engineering/helpers/postgresHelpers/tableHelper.js

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,14 @@ const checkHaveJsonTypes = columns => {
131131
return _.find(columns, { type: 'json' });
132132
};
133133

134-
const getLimit = (count, recordSamplingSettings) => {
135-
const per = recordSamplingSettings.relative.value;
136-
const size =
137-
recordSamplingSettings.active === 'absolute'
138-
? recordSamplingSettings.absolute.value
139-
: Math.round((count / 100) * per);
140-
return Math.min(size, 100000);
134+
const getSampleDocSize = (count, recordSamplingSettings) => {
135+
if (recordSamplingSettings.active === 'absolute') {
136+
return Number(recordSamplingSettings.absolute.value);
137+
}
138+
139+
const limit = Math.ceil((count * recordSamplingSettings.relative.value) / 100);
140+
141+
return Math.min(limit, recordSamplingSettings.maxValue);
141142
};
142143

143144
const prepareTableConstraints = (constraintsResult, attributesWithPositions, tableIndexes) => {
@@ -355,6 +356,6 @@ module.exports = {
355356
prepareTableConstraints,
356357
prepareTableLevelData,
357358
prepareTableIndexes,
358-
getLimit,
359+
getSampleDocSize,
359360
prepareTableInheritance,
360361
};

reverse_engineering/helpers/postgresService.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const {
2424
prepareTablePartition,
2525
checkHaveJsonTypes,
2626
prepareTableConstraints,
27-
getLimit,
27+
getSampleDocSize,
2828
prepareTableLevelData,
2929
prepareTableIndexes,
3030
prepareTableInheritance,
@@ -372,7 +372,7 @@ module.exports = {
372372
const fullTableName = `${schemaName}.${tableName}`;
373373
const quantity =
374374
(await db.queryTolerant(queryConstants.GET_ROWS_COUNT(fullTableName), [], true))?.quantity || 0;
375-
const limit = getLimit(quantity, recordSamplingSettings);
375+
const limit = getSampleDocSize(quantity, recordSamplingSettings);
376376

377377
const jsonColumns = attributes.filter(({ type }) => _.includes(['json', 'jsonb'], type));
378378

0 commit comments

Comments
 (0)