Merge pull request #987 from CartoDB/ignore-null-values-formula-dataview
ensuring formula dataview filters infinities, nans and nulls
This commit is contained in:
commit
028c3f9aec
@ -288,7 +288,7 @@ describe('aggregation-dataview: special float values', function() {
|
|||||||
filters.forEach(function (filter) {
|
filters.forEach(function (filter) {
|
||||||
it('should handle special float values using filter: ' + JSON.stringify(filter), function(done) {
|
it('should handle special float values using filter: ' + JSON.stringify(filter), function(done) {
|
||||||
this.testClient = new TestClient(mapConfig, 1234);
|
this.testClient = new TestClient(mapConfig, 1234);
|
||||||
this.testClient.getDataview('val_aggregation', { own_filter: 0 }, function(err, dataview) {
|
this.testClient.getDataview('val_aggregation', filter, function(err, dataview) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.ok(dataview.infinities === (250 + 250));
|
assert.ok(dataview.infinities === (250 + 250));
|
||||||
assert.ok(dataview.nans === 250);
|
assert.ok(dataview.nans === 250);
|
||||||
@ -303,7 +303,7 @@ describe('aggregation-dataview: special float values', function() {
|
|||||||
|
|
||||||
it('should handle special numeric values using filter: ' + JSON.stringify(filter), function(done) {
|
it('should handle special numeric values using filter: ' + JSON.stringify(filter), function(done) {
|
||||||
this.testClient = new TestClient(mapConfig, 1234);
|
this.testClient = new TestClient(mapConfig, 1234);
|
||||||
this.testClient.getDataview('sum_aggregation_numeric', { own_filter: 0 }, function(err, dataview) {
|
this.testClient.getDataview('sum_aggregation_numeric', filter, function(err, dataview) {
|
||||||
assert.ifError(err);
|
assert.ifError(err);
|
||||||
assert.ok(dataview.nans === 333);
|
assert.ok(dataview.nans === 333);
|
||||||
assert.ok(dataview.categories.length === 2);
|
assert.ok(dataview.categories.length === 2);
|
||||||
|
@ -11,18 +11,8 @@ function createMapConfig(layers, dataviews, analysis) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('formula-dataview: special float values', function() {
|
function getMapConfig(operation, lastNumber) {
|
||||||
|
return createMapConfig([
|
||||||
afterEach(function(done) {
|
|
||||||
if (this.testClient) {
|
|
||||||
this.testClient.drain(done);
|
|
||||||
} else {
|
|
||||||
done();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
var mapConfig = createMapConfig(
|
|
||||||
[
|
|
||||||
{
|
{
|
||||||
"type": "cartodb",
|
"type": "cartodb",
|
||||||
"options": {
|
"options": {
|
||||||
@ -42,39 +32,104 @@ describe('formula-dataview: special float values', function() {
|
|||||||
type: 'formula',
|
type: 'formula',
|
||||||
options: {
|
options: {
|
||||||
column: 'val',
|
column: 'val',
|
||||||
operation: 'avg'
|
operation: operation
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"id": "a0",
|
id: "a0",
|
||||||
"type": "source",
|
type: "source",
|
||||||
"params": {
|
params: {
|
||||||
"query": [
|
query: `
|
||||||
'SELECT',
|
SELECT
|
||||||
' null::geometry the_geom_webmercator,',
|
null::geometry the_geom_webmercator,
|
||||||
' CASE',
|
CASE
|
||||||
' WHEN x % 4 = 0 THEN \'infinity\'::float',
|
WHEN x % 5 = 1 THEN 'infinity'::float
|
||||||
' WHEN x % 4 = 1 THEN \'-infinity\'::float',
|
WHEN x % 5 = 2 THEN '-infinity'::float
|
||||||
' WHEN x % 4 = 2 THEN \'NaN\'::float',
|
WHEN x % 5 = 3 THEN 'NaN'::float
|
||||||
' ELSE x',
|
WHEN x % 5 = 4 THEN NULL
|
||||||
' END AS val',
|
ELSE x
|
||||||
'FROM generate_series(1, 1000) x'
|
END AS val
|
||||||
].join('\n')
|
FROM generate_series(1, ${lastNumber}) x
|
||||||
|
`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]);
|
||||||
);
|
}
|
||||||
|
|
||||||
it('should filter infinities out and count them in the summary', function(done) {
|
describe('formula-dataview: special float values', function() {
|
||||||
this.testClient = new TestClient(mapConfig, 1234);
|
describe('easy numbers', function() { // not needed, but I keep it here to help human calc
|
||||||
|
afterEach(function(done) {
|
||||||
|
if (this.testClient) {
|
||||||
|
this.testClient.drain(done);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastNumber = 10;
|
||||||
|
|
||||||
|
[
|
||||||
|
{operation: 'count', result: 2},
|
||||||
|
{operation: 'avg', result: 7.5},
|
||||||
|
{operation: 'sum', result: 15},
|
||||||
|
{operation: 'min', result: 5},
|
||||||
|
{operation: 'max', result: 10}
|
||||||
|
]
|
||||||
|
.forEach(operationData => {
|
||||||
|
it(operationData.operation, function(done) {
|
||||||
|
this.testClient = new TestClient(getMapConfig(operationData.operation, lastNumber), 1234);
|
||||||
this.testClient.getDataview('val_formula', {}, function(err, dataview) {
|
this.testClient.getDataview('val_formula', {}, function(err, dataview) {
|
||||||
assert.ok(!err, err);
|
assert.ok(!err, err);
|
||||||
assert.equal(dataview.result, 501);
|
assert.deepStrictEqual(dataview, {
|
||||||
assert.ok(dataview.infinities === (250 + 250));
|
type: 'formula',
|
||||||
assert.ok(dataview.nans === 250);
|
operation: operationData.operation,
|
||||||
|
result: operationData.result,
|
||||||
|
nulls: lastNumber / 5,
|
||||||
|
nans: lastNumber / 5,
|
||||||
|
infinities: 2 * lastNumber / 5
|
||||||
|
});
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('bigger numbers', function() {
|
||||||
|
afterEach(function(done) {
|
||||||
|
if (this.testClient) {
|
||||||
|
this.testClient.drain(done);
|
||||||
|
} else {
|
||||||
|
done();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const lastNumber = 1000;
|
||||||
|
|
||||||
|
[
|
||||||
|
{operation: 'count', result: 200},
|
||||||
|
{operation: 'avg', result: 502.5},
|
||||||
|
{operation: 'sum', result: 100500},
|
||||||
|
{operation: 'min', result: 5},
|
||||||
|
{operation: 'max', result: 1000}
|
||||||
|
]
|
||||||
|
.forEach(operationData => {
|
||||||
|
it(operationData.operation, function(done) {
|
||||||
|
this.testClient = new TestClient(getMapConfig(operationData.operation, lastNumber), 1234);
|
||||||
|
this.testClient.getDataview('val_formula', {}, function(err, dataview) {
|
||||||
|
assert.ok(!err, err);
|
||||||
|
assert.deepStrictEqual(dataview, {
|
||||||
|
type: 'formula',
|
||||||
|
operation: operationData.operation,
|
||||||
|
result: operationData.result,
|
||||||
|
nulls: lastNumber / 5,
|
||||||
|
nans: lastNumber / 5,
|
||||||
|
infinities: 2 * lastNumber / 5
|
||||||
|
});
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user