diff --git a/NEWS.md b/NEWS.md index 6569f3e7..aee22f64 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,8 +1,10 @@ # Changelog -## 4.8.1 -Released 2018-mm-dd +## 5.0.0 +Released 2018-01-29 +Backward incompatible changes: +- Aggregation dataview returns categories with the same type as the database type. For example, if we are aggretating by a numeric field, the resulting JSON will contain a number instead of a stringified number. ## 4.8.0 Released 2018-01-04 diff --git a/lib/cartodb/models/dataview/aggregation.js b/lib/cartodb/models/dataview/aggregation.js index 40774353..d4d1baf5 100644 --- a/lib/cartodb/models/dataview/aggregation.js +++ b/lib/cartodb/models/dataview/aggregation.js @@ -74,7 +74,7 @@ const specialNumericValuesColumns = () => `, nans_count, infinities_count`; const rankedAggregationQueryTpl = ctx => ` SELECT - CAST(category AS text), + category, value, false as agg, nulls_count, @@ -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, @@ -109,7 +109,7 @@ const rankedAggregationQueryTpl = ctx => ` const aggregationQueryTpl = ctx => ` SELECT - CAST(${ctx.column} AS text) AS category, + ${ctx.column} AS category, ${ctx.aggregationFn} AS value, false 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 ? 'Other' : category, + value, + agg + }; + }) }; } diff --git a/package.json b/package.json index e500a253..2ac978e2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "private": true, "name": "windshaft-cartodb", - "version": "4.8.1", + "version": "5.0.0", "description": "A map tile server for CartoDB", "keywords": [ "cartodb"