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.
This commit is contained in:
manmorjim 2020-04-10 14:09:44 +02:00
parent a614fb1ef6
commit d1696425fd

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),