diff --git a/lib/cartodb/models/aggregation/aggregation-query.js b/lib/cartodb/models/aggregation/aggregation-query.js index 866f1eb0..6fd416c5 100644 --- a/lib/cartodb/models/aggregation/aggregation-query.js +++ b/lib/cartodb/models/aggregation/aggregation-query.js @@ -4,31 +4,6 @@ const timeDimension = require('./time-dimension'); const DEFAULT_PLACEMENT = 'point-sample'; - -/** - * Returns a template function (function that accepts template parameters and returns a string) - * to generate an aggregation query. - * Valid options to define the query template are: - * - placement - * - columns - * - dimensions* - * The query template parameters taken by the result template function are: - * - sourceQuery - * - res - * - columns - * - dimensions - */ -const templateForOptions = (options) => { - let templateFn = defaultAggregationQueryTemplate; - if (!options.isDefaultAggregation) { - templateFn = aggregationQueryTemplates[options.placement || DEFAULT_PLACEMENT]; - if (!templateFn) { - throw new Error("Invalid Aggregation placement: '" + options.placement + "'"); - } - } - return templateFn; -}; - function optionsToParams (options) { return { sourceQuery: options.query, @@ -55,7 +30,7 @@ function optionsToParams (options) { * When placement, columns or dimensions are specified, columns are aggregated as requested * (by default only _cdb_feature_count) and with the_geom_webmercator as defined by placement. */ -const queryForOptions = (options) => templateForOptions(options)(optionsToParams(options)); +const queryForOptions = (options) => aggregationQueryTemplate(optionsToParams(options)); module.exports = queryForOptions; @@ -398,7 +373,7 @@ const aggregatedPosCoordinate = (ctx, coordinate) => { }; -const defaultAggregationQueryTemplate = ctx => ` +const aggregationQueryTemplate = ctx => ` WITH __cdb_grid_params AS ( ${gridInfoQuery(ctx)} @@ -437,14 +412,7 @@ SELECT * FROM ${aggregatedPointJoin(ctx)} `; -const aggregationQueryTemplates = { - 'centroid': defaultAggregationQueryTemplate, - 'point-grid': defaultAggregationQueryTemplate, - 'point-sample': defaultAggregationQueryTemplate - -}; - -module.exports.SUPPORTED_PLACEMENTS = Object.keys(aggregationQueryTemplates); +module.exports.SUPPORTED_PLACEMENTS = ['centroid', 'point-grid', 'point-sample']; module.exports.GEOMETRY_COLUMN = 'the_geom_webmercator'; const clusterFeaturesQuery = ctx => `