From d1696425fd724e28d04f96c84b9a18d05d01624f Mon Sep 17 00:00:00 2001 From: manmorjim Date: Fri, 10 Apr 2020 14:09:44 +0200 Subject: [PATCH 1/3] Prevent using cast column from alias `__ctx_query` Fixes #1160 by keep the original name of the column and using it if the column type is date. --- lib/models/dataview/histograms/numeric-histogram.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/models/dataview/histograms/numeric-histogram.js b/lib/models/dataview/histograms/numeric-histogram.js index 6f17b59b..858531ad 100644 --- a/lib/models/dataview/histograms/numeric-histogram.js +++ b/lib/models/dataview/histograms/numeric-histogram.js @@ -52,10 +52,18 @@ Numeric histogram: */ module.exports = class NumericHistogram extends BaseHistogram { _buildQuery (psql, override, callback) { + let column = this.column; + let query = this.query; + // for date type we have to cast the column using an alias + // and using that alias to prevent multiple calls to the cast + if (this._columnType === 'date') { + query = `(SELECT *, ${utils.columnCastTpl({ column })} as __cdb_cast_date FROM (${this.query}) __cdb_original_query)`; + column = '__cdb_cast_date'; + } const histogramSql = this._buildQueryTpl({ - column: this._columnType === 'date' ? utils.columnCastTpl({ column: this.column }) : this.column, + column, isFloatColumn: this._columnType === 'float', - query: this.query, + query, start: this._getBinStart(override), end: this._getBinEnd(override), bins: this._getBinsCount(override), From 7237fb04a8d5b9187ed44f1e8f6cc034c2074153 Mon Sep 17 00:00:00 2001 From: manmorjim Date: Fri, 10 Apr 2020 14:33:38 +0200 Subject: [PATCH 2/3] Adding test for column date type in numeric histograms --- test/acceptance/dataviews/histogram-test.js | 24 +++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/acceptance/dataviews/histogram-test.js b/test/acceptance/dataviews/histogram-test.js index a78c0de7..ac59a848 100644 --- a/test/acceptance/dataviews/histogram-test.js +++ b/test/acceptance/dataviews/histogram-test.js @@ -325,6 +325,15 @@ describe('histogram-dataview for date column type', function () { column: 'd', aggregation: 'minute' } + }, + date_histogram_no_agg: { + options: { + column: 'd' + }, + source: { + id: 'minute-histogram-source-tz' + }, + type: 'histogram' } }, [ @@ -1232,6 +1241,21 @@ describe('histogram-dataview for date column type', function () { done(); }); }); + + it('should work with dates without aggregation', function (done) { + var params = { + start: 1171583400, + end: 1171584600 + }; + this.testClient = new TestClient(mapConfig, 1234); + this.testClient.getDataview('date_histogram_no_agg', params, function (err, dataview) { + assert.ifError(err); + assert.strictEqual(dataview.type, 'histogram'); + assert.strictEqual(dataview.bins.length, 6); + assert.strictEqual(dataview.bins_count, 6); + done(); + }); + }); }); describe('histogram-dataview: special float valuer', function () { From 5ac27d10021238effee12610ba5ee0ce7cf092d0 Mon Sep 17 00:00:00 2001 From: manmorjim Date: Fri, 10 Apr 2020 14:34:02 +0200 Subject: [PATCH 3/3] Update NEWS --- NEWS.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NEWS.md b/NEWS.md index 3b07a9cf..29e94124 100644 --- a/NEWS.md +++ b/NEWS.md @@ -21,6 +21,9 @@ Announcements: - Remove `bootstrapFonts` at process startup (now done in `windshaft@6.0.0`) - Stop checking the installed version of some dependencies while testing +Bug Fixes: +- Parsing date column in numeric histograms (#1160) + ## 8.1.1 Released 2020-02-17