Simplify to pass test
This commit is contained in:
parent
f376a7cdd5
commit
6f04214f5d
@ -3,7 +3,3 @@ module.exports = class BaseAggregation {
|
|||||||
throw new Error('Unimplemented method');
|
throw new Error('Unimplemented method');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports.baseQueryTemplate = ctx => `
|
|
||||||
select ${ctx} blah.., blah, blah...
|
|
||||||
`;
|
|
||||||
|
@ -1,54 +1,13 @@
|
|||||||
const BaseAggregation = require('./base-aggregation');
|
const BaseAggregation = require('./base-aggregation');
|
||||||
const { baseQueryTemplate } = BaseAggregation;
|
|
||||||
|
|
||||||
module.exports = class RasterAggregation extends BaseAggregation {
|
module.exports = class RasterAggregation extends BaseAggregation {
|
||||||
sql (options) {
|
sql (options) {
|
||||||
return rasterAggregationQueryTemplate({
|
return rasterAggregationQueryTemplate({
|
||||||
source_query: options.sql,
|
sourceQuery: options.sql,
|
||||||
res: options.resolution,
|
res: options.resolution,
|
||||||
columns: options.columns
|
columns: options.columns
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const rasterAggregationQueryTemplate = ctx => `
|
const rasterAggregationQueryTemplate = ctx => `${ctx.sourceQuery}`;
|
||||||
WITH
|
|
||||||
_cdb_source AS (
|
|
||||||
-- original query
|
|
||||||
${ctx.source_query}
|
|
||||||
),
|
|
||||||
_cdb_resolution AS (
|
|
||||||
SELECT ${ctx.res}*CDB_XYZ_Resolution(CDB_ZoomFromScale(!scale_denominator!))
|
|
||||||
AS _cdb_grid_size
|
|
||||||
-- equivalent to:
|
|
||||||
-- ${ctx.res}*!scale_denominator!*0.00028
|
|
||||||
),
|
|
||||||
_cdb_gridded AS (
|
|
||||||
SELECT
|
|
||||||
Floor(ST_X(_cdb_source.the_geom_webmercator)/_cdb_grid_size)::int AS _cdb_gx,
|
|
||||||
Floor(ST_Y(_cdb_source.the_geom_webmercator)/_cdb_grid_size)::int AS _cdb_gy,
|
|
||||||
count(*) AS _cdb_feature_count
|
|
||||||
FROM _cdb_source, _cdb_resolution
|
|
||||||
GROUP BY _cdb_gx, _cdb_gy
|
|
||||||
),
|
|
||||||
_cdb_webmercator AS (
|
|
||||||
SELECT
|
|
||||||
row_number() over() AS cartodb_id,
|
|
||||||
_cdb_feature_count,
|
|
||||||
ST_SetSRID(
|
|
||||||
ST_MakePoint(
|
|
||||||
_cdb_gx*_cdb_grid_size + _cdb_grid_size/2,
|
|
||||||
_cdb_gy*_cdb_grid_size + _cdb_grid_size/2
|
|
||||||
),
|
|
||||||
3857
|
|
||||||
) AS the_geom_webmercator
|
|
||||||
FROM _cdb_gridded, _cdb_resolution
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
cartodb_id,
|
|
||||||
ST_Transform(the_geom_webmercator, 4326) AS the_geom,
|
|
||||||
the_geom_webmercator,
|
|
||||||
_cdb_feature_count
|
|
||||||
FROM _cdb_webmercator
|
|
||||||
${baseQueryTemplate(ctx)}
|
|
||||||
`;
|
|
||||||
|
@ -1,54 +1,13 @@
|
|||||||
const BaseAggregation = require('./base-aggregation');
|
const BaseAggregation = require('./base-aggregation');
|
||||||
const { baseQueryTemplate } = BaseAggregation;
|
|
||||||
|
|
||||||
module.exports = class VectorAggregation extends BaseAggregation {
|
module.exports = class VectorAggregation extends BaseAggregation {
|
||||||
sql (options) {
|
sql (options) {
|
||||||
return vectorAggregationQueryTemplate({
|
return vectorAggregationQueryTemplate({
|
||||||
source_query: options.sql,
|
sourceQuery: options.sql,
|
||||||
res: options.resolution,
|
res: options.resolution,
|
||||||
columns: options.columns
|
columns: options.columns
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const vectorAggregationQueryTemplate = ctx => `
|
const vectorAggregationQueryTemplate = ctx => `${ctx.sourceQuery}`;
|
||||||
WITH
|
|
||||||
_cdb_source AS (
|
|
||||||
-- original query
|
|
||||||
${ctx.source_query}
|
|
||||||
),
|
|
||||||
_cdb_resolution AS (
|
|
||||||
SELECT ${ctx.res}*CDB_XYZ_Resolution(CDB_ZoomFromScale(!scale_denominator!))
|
|
||||||
AS _cdb_grid_size
|
|
||||||
-- equivalent to:
|
|
||||||
-- ${ctx.res}*!scale_denominator!*0.00028
|
|
||||||
),
|
|
||||||
_cdb_gridded AS (
|
|
||||||
SELECT
|
|
||||||
Floor(ST_X(_cdb_source.the_geom_webmercator)/_cdb_grid_size)::int AS _cdb_gx,
|
|
||||||
Floor(ST_Y(_cdb_source.the_geom_webmercator)/_cdb_grid_size)::int AS _cdb_gy,
|
|
||||||
count(*) AS _cdb_feature_count
|
|
||||||
FROM _cdb_source, _cdb_resolution
|
|
||||||
GROUP BY _cdb_gx, _cdb_gy
|
|
||||||
),
|
|
||||||
_cdb_webmercator AS (
|
|
||||||
SELECT
|
|
||||||
row_number() over() AS cartodb_id,
|
|
||||||
_cdb_feature_count,
|
|
||||||
ST_SetSRID(
|
|
||||||
ST_MakePoint(
|
|
||||||
_cdb_gx*_cdb_grid_size + _cdb_grid_size/2,
|
|
||||||
_cdb_gy*_cdb_grid_size + _cdb_grid_size/2
|
|
||||||
),
|
|
||||||
3857
|
|
||||||
) AS the_geom_webmercator
|
|
||||||
FROM _cdb_gridded, _cdb_resolution
|
|
||||||
)
|
|
||||||
SELECT
|
|
||||||
cartodb_id,
|
|
||||||
ST_Transform(the_geom_webmercator, 4326) AS the_geom,
|
|
||||||
the_geom_webmercator,
|
|
||||||
_cdb_feature_count
|
|
||||||
FROM _cdb_webmercator
|
|
||||||
${baseQueryTemplate(ctx)}
|
|
||||||
`;
|
|
||||||
|
Loading…
Reference in New Issue
Block a user