Do not choose histogram implementation until getResult()
This commit is contained in:
@@ -7,31 +7,38 @@ const DATE_HISTOGRAM = 'DateHistogram';
|
||||
const NUMERIC_HISTOGRAM = 'NumericHistogram';
|
||||
|
||||
module.exports = class Histogram {
|
||||
constructor (query, options, queries) {
|
||||
switch (this._getHistogramSubtype(options)) {
|
||||
constructor (query, options = {}, queries) {
|
||||
this.query = query;
|
||||
this.options = options;
|
||||
this.queries = queries;
|
||||
|
||||
this.dataview = this._getHistogramImplemetation();
|
||||
}
|
||||
|
||||
_getHistogramImplemetation (override) {
|
||||
switch (this._getHistogramSubtype(override)) {
|
||||
case DATE_HISTOGRAM:
|
||||
debug('Delegating to DateHistogram with options: %j', options)
|
||||
this.dataview = new DateHistogram(query, options, queries);
|
||||
debug('Delegating to DateHistogram with options: %j and overriding: %j', this.options, override)
|
||||
return new DateHistogram(this.query, this.options, this.queries);
|
||||
break;
|
||||
case NUMERIC_HISTOGRAM:
|
||||
debug('Delegating to NumericHistogram with options: %j', options)
|
||||
this.dataview = new NumericHistogram(query, options, queries);
|
||||
debug('Delegating to NumericHistogram with options: %j and overriding: %j', this.options, override)
|
||||
return new NumericHistogram(this.query, this.options, this.queries);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new Error('Unsupported Histogram type');
|
||||
}
|
||||
}
|
||||
|
||||
_getHistogramSubtype (options) {
|
||||
if(options.bins && !options.aggregation) {
|
||||
return NUMERIC_HISTOGRAM
|
||||
} else if(options.aggregation && !options.bins) {
|
||||
return DATE_HISTOGRAM
|
||||
}
|
||||
|
||||
_getHistogramSubtype (override = {}) {
|
||||
if(this.options.aggregation !== undefined || override.aggregation !== undefined) {
|
||||
return DATE_HISTOGRAM;
|
||||
}
|
||||
return NUMERIC_HISTOGRAM;
|
||||
}
|
||||
|
||||
|
||||
getResult (psql, override, callback) {
|
||||
this.dataview = this._getHistogramImplemetation(override);
|
||||
this.dataview.getResult(psql, override, callback);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user