From f8b6479254a973116cc128bf902200706f6c2d66 Mon Sep 17 00:00:00 2001 From: missinglink Date: Thu, 23 Apr 2020 19:27:38 +0200 Subject: [PATCH] feat(sqlite): add filter to remove alt-geometries --- src/components/sqliteStream.js | 7 ++++--- test/components/sqliteStream.js | 10 +++++++++- test/functional.js | 4 +--- test/generateWOFDB.js | 7 +++++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/components/sqliteStream.js b/src/components/sqliteStream.js index a3dbd350..0a6df572 100644 --- a/src/components/sqliteStream.js +++ b/src/components/sqliteStream.js @@ -27,10 +27,11 @@ class SQLiteStream extends Readable { */ function findGeoJSON() { return ` -SELECT geojson.id, geojson.body - FROM geojson JOIN spr - ON geojson.id = spr.id + SELECT geojson.id, geojson.body + FROM geojson + JOIN spr ON geojson.id = spr.id WHERE geojson.id != 1 + AND geojson.is_alt != 1 AND spr.is_deprecated = 0 AND spr.is_superseded = 0 AND NOT TRIM( IFNULL(spr.name, '') ) = '' diff --git a/test/components/sqliteStream.js b/test/components/sqliteStream.js index 05455062..69c59763 100644 --- a/test/components/sqliteStream.js +++ b/test/components/sqliteStream.js @@ -73,4 +73,12 @@ tape('SQLiteStream', (test) => { 'Should format correctly array of strings'); t.end(); }); -}); \ No newline at end of file + + test.test('Should ignore alt geometries', t => { + const msg = 'Should ignore alt geometries'; + t.ok(SQLiteStream.findGeoJSON().includes('geojson.is_alt != 1'), msg); + t.ok(SQLiteStream.findGeoJSONByPlacetype().includes('geojson.is_alt != 1'), msg); + t.ok(SQLiteStream.findGeoJSONByPlacetypeAndWOFId().includes('geojson.is_alt != 1'), msg); + t.end(); + }); +}); diff --git a/test/functional.js b/test/functional.js index 788cd7a3..b87f7422 100644 --- a/test/functional.js +++ b/test/functional.js @@ -4,8 +4,6 @@ const readStreamModule = require('../src/readStream'); const hierarchyFinder = require('../src/hierarchyFinder'); const peliasDocGenerators = require('../src/peliasDocGenerators'); const sink = require('through2-sink'); -const map_stream = require('through2-map'); -const event_stream = require('event-stream'); const temp = require('temp').track(); const generateWOFDB = require('./generateWOFDB'); const path = require('path'); @@ -57,4 +55,4 @@ tape('functional', function(test) { }); test.end(); -}); \ No newline at end of file +}); diff --git a/test/generateWOFDB.js b/test/generateWOFDB.js index 524de635..3383ce6d 100644 --- a/test/generateWOFDB.js +++ b/test/generateWOFDB.js @@ -8,10 +8,13 @@ module.exports = (dbPath, entries) => { const db = new Sqlite3(dbPath) .exec(` CREATE TABLE geojson ( - id INTEGER NOT NULL PRIMARY KEY, + id INTEGER NOT NULL, body TEXT, + source TEXT, + is_alt BOOLEAN DEFAULT 0, lastmodified INTEGER )`) + .exec(`CREATE UNIQUE INDEX IF NOT EXISTS geojson_by_id ON geojson (id, source)`) .exec(` CREATE TABLE spr ( id INTEGER NOT NULL PRIMARY KEY, @@ -55,4 +58,4 @@ module.exports = (dbPath, entries) => { }); } return db; -}; \ No newline at end of file +};