Merge pull request #991 from CartoDB/fix-numeric-histogram-bounds
Fix numeric histogram bounds
This commit is contained in:
@@ -45,6 +45,7 @@ Bug Fixes:
|
||||
- Static maps fails for unsupported formats
|
||||
- Handling errors extracting the column type on dataviews
|
||||
- Fix `meta.stats.estimatedFeatureCount` for aggregations and queries with tokens
|
||||
- Fix numeric histogram bounds when `start` and `end` are specified (#991)
|
||||
- Static maps filters correctly if `layer` option is passed in the url.
|
||||
|
||||
Announcements:
|
||||
|
||||
@@ -99,8 +99,14 @@ module.exports = class NumericHistogram extends BaseHistogram {
|
||||
var extra_tables = ``;
|
||||
var extra_queries = ``;
|
||||
var extra_groupby = ``;
|
||||
var extra_filter = ``;
|
||||
|
||||
if (ctx.start >= ctx.end) {
|
||||
if (ctx.start < ctx.end) {
|
||||
extra_filter = `
|
||||
WHERE __ctx_query.${ctx.column} >= ${ctx.start}
|
||||
AND __ctx_query.${ctx.column} <= ${ctx.end}
|
||||
`;
|
||||
} else {
|
||||
ctx.end = `__cdb_basics.__cdb_max_val`;
|
||||
ctx.start = `__cdb_basics.__cdb_min_val`;
|
||||
extra_groupby = `, __cdb_basics.__cdb_max_val, __cdb_basics.__cdb_min_val`;
|
||||
@@ -135,7 +141,7 @@ SELECT
|
||||
END AS bin
|
||||
FROM
|
||||
(
|
||||
${ctx.query}
|
||||
SELECT * FROM (${ctx.query}) __ctx_query${extra_tables} ${extra_filter}
|
||||
) __cdb_filtered_source_query${extra_tables}
|
||||
GROUP BY 10${extra_groupby}
|
||||
ORDER BY 10;`;
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
#!/bin/bash
|
||||
|
||||
OPT_CREATE_REDIS=yes # create the redis test environment
|
||||
OPT_CREATE_PGSQL=yes # create the PostgreSQL test environment
|
||||
|
||||
@@ -67,6 +67,27 @@ describe('histogram-dataview', function() {
|
||||
]
|
||||
);
|
||||
|
||||
it('should get bins with min >= start and max <= end', function(done) {
|
||||
var params = {
|
||||
bins: 3,
|
||||
start: 50,
|
||||
end: 500
|
||||
};
|
||||
|
||||
this.testClient = new TestClient(mapConfig, 1234);
|
||||
this.testClient.getDataview('pop_max_histogram', params, function(err, dataview) {
|
||||
assert.ok(!err, err);
|
||||
|
||||
assert.ok(3 === dataview.bins_count, 'Unexpected bin count: ' + dataview.bins_count);
|
||||
assert.ok(3 === dataview.bins.length, 'Unexpected number of bins: ' + dataview.bins.length);
|
||||
dataview.bins.forEach(function(bin) {
|
||||
assert.ok(bin.min >= params.start, 'bin min < start: ' + JSON.stringify(bin));
|
||||
assert.ok(bin.max <= params.end, 'bin max > end: ' + JSON.stringify(bin));
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get bin_width right when max > min in filter', function(done) {
|
||||
var params = {
|
||||
bins: 10,
|
||||
|
||||
Reference in New Issue
Block a user