From 99421b613c106b916adf5efa4aac06ffe56db657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20Mart=C3=ADn?= Date: Fri, 26 Jan 2018 15:24:21 +0100 Subject: [PATCH] moving 'other' outside of the query allowing queries of different types --- lib/cartodb/models/dataview/aggregation.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/cartodb/models/dataview/aggregation.js b/lib/cartodb/models/dataview/aggregation.js index 9b5d62ef..dbdb4277 100644 --- a/lib/cartodb/models/dataview/aggregation.js +++ b/lib/cartodb/models/dataview/aggregation.js @@ -87,7 +87,7 @@ const rankedAggregationQueryTpl = ctx => ` WHERE rank < ${ctx.limit} UNION ALL SELECT - 'Other' category, + null category, ${ctx.aggregation !== 'count' ? ctx.aggregation : 'sum'}(value) as value, true as agg, nulls_count, @@ -282,7 +282,7 @@ module.exports = class Aggregation extends BaseDataview { max_val = 0, categories_count = 0 } = result.rows[0] || {}; - + return { aggregation: this.aggregation, count: count, @@ -292,7 +292,13 @@ module.exports = class Aggregation extends BaseDataview { min: min_val, max: max_val, categoriesCount: categories_count, - categories: result.rows.map(({ category, value, agg }) => ({ category, value, agg })) + categories: result.rows.map(({ category, value, agg }) => { + return { + category: agg ? 'Others' : category, + value, + agg + }; + }) }; }