Use full-sample aggregation only as default

Sampling is performed only when placement, columns or dimensions are specified;
otherwise the regular centroid/grid-point/grid-center is used without sampling.
This commit is contained in:
Javier Goizueta
2017-12-22 11:31:33 +01:00
parent 7f64d15944
commit e9a4fc4b2c
3 changed files with 249 additions and 51 deletions
+179 -15
View File
@@ -289,7 +289,8 @@ describe('aggregation', function () {
options: {
sql: POINTS_SQL_2,
aggregation: {
threshold: 1
threshold: 1,
placement: 'centroid'
},
cartocss: '#layer { marker-width: [value]; }',
cartocss_version: '2.3.0'
@@ -309,6 +310,45 @@ describe('aggregation', function () {
});
});
it('should provide all columns in the default aggregation ',
function (done) {
const response = {
status: 200,
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
};
this.mapConfig = createVectorMapConfig([
{
type: 'cartodb',
options: {
sql: POINTS_SQL_2,
aggregation: {
threshold: 1
},
cartocss: '#layer { marker-width: [value]; }',
cartocss_version: '2.3.0'
}
}
]);
this.testClient = new TestClient(this.mapConfig);
this.testClient.getLayergroup({ response }, (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();
});
});
it('should skip aggregation to create a layergroup with aggregation defined already', function (done) {
const mapConfig = createVectorMapConfig([
{
@@ -569,6 +609,140 @@ describe('aggregation', function () {
});
});
['centroid', 'point-sample', 'point-grid'].forEach(placement => {
it(`dimensions should work for ${placement} placement`, function(done) {
// FIXME: skip until pg-mvt renderer is able to return all columns
if (process.env.POSTGIS_VERSION === '2.4') {
return done();
}
this.mapConfig = createVectorMapConfig([
{
type: 'cartodb',
options: {
sql: POINTS_SQL_1,
aggregation: {
placement: placement ,
threshold: 1,
dimensions: {
value: "value"
}
}
}
}
]);
this.testClient = new TestClient(this.mapConfig);
const options = {
format: 'mvt'
};
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
if (err) {
return done(err);
}
const tileJSON = tile.toJSON();
tileJSON[0].features.forEach(
feature => assert.equal(typeof feature.properties.value, 'number')
);
done();
});
});
});
it(`dimensions should trigger non-default aggregation`, function(done) {
// FIXME: skip until pg-mvt renderer is able to return all columns
if (process.env.POSTGIS_VERSION === '2.4') {
return done();
}
this.mapConfig = createVectorMapConfig([
{
type: 'cartodb',
options: {
sql: POINTS_SQL_2,
aggregation: {
threshold: 1,
dimensions: {
value: "value"
}
}
}
}
]);
this.testClient = new TestClient(this.mapConfig);
const options = {
format: 'mvt'
};
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
if (err) {
return done(err);
}
const tileJSON = tile.toJSON();
tileJSON[0].features.forEach(
feature => assert.equal(typeof feature.properties.value, 'number')
);
tileJSON[0].features.forEach(
feature => assert.equal(typeof feature.properties.sqrt_value, 'undefined')
);
done();
});
});
it(`aggregations should trigger non-default aggregation`, function(done) {
// FIXME: skip until pg-mvt renderer is able to return all columns
if (process.env.POSTGIS_VERSION === '2.4') {
return done();
}
this.mapConfig = createVectorMapConfig([
{
type: 'cartodb',
options: {
sql: POINTS_SQL_2,
aggregation: {
threshold: 1,
columns: {
value: {
aggregate_function: 'sum',
aggregated_column: 'value'
}
}
}
}
}
]);
this.testClient = new TestClient(this.mapConfig);
const options = {
format: 'mvt'
};
this.testClient.getTile(0, 0, 0, options, (err, res, tile) => {
if (err) {
return done(err);
}
const tileJSON = tile.toJSON();
tileJSON[0].features.forEach(
feature => assert.equal(typeof feature.properties.value, 'number')
);
tileJSON[0].features.forEach(
feature => assert.equal(typeof feature.properties.sqrt_value, 'undefined')
);
done();
});
});
it('should work when the sql has single quotes', function (done) {
this.mapConfig = createVectorMapConfig([
{
@@ -576,6 +750,7 @@ describe('aggregation', function () {
options: {
sql: `
SELECT
cartodb_id,
the_geom_webmercator,
the_geom,
value,
@@ -732,7 +907,7 @@ describe('aggregation', function () {
});
});
it('aggregates with full-sample placement', function (done) {
it('aggregates with full-sample placement by default', function (done) {
this.mapConfig = createVectorMapConfig([
{
type: 'cartodb',
@@ -740,17 +915,6 @@ describe('aggregation', function () {
sql: POINTS_SQL_1,
resolution: 256,
aggregation: {
placement: 'point-grid',
columns: {
total: {
aggregate_function: 'sum',
aggregated_column: 'value'
},
v_avg: {
aggregate_function: 'avg',
aggregated_column: 'value'
}
},
threshold: 1
}
}
@@ -847,10 +1011,10 @@ describe('aggregation', function () {
}
assert.deepEqual(body, {
errors: [ 'Invalid placement. Valid values: centroid, point-grid, point-sample, full-sample'],
errors: [ 'Invalid placement. Valid values: centroid, point-grid, point-sample'],
errors_with_context:[{
type: 'layer',
message: 'Invalid placement. Valid values: centroid, point-grid, point-sample, full-sample',
message: 'Invalid placement. Valid values: centroid, point-grid, point-sample',
layer: {
id: "layer0",
index: 0,