Merge pull request #1161 from CartoDB/fix_parsing_columns_histograms_1160

Fixes 1160: Prevent using cast column as part of __ctx_query
This commit is contained in:
Manuel J. Morillo 2020-04-23 13:12:32 +02:00 committed by GitHub
commit 809c267419
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View File

@ -21,6 +21,9 @@ Announcements:
- Remove `bootstrapFonts` at process startup (now done in `windshaft@6.0.0`) - Remove `bootstrapFonts` at process startup (now done in `windshaft@6.0.0`)
- Stop checking the installed version of some dependencies while testing - Stop checking the installed version of some dependencies while testing
Bug Fixes:
- Parsing date column in numeric histograms (#1160)
## 8.1.1 ## 8.1.1
Released 2020-02-17 Released 2020-02-17

View File

@ -52,10 +52,18 @@ Numeric histogram:
*/ */
module.exports = class NumericHistogram extends BaseHistogram { module.exports = class NumericHistogram extends BaseHistogram {
_buildQuery (psql, override, callback) { _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({ const histogramSql = this._buildQueryTpl({
column: this._columnType === 'date' ? utils.columnCastTpl({ column: this.column }) : this.column, column,
isFloatColumn: this._columnType === 'float', isFloatColumn: this._columnType === 'float',
query: this.query, query,
start: this._getBinStart(override), start: this._getBinStart(override),
end: this._getBinEnd(override), end: this._getBinEnd(override),
bins: this._getBinsCount(override), bins: this._getBinsCount(override),

View File

@ -325,6 +325,15 @@ describe('histogram-dataview for date column type', function () {
column: 'd', column: 'd',
aggregation: 'minute' 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(); 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 () { describe('histogram-dataview: special float valuer', function () {