Please jshint
This commit is contained in:
parent
aed456bf32
commit
46600bf4fc
@ -108,16 +108,6 @@ const aggregateColumns = ctx => {
|
|||||||
}, ctx.columns || {});
|
}, ctx.columns || {});
|
||||||
};
|
};
|
||||||
|
|
||||||
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));
|
|
||||||
};
|
|
||||||
|
|
||||||
const aggregateExpression = (column_name, column_parameters) => {
|
const aggregateExpression = (column_name, column_parameters) => {
|
||||||
const aggregate_function = column_parameters.aggregate_function || 'count';
|
const aggregate_function = column_parameters.aggregate_function || 'count';
|
||||||
const aggregate_definition = SUPPORTED_AGGREGATE_FUNCTIONS[aggregate_function];
|
const aggregate_definition = SUPPORTED_AGGREGATE_FUNCTIONS[aggregate_function];
|
||||||
@ -342,29 +332,41 @@ const gridInfoQuery = ctx => {
|
|||||||
|
|
||||||
|
|
||||||
// Function to generate the resulting point for a cell from the aggregated data
|
// Function to generate the resulting point for a cell from the aggregated data
|
||||||
// Point sample joins the query with itself to get the data from the lowest id
|
const aggregatedPointWebMercator = (ctx) => {
|
||||||
const aggregatedPoint = (ctx, aggregated) => {
|
switch (ctx.placement) {
|
||||||
const placement = ctx.placement || DEFAULT_PLACEMENT;
|
|
||||||
switch (placement) {
|
|
||||||
|
|
||||||
// For centroid, we return the average of the cell
|
// For centroid, we return the average of the cell
|
||||||
case `centroid`:
|
case `centroid`:
|
||||||
return aggregated ?
|
return `, ST_SetSRID(ST_MakePoint(AVG(cdb_x), AVG(cdb_y)), 3857) AS the_geom_webmercator`;
|
||||||
`, ST_SetSRID(ST_MakePoint(AVG(cdb_x), AVG(cdb_y)), 3857) AS the_geom_webmercator` :
|
|
||||||
``;
|
|
||||||
|
|
||||||
// Middle point of the cell
|
// Middle point of the cell
|
||||||
case `point-grid`:
|
case `point-grid`:
|
||||||
return aggregated ?
|
return `, ST_SetSRID(ST_MakePoint(cdb_pos_grid_x, cdb_pos_grid_y), 3857) AS the_geom_webmercator`;
|
||||||
`, ST_SetSRID(ST_MakePoint(cdb_pos_grid_x, cdb_pos_grid_y), 3857) AS the_geom_webmercator`:
|
|
||||||
``;
|
|
||||||
|
|
||||||
// For point-sample we'll get a single point directly from the source
|
// For point-sample we'll get a single point directly from the source
|
||||||
// If it's default aggregation we'll add the extra columns to keep backwards compatibility
|
// If it's default aggregation we'll add the extra columns to keep backwards compatibility
|
||||||
case `point-sample`:
|
case `point-sample`:
|
||||||
return aggregated ?
|
return ``;
|
||||||
`` :
|
|
||||||
`NATURAL JOIN
|
default:
|
||||||
|
throw new Error(`Invalid aggregation placement "${ctx.placement}`);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// Function to generate the resulting point for a cell from the a join with the source
|
||||||
|
const aggregatedPointJoin = (ctx) => {
|
||||||
|
switch (ctx.placement) {
|
||||||
|
|
||||||
|
case `centroid`:
|
||||||
|
return ``;
|
||||||
|
|
||||||
|
case `point-grid`:
|
||||||
|
return ``;
|
||||||
|
|
||||||
|
// For point-sample we'll get a single point directly from the source
|
||||||
|
// If it's default aggregation we'll add the extra columns to keep backwards compatibility
|
||||||
|
case `point-sample`:
|
||||||
|
return `NATURAL JOIN
|
||||||
(
|
(
|
||||||
SELECT ${ctx.isDefaultAggregation ? `*` : `cartodb_id, the_geom_webmercator`}
|
SELECT ${ctx.isDefaultAggregation ? `*` : `cartodb_id, the_geom_webmercator`}
|
||||||
FROM
|
FROM
|
||||||
@ -375,7 +377,7 @@ const aggregatedPoint = (ctx, aggregated) => {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new Error(`Invalid aggregation placement "${placement}`);
|
throw new Error(`Invalid aggregation placement "${ctx.placement}`);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -384,8 +386,7 @@ const aggregatedPoint = (ctx, aggregated) => {
|
|||||||
// get the coordinates of the mid point so we don't need to calculate them later
|
// get the coordinates of the mid point so we don't need to calculate them later
|
||||||
// which requires extra data in the group by clause
|
// which requires extra data in the group by clause
|
||||||
const aggregatedPosCoordinate = (ctx, coordinate) => {
|
const aggregatedPosCoordinate = (ctx, coordinate) => {
|
||||||
const placement = ctx.placement || DEFAULT_PLACEMENT;
|
switch (ctx.placement) {
|
||||||
switch (placement) {
|
|
||||||
// For point-grid we return the coordinate of the middle point of the grid
|
// For point-grid we return the coordinate of the middle point of the grid
|
||||||
case `point-grid`:
|
case `point-grid`:
|
||||||
return `(FLOOR(cdb_${coordinate} / __cdb_grid_params.cdb_res) + 0.5) * __cdb_grid_params.cdb_res`;
|
return `(FLOOR(cdb_${coordinate} / __cdb_grid_params.cdb_res) + 0.5) * __cdb_grid_params.cdb_res`;
|
||||||
@ -406,7 +407,7 @@ SELECT * FROM
|
|||||||
(
|
(
|
||||||
SELECT
|
SELECT
|
||||||
min(cartodb_id) as cartodb_id
|
min(cartodb_id) as cartodb_id
|
||||||
${aggregatedPoint(ctx, true)}
|
${aggregatedPointWebMercator(ctx)}
|
||||||
${dimensionDefs(ctx)}
|
${dimensionDefs(ctx)}
|
||||||
${aggregateColumnDefs(ctx)}
|
${aggregateColumnDefs(ctx)}
|
||||||
FROM
|
FROM
|
||||||
@ -433,7 +434,7 @@ SELECT * FROM
|
|||||||
GROUP BY cdb_pos_grid_x, cdb_pos_grid_y ${dimensionNames(ctx)}
|
GROUP BY cdb_pos_grid_x, cdb_pos_grid_y ${dimensionNames(ctx)}
|
||||||
${havingClause(ctx)}
|
${havingClause(ctx)}
|
||||||
) __cdb_aggregation_src
|
) __cdb_aggregation_src
|
||||||
${aggregatedPoint(ctx, false)}
|
${aggregatedPointJoin(ctx)}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const aggregationQueryTemplates = {
|
const aggregationQueryTemplates = {
|
||||||
|
Loading…
Reference in New Issue
Block a user