Be able to accept timezone parameter
This commit is contained in:
parent
6374d2e4b6
commit
c1fac13d6b
@ -80,7 +80,7 @@ DataviewBackend.prototype.getDataview = function (mapConfigProvider, user, param
|
||||
overviewsQueryRewriter, queryRewriteData, { bbox: params.bbox }
|
||||
);
|
||||
|
||||
var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins'),
|
||||
var overrideParams = _.reduce(_.pick(params, 'start', 'end', 'bins', 'timezone'),
|
||||
function castNumbers(overrides, val, k) {
|
||||
if (!Number.isFinite(+val)) {
|
||||
throw new Error('Invalid number format for parameter \'' + k + '\'');
|
||||
|
@ -26,6 +26,7 @@ var REQUEST_QUERY_PARAMS_WHITELIST = [
|
||||
'end', // number
|
||||
'column_type', // string
|
||||
'aggregation', //string
|
||||
'timezone', // number
|
||||
// widgets search
|
||||
'q'
|
||||
];
|
||||
|
@ -110,15 +110,6 @@ var dateBasicsQueryTpl = dot.template([
|
||||
')'
|
||||
].join(' \n'));
|
||||
|
||||
var overrideBasicsQueryTpl = dot.template([
|
||||
'basics AS (',
|
||||
' SELECT',
|
||||
' max({{=it._end}}) AS max_val, min({{=it._start}}) AS min_val,',
|
||||
' avg({{=it._column}}) AS avg_val, count(1) AS total_rows',
|
||||
' FROM ({{=it._query}}) _cdb_basics',
|
||||
')'
|
||||
].join('\n'));
|
||||
|
||||
var dateOverrideBasicsQueryTpl = dot.template([
|
||||
'basics AS (',
|
||||
' SELECT',
|
||||
@ -156,13 +147,14 @@ var dateHistogramQueryTpl = dot.template([
|
||||
' THEN 0',
|
||||
' ELSE GREATEST(1, LEAST(WIDTH_BUCKET({{=it._column}}, bins_array), bins_number)) - 1',
|
||||
' END AS bin,',
|
||||
' date_part(\'epoch\', start_date)::numeric AS bin_start,',
|
||||
' min(date_part(\'epoch\', {{=it._column}}))::numeric AS min,',
|
||||
' max(date_part(\'epoch\', {{=it._column}}))::numeric AS max,',
|
||||
' avg(date_part(\'epoch\', {{=it._column}}))::numeric AS avg,',
|
||||
' count(*) AS freq',
|
||||
'FROM ({{=it._query}}) _cdb_histogram, basics, bins, nulls',
|
||||
'WHERE date_part(\'epoch\', {{=it._column}}) IS NOT NULL',
|
||||
'GROUP BY bin, bins_number, bin_width, nulls_count, avg_val',
|
||||
'GROUP BY bin, bins_number, bin_width, nulls_count, avg_val, start_date',
|
||||
'ORDER BY bin'
|
||||
].join('\n'));
|
||||
|
||||
@ -187,6 +179,7 @@ function Histogram(query, options, queries) {
|
||||
this.column = options.column;
|
||||
this.bins = options.bins;
|
||||
this.aggregation = options.aggregation;
|
||||
this.timezone = options.timezone;
|
||||
|
||||
this._columnType = null;
|
||||
}
|
||||
|
@ -204,4 +204,22 @@ describe('histogram-dataview for date column type', function() {
|
||||
});
|
||||
});
|
||||
|
||||
it.skip('should aggregate respecting timezone', function (done) {
|
||||
var params = {
|
||||
timezone: -7200 // GMT -2h
|
||||
};
|
||||
|
||||
this.testClient = new TestClient(mapConfig, 1234);
|
||||
this.testClient.getDataview('date_histogram', params, function(err, dataview) {
|
||||
assert.ok(!err, err);
|
||||
assert.equal(dataview.type, 'histogram');
|
||||
assert.ok(dataview.bin_width > 0, 'Unexpected bin width: ' + dataview.bin_width);
|
||||
assert.equal(dataview.bins.length, 5);
|
||||
dataview.bins.forEach(function(bin) {
|
||||
assert.ok(bin.min <= bin.max, 'bin min < bin max: ' + JSON.stringify(bin));
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -369,7 +369,7 @@ TestClient.prototype.getDataview = function(dataviewName, params, callback) {
|
||||
own_filter: params.hasOwnProperty('own_filter') ? params.own_filter : 1
|
||||
};
|
||||
|
||||
['bbox', 'bins', 'start', 'end', 'aggregation'].forEach(function(extraParam) {
|
||||
['bbox', 'bins', 'start', 'end', 'aggregation', 'timezone'].forEach(function(extraParam) {
|
||||
if (params.hasOwnProperty(extraParam)) {
|
||||
urlParams[extraParam] = params[extraParam];
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user