From d726c9ad013d072b03c6eea0d42ed68a7c0deaff Mon Sep 17 00:00:00 2001 From: Javier Goizueta Date: Fri, 22 Dec 2017 15:48:30 +0100 Subject: [PATCH] Fix point-sample aggregation it failed in the case of aggregate columns with the name of base columns --- lib/cartodb/models/aggregation/aggregation-query.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 5ecf09aa..965d201f 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -98,8 +98,13 @@ const aggregateColumns = ctx => { }, ctx.columns || {}); }; -const aggregateColumnNames = ctx => { +const aggregateColumnNames = (ctx, table) => { let columns = aggregateColumns(ctx); + if (table) { + return sep(Object.keys(columns).map( + column_name => `${table}.${column_name}` + )); + } return sep(Object.keys(columns)); }; @@ -120,13 +125,13 @@ const aggregateColumnDefs = ctx => { const aggregateDimensions = ctx => ctx.dimensions || {}; const dimensionNames = (ctx, table) => { + let dimensions = aggregateDimensions(ctx); if (table) { - let dimensions = aggregateDimensions(ctx); return sep(Object.keys(dimensions).map( dimension_name => `${table}.${dimension_name}` )); } - return sep(Object.keys(aggregateDimensions(ctx))); + return sep(Object.keys(dimensions)); }; const dimensionDefs = ctx => { @@ -250,7 +255,7 @@ const aggregationQueryTemplates = { _cdb_clusters.cartodb_id, the_geom, the_geom_webmercator ${dimensionNames(ctx, '_cdb_query')} - ${aggregateColumnNames(ctx)} + ${aggregateColumnNames(ctx, '_cdb_clusters')} FROM _cdb_clusters INNER JOIN (${ctx.sourceQuery}) _cdb_query ON (_cdb_clusters.cartodb_id = _cdb_query.cartodb_id)