Merge pull request #953 from CartoDB/fix-dataview-typeof
handling pg_typeof == undefined error in dataviews
This commit is contained in:
commit
af35ff7419
@ -52,6 +52,11 @@ module.exports = class BaseDataview {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (!result || !result.rows || !result.rows.length) {
|
||||
return callback(new Error('The column type could not be determined'));
|
||||
}
|
||||
|
||||
const pgType = result.rows[0].pg_typeof;
|
||||
callback(null, getPGTypeName(pgType));
|
||||
}, readOnlyTransaction);
|
||||
|
@ -3,7 +3,9 @@ require('../../support/test_helper');
|
||||
var assert = require('../../support/assert');
|
||||
var TestClient = require('../../support/test-client');
|
||||
|
||||
describe('histogram-dataview', function() {
|
||||
describe('dataview error cases', function() {
|
||||
|
||||
describe('generic errors', function() {
|
||||
|
||||
afterEach(function(done) {
|
||||
if (this.testClient) {
|
||||
@ -85,3 +87,127 @@ describe('histogram-dataview', function() {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('pg_typeof', function() {
|
||||
|
||||
afterEach(function(done) {
|
||||
if (this.testClient) {
|
||||
this.testClient.drain(done);
|
||||
} else {
|
||||
done();
|
||||
}
|
||||
});
|
||||
|
||||
function createMapConfig(query) {
|
||||
query = query || 'select * from populated_places_simple_reduced';
|
||||
|
||||
return {
|
||||
version: '1.5.0',
|
||||
layers: [
|
||||
{
|
||||
type: 'mapnik',
|
||||
options: {
|
||||
sql: query,
|
||||
cartocss: '#layer0 { marker-fill: red; marker-width: 10; }',
|
||||
cartocss_version: '2.0.1',
|
||||
source: { id: "a0" }
|
||||
}
|
||||
}
|
||||
],
|
||||
analyses: [{
|
||||
id: "a0",
|
||||
type: "source",
|
||||
params: {
|
||||
query: query
|
||||
}
|
||||
}],
|
||||
dataviews: {
|
||||
aggregation_count_dataview: {
|
||||
type: "aggregation",
|
||||
source: { id: "a0" },
|
||||
options: {
|
||||
column: "adm0name",
|
||||
aggregation: "count",
|
||||
aggregationColumn: "adm0name"
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
it('should work without filters', function(done) {
|
||||
this.testClient = new TestClient(createMapConfig());
|
||||
this.testClient.getDataview('aggregation_count_dataview', { own_filter: 0 }, function(err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should work with filters', function(done) {
|
||||
var params = {
|
||||
filters: {
|
||||
dataviews: {aggregation_count_dataview: {accept: ['Canada']}}
|
||||
}
|
||||
};
|
||||
|
||||
this.testClient = new TestClient(createMapConfig());
|
||||
this.testClient.getDataview('aggregation_count_dataview', params, function(err) {
|
||||
assert.ifError(err);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error if the column used by dataview does not exist', function(done) {
|
||||
const query = 'select cartodb_id, the_geom, the_geom_webmercator from populated_places_simple_reduced';
|
||||
|
||||
const params = {
|
||||
response: {
|
||||
status: 404,
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=utf-8'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const expectedResponseBody = {
|
||||
errors:['column "adm0name" does not exist'],
|
||||
errors_with_context:[{
|
||||
type:'unknown',
|
||||
message:'column "adm0name" does not exist'
|
||||
}]
|
||||
};
|
||||
|
||||
this.testClient = new TestClient(createMapConfig(query));
|
||||
this.testClient.getDataview('aggregation_count_dataview', params, function(err, result) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual(result, expectedResponseBody);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should not fail if query does not return rows', function(done) {
|
||||
const query = 'select * from populated_places_simple_reduced limit 0';
|
||||
|
||||
const expectedResponseBody = {
|
||||
aggregation: 'count',
|
||||
count: 0,
|
||||
nulls: 0,
|
||||
nans: 0,
|
||||
infinities: 0,
|
||||
min: 0,
|
||||
max: 0,
|
||||
categoriesCount: 0,
|
||||
categories: [],
|
||||
type: 'aggregation'
|
||||
};
|
||||
|
||||
this.testClient = new TestClient(createMapConfig(query));
|
||||
this.testClient.getDataview('aggregation_count_dataview', { own_filter: 0 }, function(err, result) {
|
||||
assert.ifError(err);
|
||||
assert.deepEqual(result, expectedResponseBody);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user