Fix point-sample aggregation

it failed in  the case of aggregate columns with the name of base columns
This commit is contained in:
Javier Goizueta 2017-12-22 15:48:30 +01:00
parent 1ce8076699
commit d726c9ad01

View File

@ -98,8 +98,13 @@ const aggregateColumns = ctx => {
}, ctx.columns || {}); }, ctx.columns || {});
}; };
const aggregateColumnNames = ctx => { const aggregateColumnNames = (ctx, table) => {
let columns = aggregateColumns(ctx); let columns = aggregateColumns(ctx);
if (table) {
return sep(Object.keys(columns).map(
column_name => `${table}.${column_name}`
));
}
return sep(Object.keys(columns)); return sep(Object.keys(columns));
}; };
@ -120,13 +125,13 @@ const aggregateColumnDefs = ctx => {
const aggregateDimensions = ctx => ctx.dimensions || {}; const aggregateDimensions = ctx => ctx.dimensions || {};
const dimensionNames = (ctx, table) => { const dimensionNames = (ctx, table) => {
let dimensions = aggregateDimensions(ctx);
if (table) { if (table) {
let dimensions = aggregateDimensions(ctx);
return sep(Object.keys(dimensions).map( return sep(Object.keys(dimensions).map(
dimension_name => `${table}.${dimension_name}` dimension_name => `${table}.${dimension_name}`
)); ));
} }
return sep(Object.keys(aggregateDimensions(ctx))); return sep(Object.keys(dimensions));
}; };
const dimensionDefs = ctx => { const dimensionDefs = ctx => {
@ -250,7 +255,7 @@ const aggregationQueryTemplates = {
_cdb_clusters.cartodb_id, _cdb_clusters.cartodb_id,
the_geom, the_geom_webmercator the_geom, the_geom_webmercator
${dimensionNames(ctx, '_cdb_query')} ${dimensionNames(ctx, '_cdb_query')}
${aggregateColumnNames(ctx)} ${aggregateColumnNames(ctx, '_cdb_clusters')}
FROM FROM
_cdb_clusters INNER JOIN (${ctx.sourceQuery}) _cdb_query _cdb_clusters INNER JOIN (${ctx.sourceQuery}) _cdb_query
ON (_cdb_clusters.cartodb_id = _cdb_query.cartodb_id) ON (_cdb_clusters.cartodb_id = _cdb_query.cartodb_id)