Move method
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user