Export methods to get max, min, values od a column and sample based on a range
This commit is contained in:
@@ -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 `
|
||||
|
||||
Reference in New Issue
Block a user