Various fixes

This avoids errors when trying to wrap dates or detect wrapped dates in non-mapnik layers
This commit is contained in:
Javier Goizueta 2018-06-12 12:05:31 +02:00
parent 251570b638
commit 4a52620d83
3 changed files with 20 additions and 15 deletions

View File

@ -28,7 +28,7 @@ class VectorMapConfigAdapter {
} }
_wrapLayer(layer, user) { _wrapLayer(layer, user) {
if (!layer.options.dates_as_numbers) { if (!layer.options.dates_as_numbers || !layer.options.sql) {
return Promise.resolve(layer); return Promise.resolve(layer);
} }
const originalQuery = layer.options.sql; const originalQuery = layer.options.sql;

View File

@ -35,17 +35,19 @@ function _castColumnToEpoch(columnName) {
} }
function wrappedDates(query) { function wrappedDates(query) {
if (query.match(/\b_cdb_epoch_transformation\b/)) { if (query) {
const columns = []; if (query.match(/\b_cdb_epoch_transformation\b/)) {
const fieldMatcher = /\bdate_part\('epoch', "([^"]+)"\) as "([^"]+)"/gmi; const columns = [];
let match; const fieldMatcher = /\bdate_part\('epoch', "([^"]+)"\) as "([^"]+)"/gmi;
do { let match;
match = fieldMatcher.exec(query); do {
if (match && match[1] === match[2]) { match = fieldMatcher.exec(query);
columns.push(match[1]); if (match && match[1] === match[2]) {
} columns.push(match[1]);
} while (match); }
return columns; } while (match);
return columns;
}
} }
} }

View File

@ -172,9 +172,12 @@ module.exports = class LayergroupMetadata {
if (layergroup.metadata && Array.isArray(layergroup.metadata.layers) && Array.isArray(mapConfig.layers)) { if (layergroup.metadata && Array.isArray(layergroup.metadata.layers) && Array.isArray(mapConfig.layers)) {
layergroup.metadata.layers = layergroup.metadata.layers.map(function(layer, layerIndex) { layergroup.metadata.layers = layergroup.metadata.layers.map(function(layer, layerIndex) {
const mapConfigLayer = mapConfig.layers[layerIndex]; const mapConfigLayer = mapConfig.layers[layerIndex];
const wrappedColumns = dateWrapper.wrappedDates(mapConfigLayer.options.sql); const layerOptions = mapConfigLayer.options;
if (wrappedColumns) { if (layerOptions.dates_as_numbers && layerOptions.sql) {
layer.meta.dates_as_numbers = wrappedColumns; const wrappedColumns = dateWrapper.wrappedDates(layerOptions.sql);
if (wrappedColumns) {
layer.meta.dates_as_numbers = wrappedColumns;
}
} }
return layer; return layer;
}); });