Fix issue when the sql has single quotes defined and the aggregation metadata query was not able to estimate row count

This commit is contained in:
Daniel García Aubert 2017-12-14 14:14:55 +01:00
parent bcfc43a517
commit a987f6ac05
2 changed files with 51 additions and 1 deletions

View File

@ -22,7 +22,7 @@ module.exports.extractTableNames = function extractTableNames(query) {
}; };
function getQueryRowEstimation(query) { function getQueryRowEstimation(query) {
return 'select CDB_EstimateRowCount(\'' + query + '\') as rows'; return 'select CDB_EstimateRowCount($windshaft$' + query + '$windshaft$) as rows';
} }
module.exports.getQueryRowCount = getQueryRowEstimation; module.exports.getQueryRowCount = getQueryRowEstimation;

View File

@ -26,6 +26,19 @@ describe('aggregation', function () {
from generate_series(-3, 3) x from generate_series(-3, 3) x
`; `;
const POINTS_SQL_TIMESTAMP_1 = `
select
st_setsrid(st_makepoint(x*10, x*10), 4326) as the_geom,
st_transform(st_setsrid(st_makepoint(x*10, x*10), 4326), 3857) as the_geom_webmercator,
x as value,
date
from
generate_series(-3, 3) x,
generate_series(
'2007-02-15 01:00:00'::timestamp, '2007-02-18 01:00:00'::timestamp, '1 day'::interval
) date
`;
const POINTS_SQL_2 = ` const POINTS_SQL_2 = `
select select
st_setsrid(st_makepoint(x*10, x*10*(-1)), 4326) as the_geom, st_setsrid(st_makepoint(x*10, x*10*(-1)), 4326) as the_geom,
@ -479,6 +492,43 @@ describe('aggregation', function () {
done(); done();
}); });
}); });
it('should work when the sql has single quotes', function (done) {
this.mapConfig = createVectorMapConfig([
{
type: 'cartodb',
options: {
sql: `
SELECT
the_geom_webmercator,
the_geom,
value,
DATE_PART('day', date::timestamp - '1912-12-31 01:00:00'::timestamp )::numeric AS day
FROM (${POINTS_SQL_TIMESTAMP_1}) _query
`,
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();
});
});
}); });
}); });
}); });