Merge pull request #856 from CartoDB/841-the_geom_webmercator-type
Check the type of the_geom_webmercator for aggregation
This commit is contained in:
commit
27b5420358
@ -47,6 +47,10 @@ module.exports = class AggregationMapConfig extends MapConfig {
|
|||||||
return AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES.includes(geometryType);
|
return AggregationMapConfig.SUPPORTED_GEOMETRY_TYPES.includes(geometryType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static getAggregationGeometryColumn() {
|
||||||
|
return aggregationQuery.GEOMETRY_COLUMN;
|
||||||
|
}
|
||||||
|
|
||||||
constructor (user, config, connection, datasource) {
|
constructor (user, config, connection, datasource) {
|
||||||
super(config, datasource);
|
super(config, datasource);
|
||||||
|
|
||||||
|
@ -250,3 +250,4 @@ const aggregationQueryTemplates = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
module.exports.SUPPORTED_PLACEMENTS = Object.keys(aggregationQueryTemplates);
|
module.exports.SUPPORTED_PLACEMENTS = Object.keys(aggregationQueryTemplates);
|
||||||
|
module.exports.GEOMETRY_COLUMN = 'the_geom_webmercator';
|
||||||
|
@ -122,7 +122,8 @@ module.exports = class AggregationMapConfigAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const aggregationMetadata = queryUtils.getAggregationMetadata({
|
const aggregationMetadata = queryUtils.getAggregationMetadata({
|
||||||
query: layer.options.sql_raw ? layer.options.sql_raw : layer.options.sql
|
query: layer.options.sql_raw ? layer.options.sql_raw : layer.options.sql,
|
||||||
|
geometryColumn: AggregationMapConfig.getAggregationGeometryColumn()
|
||||||
});
|
});
|
||||||
|
|
||||||
connection.query(aggregationMetadata, (err, res) => {
|
connection.query(aggregationMetadata, (err, res) => {
|
||||||
|
@ -32,8 +32,8 @@ module.exports.getAggregationMetadata = ctx => `
|
|||||||
${getQueryRowEstimation(ctx.query)}
|
${getQueryRowEstimation(ctx.query)}
|
||||||
),
|
),
|
||||||
geometryType AS (
|
geometryType AS (
|
||||||
SELECT ST_GeometryType(the_geom) as geom_type
|
SELECT ST_GeometryType(${ctx.geometryColumn}) as geom_type
|
||||||
FROM (${ctx.query}) AS __cdb_query WHERE the_geom IS NOT NULL LIMIT 1
|
FROM (${ctx.query}) AS __cdb_query WHERE ${ctx.geometryColumn} IS NOT NULL LIMIT 1
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
rows AS count,
|
rows AS count,
|
||||||
|
@ -92,6 +92,14 @@ describe('aggregation', function () {
|
|||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
const POINTS_SQL_ONLY_WEBMERCATOR = `
|
||||||
|
select
|
||||||
|
x + 4 as cartodb_id,
|
||||||
|
st_transform(st_setsrid(st_makepoint(x*10, x*10), 4326), 3857) as the_geom_webmercator,
|
||||||
|
x as value
|
||||||
|
from generate_series(-3, 3) x
|
||||||
|
`;
|
||||||
|
|
||||||
function createVectorMapConfig (layers = [
|
function createVectorMapConfig (layers = [
|
||||||
{
|
{
|
||||||
type: 'cartodb',
|
type: 'cartodb',
|
||||||
@ -1401,6 +1409,35 @@ describe('aggregation', function () {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should only require the_geom_webmercator for aggregation', function (done) {
|
||||||
|
this.mapConfig = createVectorMapConfig([
|
||||||
|
{
|
||||||
|
type: 'cartodb',
|
||||||
|
options: {
|
||||||
|
sql: POINTS_SQL_ONLY_WEBMERCATOR,
|
||||||
|
aggregation: {
|
||||||
|
threshold: 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
this.testClient = new TestClient(this.mapConfig);
|
||||||
|
|
||||||
|
this.testClient.getLayergroup((err, body) => {
|
||||||
|
if (err) {
|
||||||
|
return done(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
assert.equal(typeof body.metadata, 'object');
|
||||||
|
assert.ok(Array.isArray(body.metadata.layers));
|
||||||
|
|
||||||
|
body.metadata.layers.forEach(layer => assert.ok(layer.meta.aggregation.mvt));
|
||||||
|
body.metadata.layers.forEach(layer => assert.ok(!layer.meta.aggregation.png));
|
||||||
|
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user