Add timestamp_start in histogram summary to help to build the histogram in frontend side
This commit is contained in:
parent
21b8655f85
commit
0fffafa1db
@ -215,13 +215,14 @@ var dateHistogramQueryTpl = dot.template([
|
||||
' ) AT TIME ZONE \'{{=it._timezone}}\'',
|
||||
' )',
|
||||
' )::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),
|
||||
_timezone: getTimezone(_timezone, _aggregation)
|
||||
_timezone: parseTimezone(_timezone, _aggregation)
|
||||
});
|
||||
} else {
|
||||
dateBasicsQuery = dateBasicsQueryTpl({
|
||||
_query: _query,
|
||||
_column: _column,
|
||||
_aggregation: _aggregation,
|
||||
_timezone: getTimezone(_timezone, _aggregation)
|
||||
_timezone: parseTimezone(_timezone, _aggregation)
|
||||
});
|
||||
}
|
||||
|
||||
@ -429,7 +430,7 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
|
||||
_query: _query,
|
||||
_column: _column,
|
||||
_aggregation: _aggregation,
|
||||
_timezone: getTimezone(_timezone, _aggregation)
|
||||
_timezone: parseTimezone(_timezone, _aggregation)
|
||||
});
|
||||
|
||||
var histogramSql = [
|
||||
@ -492,12 +493,13 @@ Histogram.prototype.format = function(result, override) {
|
||||
var buckets = [];
|
||||
|
||||
var aggregation = getAggregation(override, this.aggregation);
|
||||
var timezone = getTimezoneParam(override, this.timezone);
|
||||
var timezone = getTimezone(override, this.timezone);
|
||||
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,
|
||||
timezone: timezone,
|
||||
timestamp_start: timestampStart,
|
||||
bin_width: width,
|
||||
bins_count: binsCount,
|
||||
bins_start: binsStart,
|
||||
@ -528,13 +531,15 @@ function getAggregation(override, aggregation) {
|
||||
return override && override.aggregation ? override.aggregation : aggregation;
|
||||
}
|
||||
|
||||
function getTimezoneParam(override, timezone) {
|
||||
function getTimezone(override, timezone) {
|
||||
if (override && override.timezone) {
|
||||
return override.timezone;
|
||||
}
|
||||
|
||||
if (timezone) {
|
||||
return timezone;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -567,7 +572,7 @@ function getWidth(override) {
|
||||
return width;
|
||||
}
|
||||
|
||||
function getTimezone(timezone, aggregation) {
|
||||
function parseTimezone(timezone, aggregation) {
|
||||
if (!timezone) {
|
||||
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,
|
||||
timezone: 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,
|
||||
timezone: -3600,
|
||||
bins:
|
||||
|
Loading…
Reference in New Issue
Block a user