Add timestamp_start in histogram summary to help to build the histogram in frontend side

This commit is contained in:
Daniel García Aubert 2017-07-14 18:22:05 +02:00
parent 21b8655f85
commit 0fffafa1db
2 changed files with 16 additions and 9 deletions

View File

@ -215,13 +215,14 @@ var dateHistogramQueryTpl = dot.template([
' ) AT TIME ZONE \'{{=it._timezone}}\'', ' ) AT TIME ZONE \'{{=it._timezone}}\'',
' )', ' )',
' )::numeric AS timestamp,', ' )::numeric AS timestamp,',
' date_part(\'epoch\', start_date)::numeric AS timestamp_start,',
' min(date_part(\'epoch\', {{=it._column}}))::numeric AS min,', ' min(date_part(\'epoch\', {{=it._column}}))::numeric AS min,',
' max(date_part(\'epoch\', {{=it._column}}))::numeric AS max,', ' max(date_part(\'epoch\', {{=it._column}}))::numeric AS max,',
' avg(date_part(\'epoch\', {{=it._column}}))::numeric AS avg,', ' avg(date_part(\'epoch\', {{=it._column}}))::numeric AS avg,',
' count(*) AS freq', ' count(*) AS freq',
'FROM ({{=it._query}}) _cdb_histogram, basics, bins, nulls', 'FROM ({{=it._query}}) _cdb_histogram, basics, bins, nulls',
'WHERE date_part(\'epoch\', {{=it._column}}) IS NOT NULL', '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' 'ORDER BY bin'
].join('\n')); ].join('\n'));
@ -403,14 +404,14 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
_aggregation: _aggregation, _aggregation: _aggregation,
_start: getBinStart(override), _start: getBinStart(override),
_end: getBinEnd(override), _end: getBinEnd(override),
_timezone: getTimezone(_timezone, _aggregation) _timezone: parseTimezone(_timezone, _aggregation)
}); });
} else { } else {
dateBasicsQuery = dateBasicsQueryTpl({ dateBasicsQuery = dateBasicsQueryTpl({
_query: _query, _query: _query,
_column: _column, _column: _column,
_aggregation: _aggregation, _aggregation: _aggregation,
_timezone: getTimezone(_timezone, _aggregation) _timezone: parseTimezone(_timezone, _aggregation)
}); });
} }
@ -429,7 +430,7 @@ Histogram.prototype._buildDateHistogramQuery = function (psql, override, callbac
_query: _query, _query: _query,
_column: _column, _column: _column,
_aggregation: _aggregation, _aggregation: _aggregation,
_timezone: getTimezone(_timezone, _aggregation) _timezone: parseTimezone(_timezone, _aggregation)
}); });
var histogramSql = [ var histogramSql = [
@ -492,12 +493,13 @@ Histogram.prototype.format = function(result, override) {
var buckets = []; var buckets = [];
var aggregation = getAggregation(override, this.aggregation); var aggregation = getAggregation(override, this.aggregation);
var timezone = getTimezoneParam(override, this.timezone); var timezone = getTimezone(override, this.timezone);
var binsCount = getBinsCount(override); var binsCount = getBinsCount(override);
var width = getWidth(override); var width = getWidth(override);
var binsStart = getBinStart(override); var binsStart = getBinStart(override);
var nulls = 0; var nulls = 0;
var avg; var avg;
var timestampStart;
if (result.rows.length) { if (result.rows.length) {
var firstRow = result.rows[0]; var firstRow = result.rows[0];
@ -506,15 +508,16 @@ Histogram.prototype.format = function(result, override) {
avg = firstRow.avg_val; avg = firstRow.avg_val;
nulls = firstRow.nulls_count; nulls = firstRow.nulls_count;
binsStart = populateBinStart(override, firstRow); binsStart = populateBinStart(override, firstRow);
timestampStart = firstRow.timestamp_start;
buckets = result.rows.map(function(row) { 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 { return {
aggregation: aggregation, aggregation: aggregation,
timezone: timezone, timezone: timezone,
timestamp_start: timestampStart,
bin_width: width, bin_width: width,
bins_count: binsCount, bins_count: binsCount,
bins_start: binsStart, bins_start: binsStart,
@ -528,13 +531,15 @@ function getAggregation(override, aggregation) {
return override && override.aggregation ? override.aggregation : aggregation; return override && override.aggregation ? override.aggregation : aggregation;
} }
function getTimezoneParam(override, timezone) { function getTimezone(override, timezone) {
if (override && override.timezone) { if (override && override.timezone) {
return override.timezone; return override.timezone;
} }
if (timezone) { if (timezone) {
return timezone; return timezone;
} }
return 0; return 0;
} }
@ -567,7 +572,7 @@ function getWidth(override) {
return width; return width;
} }
function getTimezone(timezone, aggregation) { function parseTimezone(timezone, aggregation) {
if (!timezone) { if (!timezone) {
return '0'; return '0';
} }

View File

@ -618,6 +618,7 @@ describe('histogram-dataview for date column type', function() {
bin_width: 600, bin_width: 600,
bins_count: 2, bins_count: 2,
bins_start: 1171497600, bins_start: 1171497600,
timestamp_start: 1171497600,
timezone: 0, timezone: 0,
nulls: 0, nulls: 0,
bins: bins:
@ -664,6 +665,7 @@ describe('histogram-dataview for date column type', function() {
bin_width: 1200, bin_width: 1200,
bins_count: 1, bins_count: 1,
bins_start: 1171501200, bins_start: 1171501200,
timestamp_start: 1171497600,
nulls: 0, nulls: 0,
timezone: -3600, timezone: -3600,
bins: bins: