Move method

This commit is contained in:
Daniel García Aubert
2019-08-23 17:16:35 +02:00
parent 2a8a8f6e6a
commit 780cb80c8c
2 changed files with 14 additions and 14 deletions
@@ -141,14 +141,26 @@ function _sample(ctx) {
return queryUtils.queryPromise(ctx.dbConnection, sqlMaxMin)
.then(maxMinRes => {
const { min_id: min, id_span: span } = maxMinRes.rows[0];
const ids = queryUtils.getSampleValuesFromRange(min, span, limit);
const sqlSample = _getSQL(ctx, sql => queryUtils.getSampleFromIdsQuery(sql, ids, columns));
const values = _getSampleValuesFromRange(min, span, limit);
const sqlSample = _getSQL(ctx, sql => queryUtils.getSampleFromIdsQuery(sql, values, columns));
return queryUtils.queryPromise(ctx.dbConnection, sqlSample);
})
.then(res => ({ sample: res.rows }));
}
function _getSampleValuesFromRange (min, span, limit) {
const sample = new Set();
limit = limit < span ? limit : span;
while (sample.size < limit) {
sample.add(Math.floor(min + Math.random() * span));
}
return Array.from(sample);
}
function _columnsMetadataRequired(options) {
// We need determine the columns of a query
// if either column stats or dimension stats are required,
-12
View File
@@ -160,18 +160,6 @@ module.exports.getMaxMinColumnQuery = function (query, column = 'cartodb_id') {
`;
};
module.exports.getSampleValuesFromRange = function getSampleValuesFromRange (min, span, limit) {
const sample = new Set();
limit = limit < span ? limit : span;
while (sample.size < limit) {
sample.add(Math.floor(min + Math.random() * span));
}
return Array.from(sample);
};
module.exports.getSampleFromIdsQuery = function (query, ids, columns, column = 'cartodb_id') {
return `
SELECT