Change camshaft naming from filters

This commit is contained in:
Raul Ochoa 2016-07-06 21:11:39 +02:00
parent a7dddcebe8
commit c539d4fbbd
6 changed files with 18 additions and 18 deletions

View File

@ -1,6 +1,6 @@
var _ = require('underscore'); var _ = require('underscore');
var step = require('step'); var step = require('step');
var CamshaftFilter = require('../models/filter/camshaft'); var AnalysisFilter = require('../models/filter/analysis');
function FilterStatsApi(pgQueryRunner) { function FilterStatsApi(pgQueryRunner) {
this.pgQueryRunner = pgQueryRunner; this.pgQueryRunner = pgQueryRunner;
@ -40,8 +40,8 @@ FilterStatsApi.prototype.getFilterStats = function (username, unfiltered_query,
}, },
function getFilteredRows() { function getFilteredRows() {
if ( filters && !_.isEmpty(filters)) { if ( filters && !_.isEmpty(filters)) {
var camshaftFilter = new CamshaftFilter(filters); var analysisFilter = new AnalysisFilter(filters);
var query = camshaftFilter.sql(unfiltered_query); var query = analysisFilter.sql(unfiltered_query);
getEstimatedRows(self.pgQueryRunner, username, query, this); getEstimatedRows(self.pgQueryRunner, username, query, this);
} else { } else {
this(null, null); this(null, null);

View File

@ -1,6 +1,6 @@
var filters = { var filters = {
category: require('./camshaft/category'), category: require('./analysis/category'),
range: require('./camshaft/range') range: require('./analysis/range')
}; };
function createFilter(filterDefinition) { function createFilter(filterDefinition) {
@ -11,11 +11,11 @@ function createFilter(filterDefinition) {
return new filters[filterType](filterDefinition.column, filterDefinition.params); return new filters[filterType](filterDefinition.column, filterDefinition.params);
} }
function CamshaftFilters(filters) { function AnalysisFilters(filters) {
this.filters = filters; this.filters = filters;
} }
CamshaftFilters.prototype.sql = function(rawSql) { AnalysisFilters.prototype.sql = function(rawSql) {
var filters = this.filters || {}; var filters = this.filters || {};
var applyFilters = {}; var applyFilters = {};
@ -32,4 +32,4 @@ CamshaftFilters.prototype.sql = function(rawSql) {
}, rawSql); }, rawSql);
}; };
module.exports = CamshaftFilters; module.exports = AnalysisFilters;

View File

@ -6,7 +6,7 @@ dot.templateSettings.strip = false;
var filterQueryTpl = dot.template([ var filterQueryTpl = dot.template([
'SELECT *', 'SELECT *',
'FROM ({{=it._sql}}) _camshaft_category_filter', 'FROM ({{=it._sql}}) _analysis_category_filter',
'WHERE {{=it._filters}}' 'WHERE {{=it._filters}}'
].join('\n')); ].join('\n'));
var escapeStringTpl = dot.template('$escape_{{=it._i}}${{=it._value}}$escape_{{=it._i}}$'); var escapeStringTpl = dot.template('$escape_{{=it._i}}${{=it._value}}$escape_{{=it._i}}$');

View File

@ -6,7 +6,7 @@ dot.templateSettings.strip = false;
var betweenFilterTpl = dot.template('{{=it._column}} BETWEEN {{=it._min}} AND {{=it._max}}'); var betweenFilterTpl = dot.template('{{=it._column}} BETWEEN {{=it._min}} AND {{=it._max}}');
var minFilterTpl = dot.template('{{=it._column}} >= {{=it._min}}'); var minFilterTpl = dot.template('{{=it._column}} >= {{=it._min}}');
var maxFilterTpl = dot.template('{{=it._column}} <= {{=it._max}}'); var maxFilterTpl = dot.template('{{=it._column}} <= {{=it._max}}');
var filterQueryTpl = dot.template('SELECT * FROM ({{=it._sql}}) _camshaft_range_filter WHERE {{=it._filter}}'); var filterQueryTpl = dot.template('SELECT * FROM ({{=it._sql}}) _analysis_range_filter WHERE {{=it._filter}}');
function Range(column, filterParams) { function Range(column, filterParams) {
this.column = column; this.column = column;

View File

@ -2,7 +2,7 @@ var _ = require('underscore');
var TableNameParser = require('./table_name_parser'); var TableNameParser = require('./table_name_parser');
var BBoxFilter = require('../models/filter/bbox'); var BBoxFilter = require('../models/filter/bbox');
var CamshaftFilter = require('../models/filter/camshaft'); var AnalysisFilter = require('../models/filter/analysis');
// Minimim number of filtered rows to use overviews // Minimim number of filtered rows to use overviews
var FILTER_MIN_ROWS = 65536; var FILTER_MIN_ROWS = 65536;
@ -11,8 +11,8 @@ var FILTER_MAX_FRACTION = 0.2;
function apply_filters_to_query(query, filters, bbox_filter) { function apply_filters_to_query(query, filters, bbox_filter) {
if ( filters && !_.isEmpty(filters)) { if ( filters && !_.isEmpty(filters)) {
var camshaftFilter = new CamshaftFilter(filters); var analysisFilter = new AnalysisFilter(filters);
query = camshaftFilter.sql(query); query = analysisFilter.sql(query);
} }
if ( bbox_filter ) { if ( bbox_filter ) {
var bboxFilter = new BBoxFilter(bbox_filter.options, bbox_filter.params); var bboxFilter = new BBoxFilter(bbox_filter.options, bbox_filter.params);

View File

@ -527,7 +527,7 @@ describe('Overviews query rewriter', function() {
it('generates query with filters', function(){ it('generates query with filters', function(){
var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\ var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\
FROM (SELECT *\ FROM (SELECT *\
FROM (select * from table1) _camshaft_category_filter\ FROM (select * from table1) _analysis_category_filter\
WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query"; WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query";
var data = { var data = {
overviews: { overviews: {
@ -555,7 +555,7 @@ describe('Overviews query rewriter', function() {
SELECT * FROM table1_ov3, _vovw_scale WHERE _vovw_z = 3\ SELECT * FROM table1_ov3, _vovw_scale WHERE _vovw_z = 3\
UNION ALL\ UNION ALL\
SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 3\ SELECT * FROM table1, _vovw_scale WHERE _vovw_z > 3\
) AS _vovw_table1) _camshaft_category_filter\ ) AS _vovw_table1) _analysis_category_filter\
WHERE name IN ($escape_0$X$escape_0$)\ WHERE name IN ($escape_0$X$escape_0$)\
"; ";
assertSameSql(overviews_sql, expected_sql); assertSameSql(overviews_sql, expected_sql);
@ -564,7 +564,7 @@ describe('Overviews query rewriter', function() {
it('generates query with filters for specific zoom level', function(){ it('generates query with filters for specific zoom level', function(){
var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\ var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\
FROM (SELECT *\ FROM (SELECT *\
FROM (select * from table1) _camshaft_category_filter\ FROM (select * from table1) _analysis_category_filter\
WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query"; WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query";
var data = { var data = {
overviews: { overviews: {
@ -581,7 +581,7 @@ describe('Overviews query rewriter', function() {
}; };
var overviews_sql = overviewsQueryRewriter.query(sql, data, { zoom_level: 2 }); var overviews_sql = overviewsQueryRewriter.query(sql, data, { zoom_level: 2 });
var expected_sql = "\ var expected_sql = "\
SELECT * FROM (SELECT * FROM table1_ov2) _camshaft_category_filter\ SELECT * FROM (SELECT * FROM table1_ov2) _analysis_category_filter\
WHERE name IN ($escape_0$X$escape_0$)\ WHERE name IN ($escape_0$X$escape_0$)\
"; ";
assertSameSql(overviews_sql, expected_sql); assertSameSql(overviews_sql, expected_sql);
@ -590,7 +590,7 @@ describe('Overviews query rewriter', function() {
it('does not generates query with aggressive filtering', function(){ it('does not generates query with aggressive filtering', function(){
var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\ var sql = "SELECT ST_Transform(the_geom, 3857) the_geom_webmercator, cartodb_id, name\
FROM (SELECT *\ FROM (SELECT *\
FROM (select * from table1) _camshaft_category_filter\ FROM (select * from table1) _analysis_category_filter\
WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query"; WHERE name IN ($escape_0$X$escape_0$)) _cdb_analysis_query";
var data = { var data = {
overviews: { overviews: {