Modify sample metadata
This commit is contained in:
parent
71dba04d83
commit
25e3395580
@ -125,22 +125,28 @@ function mergeColumns(results) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SAMPLE_SEED = 0.5;
|
|
||||||
const DEFAULT_SAMPLE_ROWS = 100;
|
const DEFAULT_SAMPLE_ROWS = 100;
|
||||||
|
|
||||||
function _sample(ctx, numRows) {
|
function _sample(ctx) {
|
||||||
if (ctx.metaOptions.sample) {
|
if (!ctx.metaOptions.sample) {
|
||||||
const sampleProb = Math.min(ctx.metaOptions.sample.num_rows / numRows, 1);
|
return Promise.resolve();
|
||||||
// We'll use a safety limit just in case numRows is a bad estimate
|
|
||||||
const requestedRows = ctx.metaOptions.sample.num_rows || DEFAULT_SAMPLE_ROWS;
|
|
||||||
const limit = Math.ceil(requestedRows * 1.5);
|
|
||||||
let columns = ctx.metaOptions.sample.include_columns;
|
|
||||||
return queryUtils.queryPromise(ctx.dbConnection, _getSQL(
|
|
||||||
ctx,
|
|
||||||
sql => queryUtils.getQuerySample(sql, sampleProb, limit, SAMPLE_SEED, columns)
|
|
||||||
)).then(res => ({ sample: res.rows }));
|
|
||||||
}
|
}
|
||||||
return Promise.resolve();
|
|
||||||
|
// We'll use a safety limit just in case numRows is a bad estimate
|
||||||
|
const requestedRows = ctx.metaOptions.sample.num_rows || DEFAULT_SAMPLE_ROWS;
|
||||||
|
const limit = Math.ceil(requestedRows * 1.5);
|
||||||
|
const columns = ctx.metaOptions.sample.include_columns;
|
||||||
|
|
||||||
|
const sqlMaxMin = _getSQL(ctx, sql => queryUtils.getMaxMinColumnQuery(sql));
|
||||||
|
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));
|
||||||
|
|
||||||
|
return queryUtils.queryPromise(ctx.dbConnection, sqlSample);
|
||||||
|
})
|
||||||
|
.then(res => ({ sample: res.rows }));
|
||||||
}
|
}
|
||||||
|
|
||||||
function _columnsMetadataRequired(options) {
|
function _columnsMetadataRequired(options) {
|
||||||
|
Loading…
Reference in New Issue
Block a user