Merge branch '691-date-histogram' into 691-date-histogram-offset
This commit is contained in:
commit
e30b883906
@ -215,13 +215,14 @@ var dateHistogramQueryTpl = dot.template([
|
||||
' ) AT TIME ZONE \'{{=it._offset}}\'',
|
||||
' )',
|
||||
' )::numeric AS timestamp,',
|
||||
' date_part(\'epoch\', start_date)::numeric AS timestamp_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'));
|
||||
|
||||
@ -403,14 +404,14 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
|
||||
_aggregation: _aggregation,
|
||||
_start: getBinStart(override),
|
||||
_end: getBinEnd(override),
|
||||
_offset: getOffset(_offset, _aggregation)
|
||||
_offset: parseOffset(_offset, _aggregation)
|
||||
});
|
||||
} else {
|
||||
dateBasicsQuery = dateBasicsQueryTpl({
|
||||
_query: _query,
|
||||
_column: _column,
|
||||
_aggregation: _aggregation,
|
||||
_offset: getOffset(_offset, _aggregation)
|
||||
_offset: parseOffset(_offset, _aggregation)
|
||||
});
|
||||
}
|
||||
|
||||
@ -429,7 +430,7 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
|
||||
_query: _query,
|
||||
_column: _column,
|
||||
_aggregation: _aggregation,
|
||||
_offset: getOffset(_offset, _aggregation)
|
||||
_offset: parseOffset(_offset, _aggregation)
|
||||
});
|
||||
|
||||
var histogramSql = [
|
||||
@ -492,12 +493,13 @@ Histogram.prototype.format = function(result, override) {
|
||||
var buckets = [];
|
||||
|
||||
var aggregation = getAggregation(override, this.aggregation);
|
||||
var offset = getOffsetParam(override, this.offset);
|
||||
var offset = getOffset(override, this.offset);
|
||||
var binsCount = getBinsCount(override);
|
||||
var width = getWidth(override);
|
||||
var binsStart = getBinStart(override);
|
||||
var nulls = 0;
|
||||
var avg;
|
||||
var timestampStart;
|
||||
|
||||
if (result.rows.length) {
|
||||
var firstRow = result.rows[0];
|
||||
@ -506,15 +508,16 @@ Histogram.prototype.format = function(result, override) {
|
||||
avg = firstRow.avg_val;
|
||||
nulls = firstRow.nulls_count;
|
||||
binsStart = populateBinStart(override, firstRow);
|
||||
|
||||
timestampStart = firstRow.timestamp_start;
|
||||
buckets = result.rows.map(function(row) {
|
||||
return _.omit(row, 'bins_number', 'bin_width', 'nulls_count', 'avg_val');
|
||||
return _.omit(row, 'bins_number', 'bin_width', 'nulls_count', 'avg_val', 'timestamp_start');
|
||||
});
|
||||
}
|
||||
|
||||
return {
|
||||
aggregation: aggregation,
|
||||
offset: offset,
|
||||
timestamp_start: timestampStart,
|
||||
bin_width: width,
|
||||
bins_count: binsCount,
|
||||
bins_start: binsStart,
|
||||
@ -528,13 +531,14 @@ function getAggregation(override, aggregation) {
|
||||
return override && override.aggregation ? override.aggregation : aggregation;
|
||||
}
|
||||
|
||||
function getOffsetParam(override, offset) {
|
||||
function getOffset(override, offset) {
|
||||
if (override && override.offset) {
|
||||
return override.offset;
|
||||
}
|
||||
if (offset) {
|
||||
return offset;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -567,11 +571,10 @@ function getWidth(override) {
|
||||
return width;
|
||||
}
|
||||
|
||||
function getOffset(offset, aggregation) {
|
||||
function parseOffset(offset, aggregation) {
|
||||
if (!offset) {
|
||||
return '0';
|
||||
}
|
||||
|
||||
if (aggregation === 'hour' || aggregation === 'minute') {
|
||||
return '0';
|
||||
}
|
||||
|
@ -618,6 +618,7 @@ describe('histogram-dataview for date column type', function() {
|
||||
bin_width: 600,
|
||||
bins_count: 2,
|
||||
bins_start: 1171497600,
|
||||
timestamp_start: 1171497600,
|
||||
offset: 0,
|
||||
nulls: 0,
|
||||
bins:
|
||||
@ -664,6 +665,7 @@ describe('histogram-dataview for date column type', function() {
|
||||
bin_width: 1200,
|
||||
bins_count: 1,
|
||||
bins_start: 1171501200,
|
||||
timestamp_start: 1171497600,
|
||||
nulls: 0,
|
||||
offset: -3600,
|
||||
bins:
|
||||
|
Loading…
Reference in New Issue
Block a user