Export methods to get max, min, values od a column and sample based on a range

This commit is contained in:
Daniel García Aubert
2019-08-23 17:10:46 +02:00
parent 850bda9669
commit 2a8a8f6e6a

View File

@@ -150,6 +150,36 @@ function simpleQueryTable(sql) {
return false;
}
module.exports.getMaxMinColumnQuery = function (query, column = 'cartodb_id') {
return `
SELECT
min(${column}) AS min_id,
max(${column}) AS max_id,
(max(${column}) - min(${column})) AS id_span
FROM (${query}) _cdb_metadata_max_min;
`;
};
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
${columnSelector(columns)}
FROM (${query}) _cdb_metadata_sample
WHERE ${column} IN (${ids.join(',')})
`;
};
function getQueryLimited(query, limit = 0) {
return `