2017-09-06 19:47:19 +08:00
|
|
|
const debug = require('debug')('windshaft:dataview:histogram');
|
2017-09-08 18:48:08 +08:00
|
|
|
const NumericHistogram = require('./numeric-histogram');
|
|
|
|
const DateHistogram = require('./date-histogram');
|
2017-09-06 21:52:13 +08:00
|
|
|
|
|
|
|
const TYPE = 'histogram';
|
2017-09-08 18:48:08 +08:00
|
|
|
const DATE_HISTOGRAM = 'DateHistogram';
|
|
|
|
const NUMERIC_HISTOGRAM = 'NumericHistogram';
|
2017-09-06 21:52:13 +08:00
|
|
|
|
2017-09-08 18:48:08 +08:00
|
|
|
module.exports = class Histogram {
|
2017-09-06 19:43:54 +08:00
|
|
|
constructor (query, options, queries) {
|
2017-09-08 18:48:08 +08:00
|
|
|
switch (this._getHistogramSubtype(options)) {
|
|
|
|
case DATE_HISTOGRAM:
|
|
|
|
debug('Delegating to DateHistogram with options: %j', options)
|
|
|
|
this.dataview = new DateHistogram(query, options, queries);
|
|
|
|
break;
|
|
|
|
case NUMERIC_HISTOGRAM:
|
|
|
|
debug('Delegating to NumericHistogram with options: %j', options)
|
|
|
|
this.dataview = new NumericHistogram(query, options, queries);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
throw new Error('Unsupported Histogram type');
|
2017-09-06 19:43:54 +08:00
|
|
|
}
|
2017-08-01 23:15:45 +08:00
|
|
|
}
|
|
|
|
|
2017-09-08 18:48:08 +08:00
|
|
|
_getHistogramSubtype (options) {
|
|
|
|
if(options.bins && !options.aggregation) {
|
|
|
|
return NUMERIC_HISTOGRAM
|
|
|
|
} else if(options.aggregation && !options.bins) {
|
|
|
|
return DATE_HISTOGRAM
|
2017-09-06 19:43:54 +08:00
|
|
|
}
|
|
|
|
}
|
2017-06-16 18:57:46 +08:00
|
|
|
|
2017-09-08 18:48:08 +08:00
|
|
|
getResult (psql, override, callback) {
|
|
|
|
this.dataview.getResult(psql, override, callback);
|
2017-09-06 21:49:05 +08:00
|
|
|
}
|
2017-09-08 21:53:00 +08:00
|
|
|
|
|
|
|
// In order to keep previous behaviour with overviews,
|
|
|
|
// we have to expose the following methods to bypass
|
|
|
|
// the concrete overview implementation
|
|
|
|
|
|
|
|
sql (psql, override, callback) {
|
|
|
|
this.dataview.sql(psql, override, callback);
|
|
|
|
}
|
|
|
|
|
|
|
|
format (result, override) {
|
|
|
|
return this.dataview.format(result, override);
|
|
|
|
}
|
|
|
|
|
|
|
|
getType () {
|
|
|
|
return this.dataview.getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
toString () {
|
|
|
|
return this.dataview.toString();
|
|
|
|
}
|
2017-09-06 22:14:29 +08:00
|
|
|
};
|