From e247e45f9644272c134e64562de1f958a8237601 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Thu, 5 Jul 2018 17:21:35 +0200 Subject: [PATCH] Qualify columns and improve if/else style As suggested by Algunenano: qualify column names with the table/subquery/cte to avoid name clashing, and polish the code style a little. --- .../models/dataview/histograms/numeric-histogram.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/cartodb/models/dataview/histograms/numeric-histogram.js b/lib/cartodb/models/dataview/histograms/numeric-histogram.js index 2538fa54..f26a0f80 100644 --- a/lib/cartodb/models/dataview/histograms/numeric-histogram.js +++ b/lib/cartodb/models/dataview/histograms/numeric-histogram.js @@ -101,14 +101,17 @@ module.exports = class NumericHistogram extends BaseHistogram { var extra_groupby = ``; var extra_filter = ``; - if (ctx.start >= ctx.end) { + if (ctx.start < ctx.end) { + extra_filter = ` + WHERE __ctx_query.${ctx.column} >= ${ctx.start} + AND __ctx_query.${ctx.column} <= ${ctx.end} + `; + } else { ctx.end = `__cdb_basics.__cdb_max_val`; ctx.start = `__cdb_basics.__cdb_min_val`; extra_groupby = `, __cdb_basics.__cdb_max_val, __cdb_basics.__cdb_min_val`; extra_tables = `, __cdb_basics`; extra_queries = `WITH ${irqQueryTpl(ctx)}`; - } else { - extra_filter = `WHERE ${ctx.column} >= ${ctx.start} AND ${ctx.column} <= ${ctx.end}`; } if (ctx.bins <= 0) {