Add tests for query rewriter with filters
This commit is contained in:
parent
858d976637
commit
3987e83b7a
@ -523,4 +523,89 @@ describe('Overviews query rewriter', function() {
|
||||
var expected_sql = "SELECT * FROM table1";
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
});
|
||||
|
||||
it('generates query with filters', function(){
|
||||
var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\
|
||||
FROM (SELECT *\
|
||||
FROM (select * from table1) _camshaft_category_filter\
|
||||
WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query";
|
||||
var data = {
|
||||
overviews: {
|
||||
table1: {
|
||||
0: { table: 'table1_ov0' },
|
||||
1: { table: 'table1_ov1' },
|
||||
2: { table: 'table1_ov2' },
|
||||
3: { table: 'table1_ov3' }
|
||||
}
|
||||
},
|
||||
filters: { name_filter: { type: 'category', column: 'name', params: { accept: [ 'X' ] } } },
|
||||
unfiltered_query: 'SELECT * FROM table1'
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
var expected_sql = "\
|
||||
SELECT * FROM (WITH\
|
||||
_vovw_scale AS ( SELECT ZoomLevel() AS _vovw_z )\
|
||||
SELECT * FROM (\
|
||||
SELECT * FROM table1_ov0, _vovw_scale WHERE _vovw_z = 0\
|
||||
UNION ALL\
|
||||
SELECT * FROM table1_ov1, _vovw_scale WHERE _vovw_z = 1\
|
||||
UNION ALL\
|
||||
SELECT * FROM table1_ov2, _vovw_scale WHERE _vovw_z = 2\
|
||||
UNION ALL\
|
||||
SELECT * FROM table1_ov3, _vovw_scale WHERE _vovw_z = 3\
|
||||
UNION ALL\
|
||||
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 3\
|
||||
) AS _vovw_table1) _camshaft_category_filter\
|
||||
WHERE name IN ($escape_0$X$escape_0$)\
|
||||
";
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
});
|
||||
|
||||
it('generates query with filters for specific zoom level', function(){
|
||||
var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\
|
||||
FROM (SELECT *\
|
||||
FROM (select * from table1) _camshaft_category_filter\
|
||||
WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query";
|
||||
var data = {
|
||||
overviews: {
|
||||
table1: {
|
||||
0: { table: 'table1_ov0' },
|
||||
1: { table: 'table1_ov1' },
|
||||
2: { table: 'table1_ov2' },
|
||||
3: { table: 'table1_ov3' }
|
||||
}
|
||||
},
|
||||
filters: { name_filter: { type: 'category', column: 'name', params: { accept: [ 'X' ] } } },
|
||||
unfiltered_query: 'SELECT * FROM table1',
|
||||
filter_stats: { unfiltered_rows: 1000, filtered_rows: 900 }
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data, { zoom_level: 2 });
|
||||
var expected_sql = "\
|
||||
SELECT * FROM (SELECT * FROM table1_ov2) _camshaft_category_filter\
|
||||
WHERE name IN ($escape_0$X$escape_0$)\
|
||||
";
|
||||
assertSameSql(overviews_sql, expected_sql);
|
||||
});
|
||||
|
||||
it('does not generates query with aggressive filtering', function(){
|
||||
var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\
|
||||
FROM (SELECT *\
|
||||
FROM (select * from table1) _camshaft_category_filter\
|
||||
WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query";
|
||||
var data = {
|
||||
overviews: {
|
||||
table1: {
|
||||
0: { table: 'table1_ov0' },
|
||||
1: { table: 'table1_ov1' },
|
||||
2: { table: 'table1_ov2' },
|
||||
3: { table: 'table1_ov3' }
|
||||
}
|
||||
},
|
||||
filters: { name_filter: { type: 'category', column: 'name', params: { accept: [ 'X' ] } } },
|
||||
unfiltered_query: 'SELECT * FROM table1',
|
||||
filter_stats: { unfiltered_rows: 1000, filtered_rows: 10 }
|
||||
};
|
||||
var overviews_sql = overviewsQueryRewriter.query(sql, data);
|
||||
assert.equal(overviews_sql, sql);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user