2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2016-06-20 22:20:48 +08:00
|
|
|
var assert = require('../../support/assert');
|
|
|
|
var TestClient = require('../../support/test-client');
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('aggregations happy cases', function () {
|
|
|
|
afterEach(function (done) {
|
2016-06-20 22:20:48 +08:00
|
|
|
if (this.testClient) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function aggregationOperationMapConfig (operation, query, column, aggregationColumn) {
|
2017-01-17 00:00:28 +08:00
|
|
|
column = column || 'adm0name';
|
|
|
|
aggregationColumn = aggregationColumn || 'pop_max';
|
2017-01-17 02:23:08 +08:00
|
|
|
query = query || 'select * from populated_places_simple_reduced';
|
2017-01-17 00:00:28 +08:00
|
|
|
|
|
|
|
var mapConfig = {
|
2016-06-20 22:20:48 +08:00
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
2017-01-17 02:23:08 +08:00
|
|
|
sql: query,
|
2016-06-20 22:20:48 +08:00
|
|
|
cartocss: '#layer0 { marker-fill: red; marker-width: 10; }',
|
|
|
|
cartocss_version: '2.0.1',
|
2017-01-17 00:00:28 +08:00
|
|
|
widgets: {}
|
2016-06-20 22:20:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
2017-01-17 00:00:28 +08:00
|
|
|
|
|
|
|
mapConfig.layers[0].options.widgets[column] = {
|
|
|
|
type: 'aggregation',
|
|
|
|
options: {
|
|
|
|
column: column,
|
|
|
|
aggregation: operation,
|
|
|
|
aggregationColumn: aggregationColumn
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return mapConfig;
|
2016-06-20 22:20:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
var operations = ['count', 'sum', 'avg', 'max', 'min'];
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
operations.forEach(function (operation) {
|
|
|
|
it('should be able to use "' + operation + '" as aggregation operation', function (done) {
|
2016-06-20 22:20:48 +08:00
|
|
|
this.testClient = new TestClient(aggregationOperationMapConfig(operation));
|
|
|
|
this.testClient.getDataview('adm0name', { own_filter: 0 }, function (err, aggregation) {
|
|
|
|
assert.ok(!err, err);
|
|
|
|
assert.ok(aggregation);
|
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(aggregation.type, 'aggregation');
|
|
|
|
assert.strictEqual(aggregation.aggregation, operation);
|
2016-06-20 22:20:48 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-01-17 00:00:28 +08:00
|
|
|
|
2017-01-17 02:23:08 +08:00
|
|
|
var query = [
|
|
|
|
'select 1 as val, \'a\' as cat, ST_Transform(ST_SetSRID(ST_MakePoint(0,0),4326),3857) as the_geom_webmercator',
|
|
|
|
'select null, \'b\', ST_Transform(ST_SetSRID(ST_MakePoint(0,1),4326),3857)',
|
|
|
|
'select null, \'b\', ST_Transform(ST_SetSRID(ST_MakePoint(1,0),4326),3857)',
|
|
|
|
'select null, null, ST_Transform(ST_SetSRID(ST_MakePoint(1,1),4326),3857)'
|
|
|
|
].join(' UNION ALL ');
|
2017-01-17 00:00:28 +08:00
|
|
|
|
2017-01-17 02:23:08 +08:00
|
|
|
operations.forEach(function (operation) {
|
2018-03-09 00:39:36 +08:00
|
|
|
var description = 'should handle NULL values in category and aggregation columns using "' +
|
|
|
|
operation + '" as aggregation operation';
|
2017-01-18 00:09:17 +08:00
|
|
|
|
|
|
|
it(description, function (done) {
|
2017-01-17 02:23:08 +08:00
|
|
|
this.testClient = new TestClient(aggregationOperationMapConfig(operation, query, 'cat', 'val'));
|
|
|
|
this.testClient.getDataview('cat', { own_filter: 0 }, function (err, aggregation) {
|
|
|
|
assert.ifError(err);
|
2017-01-17 00:00:28 +08:00
|
|
|
|
2017-01-17 02:23:08 +08:00
|
|
|
assert.ok(aggregation);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(aggregation.type, 'aggregation');
|
2017-01-17 02:23:08 +08:00
|
|
|
assert.ok(aggregation.categories);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(aggregation.categoriesCount, 3);
|
|
|
|
assert.strictEqual(aggregation.count, 4);
|
|
|
|
assert.strictEqual(aggregation.nulls, 1);
|
2017-01-17 00:00:28 +08:00
|
|
|
|
2017-01-17 02:23:08 +08:00
|
|
|
var hasNullCategory = false;
|
|
|
|
aggregation.categories.forEach(function (category) {
|
|
|
|
if (category.category === null) {
|
|
|
|
hasNullCategory = true;
|
|
|
|
}
|
|
|
|
});
|
2017-01-18 00:09:17 +08:00
|
|
|
|
2018-03-09 00:39:36 +08:00
|
|
|
assert.ok(!hasNullCategory, 'aggregation has category NULL');
|
2017-01-17 02:23:08 +08:00
|
|
|
done();
|
|
|
|
});
|
2017-01-17 00:00:28 +08:00
|
|
|
});
|
|
|
|
});
|
2017-03-02 17:48:20 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var operations_and_values = { count: 9, sum: 45, avg: 5, max: 9, min: 1 };
|
2017-03-02 17:48:20 +08:00
|
|
|
|
|
|
|
var query_other = [
|
|
|
|
'select generate_series(1,3) as val, \'other_a\' as cat, NULL as the_geom_webmercator',
|
|
|
|
'select generate_series(4,6) as val, \'other_b\' as cat, NULL as the_geom_webmercator',
|
|
|
|
'select generate_series(7,9) as val, \'other_c\' as cat, NULL as the_geom_webmercator',
|
|
|
|
'select generate_series(10,12) as val, \'category_1\' as cat, NULL as the_geom_webmercator',
|
|
|
|
'select generate_series(10,12) as val, \'category_2\' as cat, NULL as the_geom_webmercator',
|
|
|
|
'select generate_series(10,12) as val, \'category_3\' as cat, NULL as the_geom_webmercator',
|
|
|
|
'select generate_series(10,12) as val, \'category_4\' as cat, NULL as the_geom_webmercator',
|
|
|
|
'select generate_series(10,12) as val, \'category_5\' as cat, NULL as the_geom_webmercator'
|
|
|
|
].join(' UNION ALL ');
|
|
|
|
|
|
|
|
Object.keys(operations_and_values).forEach(function (operation) {
|
|
|
|
var description = 'should aggregate OTHER category using "' + operation + '"';
|
|
|
|
|
|
|
|
it(description, function (done) {
|
|
|
|
this.testClient = new TestClient(aggregationOperationMapConfig(operation, query_other, 'cat', 'val'));
|
|
|
|
this.testClient.getDataview('cat', { own_filter: 0 }, function (err, aggregation) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.ok(aggregation);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(aggregation.type, 'aggregation');
|
2017-03-02 17:48:20 +08:00
|
|
|
assert.ok(aggregation.categories);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(aggregation.categoriesCount, 8);
|
|
|
|
assert.strictEqual(aggregation.count, 24);
|
|
|
|
assert.strictEqual(aggregation.nulls, 0);
|
2017-03-02 17:48:20 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
var aggregated_categories = aggregation.categories.filter(function (category) {
|
2017-03-02 17:48:20 +08:00
|
|
|
return category.agg === true;
|
|
|
|
});
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(aggregated_categories.length, 1);
|
|
|
|
assert.strictEqual(aggregated_categories[0].value, operations_and_values[operation]);
|
2017-03-02 17:48:20 +08:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-07-10 18:29:25 +08:00
|
|
|
|
|
|
|
var widgetSearchExpects = {
|
2019-10-22 01:07:24 +08:00
|
|
|
count: [{ category: 'other_a', value: 3 }],
|
|
|
|
sum: [{ category: 'other_a', value: 6 }],
|
|
|
|
avg: [{ category: 'other_a', value: 2 }],
|
|
|
|
max: [{ category: 'other_a', value: 3 }],
|
|
|
|
min: [{ category: 'other_a', value: 1 }]
|
2017-07-10 18:29:25 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(operations_and_values).forEach(function (operation) {
|
|
|
|
var description = 'should search OTHER category using "' + operation + '"';
|
|
|
|
|
|
|
|
it(description, function (done) {
|
|
|
|
this.testClient = new TestClient(aggregationOperationMapConfig(operation, query_other, 'cat', 'val'));
|
|
|
|
this.testClient.widgetSearch('cat', 'other_a', function (err, res, searchResult) {
|
|
|
|
assert.ifError(err);
|
|
|
|
|
|
|
|
assert.ok(searchResult);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(searchResult.type, 'aggregation');
|
2017-07-10 18:29:25 +08:00
|
|
|
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(searchResult.categories.length, 1);
|
2017-07-10 18:29:25 +08:00
|
|
|
assert.deepEqual(
|
|
|
|
searchResult.categories,
|
|
|
|
widgetSearchExpects[operation]
|
|
|
|
);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2016-06-20 22:20:48 +08:00
|
|
|
});
|
2017-06-13 00:15:39 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('aggregation-dataview: special float values', function () {
|
|
|
|
afterEach(function (done) {
|
2017-06-13 00:15:39 +08:00
|
|
|
if (this.testClient) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
} else {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
function createMapConfig (layers, dataviews, analysis) {
|
2017-06-13 00:15:39 +08:00
|
|
|
return {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: layers,
|
|
|
|
dataviews: dataviews || {},
|
|
|
|
analyses: analysis || []
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
var mapConfig = createMapConfig(
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
|
|
|
options: {
|
|
|
|
source: {
|
|
|
|
id: 'a0'
|
2017-06-13 00:15:39 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#points { marker-width: 10; marker-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2017-06-13 00:15:39 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
{
|
|
|
|
val_aggregation: {
|
|
|
|
source: {
|
|
|
|
id: 'a0'
|
|
|
|
},
|
|
|
|
type: 'aggregation',
|
|
|
|
options: {
|
|
|
|
column: 'cat',
|
2017-06-13 01:45:06 +08:00
|
|
|
aggregation: 'avg',
|
2017-06-13 00:15:39 +08:00
|
|
|
aggregationColumn: 'val'
|
|
|
|
}
|
2017-06-22 00:44:21 +08:00
|
|
|
},
|
|
|
|
sum_aggregation_numeric: {
|
|
|
|
source: {
|
|
|
|
id: 'a1'
|
|
|
|
},
|
|
|
|
type: 'aggregation',
|
|
|
|
options: {
|
|
|
|
column: 'cat',
|
|
|
|
aggregation: 'sum',
|
|
|
|
aggregationColumn: 'val'
|
|
|
|
}
|
2017-06-13 00:15:39 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
[
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'a0',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: [
|
2017-06-13 00:15:39 +08:00
|
|
|
'SELECT',
|
|
|
|
' null::geometry the_geom_webmercator,',
|
|
|
|
' CASE',
|
|
|
|
' WHEN x % 4 = 0 THEN \'infinity\'::float',
|
|
|
|
' WHEN x % 4 = 1 THEN \'-infinity\'::float',
|
|
|
|
' WHEN x % 4 = 2 THEN \'NaN\'::float',
|
|
|
|
' ELSE x',
|
|
|
|
' END AS val,',
|
|
|
|
' CASE',
|
|
|
|
' WHEN x % 2 = 0 THEN \'category_1\'',
|
|
|
|
' ELSE \'category_2\'',
|
|
|
|
' END AS cat',
|
|
|
|
'FROM generate_series(1, 1000) x'
|
|
|
|
].join('\n')
|
|
|
|
}
|
2017-06-22 00:44:21 +08:00
|
|
|
}, {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'a1',
|
|
|
|
type: 'source',
|
|
|
|
params: {
|
|
|
|
query: [
|
2017-06-22 00:44:21 +08:00
|
|
|
'SELECT',
|
|
|
|
' null::geometry the_geom_webmercator,',
|
|
|
|
' CASE',
|
|
|
|
' WHEN x % 3 = 0 THEN \'NaN\'::numeric',
|
|
|
|
' WHEN x % 3 = 1 THEN x',
|
|
|
|
' ELSE x',
|
|
|
|
' END AS val,',
|
|
|
|
' CASE',
|
|
|
|
' WHEN x % 2 = 0 THEN \'category_1\'',
|
|
|
|
' ELSE \'category_2\'',
|
|
|
|
' END AS cat',
|
|
|
|
'FROM generate_series(1, 1000) x'
|
|
|
|
].join('\n')
|
|
|
|
}
|
2017-06-13 00:15:39 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
|
2017-06-22 00:44:21 +08:00
|
|
|
// Source a0
|
|
|
|
// -----------------------------------------------
|
2017-06-13 01:45:06 +08:00
|
|
|
// the_geom_webmercator | val | cat
|
|
|
|
// ----------------------+-----------+------------
|
|
|
|
// | -Infinity | category_2
|
|
|
|
// | NaN | category_1
|
|
|
|
// | 3 | category_2
|
|
|
|
// | Infinity | category_1
|
|
|
|
// | -Infinity | category_2
|
|
|
|
// | NaN | category_1
|
|
|
|
// | 7 | category_2
|
|
|
|
// | Infinity | category_1
|
|
|
|
// | -Infinity | category_2
|
|
|
|
// | NaN | category_1
|
|
|
|
// | 11 | category_2
|
|
|
|
// | " | "
|
|
|
|
|
2017-06-13 01:22:37 +08:00
|
|
|
var filters = [{ own_filter: 0 }, {}];
|
|
|
|
filters.forEach(function (filter) {
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should handle special float values using filter: ' + JSON.stringify(filter), function (done) {
|
2017-06-13 01:21:41 +08:00
|
|
|
this.testClient = new TestClient(mapConfig, 1234);
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getDataview('val_aggregation', filter, function (err, dataview) {
|
2017-06-13 01:21:41 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(dataview.infinities === (250 + 250));
|
|
|
|
assert.ok(dataview.nans === 250);
|
2017-06-13 01:45:06 +08:00
|
|
|
assert.ok(dataview.categories.length === 1);
|
|
|
|
dataview.categories.forEach(function (category) {
|
|
|
|
assert.ok(category.category === 'category_2');
|
|
|
|
assert.ok(category.value === 501);
|
2017-06-13 01:49:58 +08:00
|
|
|
});
|
2017-06-13 01:21:41 +08:00
|
|
|
done();
|
|
|
|
});
|
2017-06-13 00:15:39 +08:00
|
|
|
});
|
2017-06-22 00:44:21 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should handle special numeric values using filter: ' + JSON.stringify(filter), function (done) {
|
2017-06-22 00:44:21 +08:00
|
|
|
this.testClient = new TestClient(mapConfig, 1234);
|
2019-10-22 01:07:24 +08:00
|
|
|
this.testClient.getDataview('sum_aggregation_numeric', filter, function (err, dataview) {
|
2017-06-22 00:44:21 +08:00
|
|
|
assert.ifError(err);
|
|
|
|
assert.ok(dataview.nans === 333);
|
|
|
|
assert.ok(dataview.categories.length === 2);
|
|
|
|
dataview.categories.forEach(function (category) {
|
|
|
|
assert.ok(category.value !== null);
|
|
|
|
});
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2017-06-13 01:49:58 +08:00
|
|
|
});
|
2017-06-13 00:15:39 +08:00
|
|
|
});
|
2017-11-07 19:51:48 +08:00
|
|
|
|
2017-11-07 23:14:47 +08:00
|
|
|
describe('aggregation dataview tuned by categories query param', function () {
|
2017-11-07 19:51:48 +08:00
|
|
|
const mapConfig = {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
2017-11-07 19:51:48 +08:00
|
|
|
options: {
|
|
|
|
source: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'a0'
|
2017-11-07 19:51:48 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#points { marker-width: 10; marker-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2017-11-07 19:51:48 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
dataviews: {
|
|
|
|
categories: {
|
|
|
|
source: {
|
|
|
|
id: 'a0'
|
|
|
|
},
|
|
|
|
type: 'aggregation',
|
|
|
|
options: {
|
|
|
|
column: 'cat',
|
|
|
|
aggregation: 'sum',
|
|
|
|
aggregationColumn: 'val'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
analyses: [
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'a0',
|
|
|
|
type: 'source',
|
2017-11-07 19:51:48 +08:00
|
|
|
params: {
|
|
|
|
query: `
|
|
|
|
SELECT
|
|
|
|
null::geometry the_geom_webmercator,
|
|
|
|
CASE
|
|
|
|
WHEN x % 4 = 0 THEN 1
|
|
|
|
WHEN x % 4 = 1 THEN 2
|
|
|
|
WHEN x % 4 = 2 THEN 3
|
|
|
|
ELSE 4
|
|
|
|
END AS val,
|
|
|
|
CASE
|
|
|
|
WHEN x % 4 = 0 THEN 'category_1'
|
|
|
|
WHEN x % 4 = 1 THEN 'category_2'
|
|
|
|
WHEN x % 4 = 2 THEN 'category_3'
|
|
|
|
ELSE 'category_4'
|
|
|
|
END AS cat
|
|
|
|
FROM generate_series(1, 1000) x
|
|
|
|
`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2017-11-07 23:28:37 +08:00
|
|
|
beforeEach(function () {
|
|
|
|
this.testClient = new TestClient(mapConfig, 1234);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function (done) {
|
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
|
2017-11-07 23:14:47 +08:00
|
|
|
var scenarios = [
|
|
|
|
{
|
|
|
|
params: { own_filter: 0, categories: -1 },
|
|
|
|
categoriesExpected: 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
params: { own_filter: 0, categories: 0 },
|
|
|
|
categoriesExpected: 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
params: { own_filter: 0, categories: 1 },
|
|
|
|
categoriesExpected: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
params: { own_filter: 0, categories: 2 },
|
|
|
|
categoriesExpected: 2
|
|
|
|
},
|
|
|
|
{
|
|
|
|
params: { own_filter: 0, categories: 4 },
|
|
|
|
categoriesExpected: 4
|
|
|
|
},
|
|
|
|
{
|
|
|
|
params: { own_filter: 0, categories: 5 },
|
|
|
|
categoriesExpected: 4
|
|
|
|
}
|
|
|
|
];
|
2017-11-07 19:51:48 +08:00
|
|
|
|
2017-11-07 23:14:47 +08:00
|
|
|
scenarios.forEach(function (scenario) {
|
|
|
|
it(`should handle cartegories to customize aggregations: ${JSON.stringify(scenario.params)}`, function (done) {
|
|
|
|
this.testClient.getDataview('categories', scenario.params, (err, dataview) => {
|
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(dataview.categories.length, scenario.categoriesExpected);
|
2017-11-07 23:14:47 +08:00
|
|
|
done();
|
|
|
|
});
|
2017-11-07 19:51:48 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-03-09 00:39:36 +08:00
|
|
|
|
|
|
|
describe('Count aggregation', function () {
|
|
|
|
const mapConfig = {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
type: 'cartodb',
|
2018-03-09 00:39:36 +08:00
|
|
|
options: {
|
|
|
|
source: {
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'a0'
|
2018-03-09 00:39:36 +08:00
|
|
|
},
|
2019-10-22 01:07:24 +08:00
|
|
|
cartocss: '#points { marker-width: 10; marker-fill: red; }',
|
|
|
|
cartocss_version: '2.3.0'
|
2018-03-09 00:39:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
],
|
|
|
|
dataviews: {
|
|
|
|
categories: {
|
|
|
|
source: {
|
|
|
|
id: 'a0'
|
|
|
|
},
|
|
|
|
type: 'aggregation',
|
|
|
|
options: {
|
|
|
|
column: 'cat',
|
|
|
|
aggregation: 'count'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
analyses: [
|
|
|
|
{
|
2019-10-22 01:07:24 +08:00
|
|
|
id: 'a0',
|
|
|
|
type: 'source',
|
2018-03-09 00:39:36 +08:00
|
|
|
params: {
|
|
|
|
query: `
|
|
|
|
SELECT
|
|
|
|
null::geometry the_geom_webmercator,
|
|
|
|
CASE
|
|
|
|
WHEN x % 4 = 0 THEN 1
|
|
|
|
WHEN x % 4 = 1 THEN 2
|
|
|
|
WHEN x % 4 = 2 THEN 3
|
|
|
|
ELSE null
|
|
|
|
END AS val,
|
|
|
|
CASE
|
|
|
|
WHEN x % 4 = 0 THEN 'category_1'
|
|
|
|
WHEN x % 4 = 1 THEN 'category_2'
|
|
|
|
WHEN x % 4 = 2 THEN 'category_3'
|
|
|
|
ELSE null
|
|
|
|
END AS cat
|
|
|
|
FROM generate_series(1, 1000) x
|
|
|
|
`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should handle null values correctly when aggregationColumn isn\'t provided', function (done) {
|
2018-03-09 00:39:36 +08:00
|
|
|
this.testClient = new TestClient(mapConfig, 1234);
|
|
|
|
this.testClient.getDataview('categories', { own_filter: 0, categories: 0 }, (err, dataview) => {
|
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(dataview.categories.length, 3);
|
2018-03-09 00:39:36 +08:00
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should handle null values correctly when aggregationColumn is provided', function (done) {
|
2018-03-09 00:39:36 +08:00
|
|
|
mapConfig.dataviews.categories.options.aggregationColumn = 'val';
|
|
|
|
this.testClient = new TestClient(mapConfig, 1234);
|
|
|
|
this.testClient.getDataview('categories', { own_filter: 0, categories: 0 }, (err, dataview) => {
|
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(dataview.categories.length, 3);
|
2018-03-09 00:39:36 +08:00
|
|
|
this.testClient.drain(done);
|
|
|
|
});
|
|
|
|
});
|
2018-05-10 21:59:38 +08:00
|
|
|
});
|