Analysis layers can have a sql_wrap option to wrap node queries
This commit is contained in:
parent
e4ba68850c
commit
7d4caf6974
@ -139,7 +139,12 @@ AnalysisMapConfigAdapter.prototype.getMapConfig = function(analysisConfiguration
|
|||||||
var layerSourceId = getLayerSourceId(layer);
|
var layerSourceId = getLayerSourceId(layer);
|
||||||
var layerNode = sourceId2Node[layerSourceId];
|
var layerNode = sourceId2Node[layerSourceId];
|
||||||
if (layerNode) {
|
if (layerNode) {
|
||||||
layer.options.sql = layerQuery(layerNode.getQuery(), layerNode.getColumns());
|
var analysisSql = layerQuery(layerNode.getQuery(), layerNode.getColumns());
|
||||||
|
var sqlQueryWrap = layer.options.sql_wrap;
|
||||||
|
if (sqlQueryWrap) {
|
||||||
|
analysisSql = sqlQueryWrap.replace(/<%=\s*__analysis_query\s*%>/g, analysisSql);
|
||||||
|
}
|
||||||
|
layer.options.sql = analysisSql;
|
||||||
var layerDataviews = getLayerDataviews(layer, dataviews);
|
var layerDataviews = getLayerDataviews(layer, dataviews);
|
||||||
layer.options.columns = layerDataviews.reduce(function(columns, dataview) {
|
layer.options.columns = layerDataviews.reduce(function(columns, dataview) {
|
||||||
return columns.concat(getDataviewColumns(dataview));
|
return columns.concat(getDataviewColumns(dataview));
|
||||||
|
@ -327,4 +327,44 @@ describe('analysis-layers', function() {
|
|||||||
testClient.drain(done);
|
testClient.drain(done);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should wrap queries from analyses', function(done) {
|
||||||
|
var testClient = new TestClient(mapConfig(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"type": "cartodb",
|
||||||
|
"options": {
|
||||||
|
"source": {
|
||||||
|
"id": "2570e105-7b37-40d2-bdf4-1af889598745"
|
||||||
|
},
|
||||||
|
"sql_wrap": "SELECT * FROM (<%= __analysis_query %>) __wrapped WHERE adm0cap = 1",
|
||||||
|
"cartocss": DEFAULT_MULTITYPE_STYLE,
|
||||||
|
"cartocss_version": "2.3.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
{},
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"id": "2570e105-7b37-40d2-bdf4-1af889598745",
|
||||||
|
"type": "source",
|
||||||
|
"params": {
|
||||||
|
"query": "select * from populated_places_simple_reduced"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
), 1234);
|
||||||
|
|
||||||
|
var tile = TILE_ANALYSIS_TABLES;
|
||||||
|
testClient.getTile(tile.z, tile.x, tile.y, function(err, res, image) {
|
||||||
|
assert.ok(!err, err);
|
||||||
|
|
||||||
|
var fixturePath = './test/fixtures/analysis/adm0cap-source-id-mapnik-layer.png';
|
||||||
|
assert.imageIsSimilarToFile(image, fixturePath, IMAGE_TOLERANCE_PER_MIL, function(err) {
|
||||||
|
assert.ok(!err, err);
|
||||||
|
|
||||||
|
testClient.drain(done);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
BIN
test/fixtures/analysis/adm0cap-source-id-mapnik-layer.png
vendored
Normal file
BIN
test/fixtures/analysis/adm0cap-source-id-mapnik-layer.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 KiB |
Loading…
Reference in New Issue
Block a user