diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 84216e91..7cdbe265 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -197,31 +197,36 @@ const timeDimensionParameters = definition => { }; }; -const dimensionExpression = definition => { +// Adapt old-style dimension definitions for backwards compatibility +const adaptDimensionDefinition = definition => { if (typeof(definition) === 'string') { - return `"definition"`; + return { column: definition } + } + return definition; +}; + +const dimensionExpression = definition => { + if (definition.group_by) { + // Currently only time dimensions are supported with parameters + return timeDimension(timeDimensionParameters(definition)); + } else { + return `"${definition.column}"`; } - // Currently only time dimensions are supported with parameters - return timeDimension(timeDimensionParameters(definition)); }; const dimensionNames = (ctx, table) => { let dimensions = aggregateDimensions(ctx); - if (table) { - return sep(Object.keys(dimensions).map( - dimension_name => `${table}."${dimension_name}"` - )); - } - return sep(Object.keys(dimensions).map(dimension_name => { - return `"${dimension_name}"`; + return sep(Object.keys(dimensions).map(dimensionName => { + return table ? `${table}."${dimensionName}"` : `"${dimensionName}"`; })); }; const dimensionDefs = ctx => { let dimensions = aggregateDimensions(ctx); - return sep(Object.keys(dimensions).map(dimension_name => { - const expression = dimensionExpression(dimensions[dimension_name]); - return `${expression} AS "${dimension_name}"`; + return sep(Object.keys(dimensions).map(dimensionName => { + const dimension = adaptDimensionDefinition(dimensions[dimensionName]); + const expression = dimensionExpression(dimension); + return `${expression} AS "${dimensionName}"`; })); };