Overpass API regression suite coverage (Nova Scotia) / overpass_api/statements/query.cc

overpass_api/statements/query.cc

910 of 1124 instrumented lines run by the suite (81.0%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#include "../../template_db/block_backend.h"
20#include "../../template_db/random_file.h"
21#include "../core/settings.h"
22#include "../data/abstract_processing.h"
23#include "../data/collect_members.h"
24#include "../data/filenames.h"
25#include "../data/filter_by_tags.h"
26#include "../data/filter_ids_by_tags.h"
27#include "../data/meta_collector.h"
28#include "../data/regular_expression.h"
29#include "../data/tags_global_reader.h"
30#include "area_query.h"
31#include "bbox_query.h"
32#include "query.h"
34#include <algorithm>
35#include <sstream>
38//-----------------------------------------------------------------------------
40bool Query_Statement::area_query_exists_ = false;
42Generic_Statement_Maker< Query_Statement > Query_Statement::statement_maker("query");
44Query_Statement::Query_Statement
45 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
462306522 q : Output_Statement(line_number_), global_bbox_statement(0)
472306522 q{
482306522 q std::map< std::string, std::string > attributes;
502306522 q attributes["into"] = "_";
512306522 q attributes["type"] = "";
532306522 q eval_attributes_array(get_name(), attributes, input_attributes);
552306522 q set_output(attributes["into"]);
562306522 q if (attributes["type"] == "node")
57348108 q type = QUERY_NODE;
581958470 q else if (attributes["type"] == "way")
59465133 q type = QUERY_WAY;
601493394 q else if (attributes["type"] == "relation")
61412120 q type = QUERY_RELATION;
621081311 q else if (attributes["type"] == "derived")
630 type = QUERY_DERIVED;
641081311 q else if (attributes["type"] == "nwr")
65426133 q type = (QUERY_NODE | QUERY_WAY | QUERY_RELATION);
66655208 q else if (attributes["type"] == "nw")
6729799 q type = (QUERY_NODE | QUERY_WAY);
68358113 q else if (attributes["type"] == "wr")
6919665 q type = (QUERY_WAY | QUERY_RELATION);
7016249 q else if (attributes["type"] == "nr")
710 type = (QUERY_NODE | QUERY_RELATION);
7216249 q else if (attributes["type"] == "area")
7315948 q {
7415948 q type = QUERY_AREA | QUERY_WAY | QUERY_CLOSED_WAY;
7515948 q area_query_exists_ = true;
7615948 q }
7731 q else
7931 q type = 0;
8031 q std::ostringstream temp;
8131 q temp<<"For the attribute \"type\" of the element \"query\""
8231 q <<" the only allowed values are \"node\", \"way\", \"relation\", \"nwr\", \"nw\", \"wr\", \"nr\", or \"area\".";
8331 q add_static_error(temp.str());
862306522 q if (global_settings.get_global_bbox_limitation().valid())
873318 q {
883318 q global_bbox_statement = new Bbox_Query_Statement(global_settings.get_global_bbox_limitation());
893318 q constraints.push_back(global_bbox_statement->get_query_constraint());
903318 q }
912306522 q}
94Query_Statement::~Query_Statement()
952306522 q{
962306522 q delete global_bbox_statement;
972306522 q}
100void Query_Statement::add_statement(Statement* statement, std::string text)
1023423518 q assure_no_text(text, this->get_name());
1043423518 q Has_Kv_Statement* has_kv(dynamic_cast<Has_Kv_Statement*>(statement));
1053423518 q if (has_kv)
1061599333 q {
1071599333 q substatements.push_back(statement);
1091599333 q if (has_kv->get_value() != "")
111915233 q if (has_kv->get_straight())
112771207 q key_values.push_back(std::make_pair< std::string, std::string >
113771207 q (has_kv->get_key(), has_kv->get_value()));
11414445 q else
11514445 q key_nvalues.push_back(std::make_pair< std::string, std::string >
11614445 q (has_kv->get_key(), has_kv->get_value()));
118684166 q else if (has_kv->get_key_regex())
11914442 q {
12014442 q if (has_kv->get_straight())
12114442 q regkey_regexes.push_back(std::make_pair< Regular_Expression*, Regular_Expression* >
12214442 q (has_kv->get_key_regex(), has_kv->get_regex()));
1230 else
1240 regkey_nregexes.push_back(std::make_pair< Regular_Expression*, Regular_Expression* >
1250 (has_kv->get_key_regex(), has_kv->get_regex()));
12614442 q }
127540135 q else if (has_kv->get_regex())
12832190 q {
12932190 q if (has_kv->get_straight())
13014141 q key_regexes.push_back(std::make_pair< std::string, Regular_Expression* >
13114141 q (has_kv->get_key(), has_kv->get_regex()));
13218053 q else
13318053 q key_nregexes.push_back(std::make_pair< std::string, Regular_Expression* >
13418053 q (has_kv->get_key(), has_kv->get_regex()));
13532190 q }
13621959 q else
13721959 q keys.push_back(has_kv->get_key());
1381599333 q return;
1391599333 q }
1411824405 q Query_Constraint* constraint = statement->get_query_constraint();
1421824405 q if (constraint)
1431824405 q {
1441824405 q constraints.push_back(constraint);
1451824405 q substatements.push_back(statement);
1461824405 q }
1470 else
1480 substatement_error(get_name(), statement);
152void Query_Statement::get_elements_by_id_from_db
153 (std::map< Uint31_Index, std::vector< Area_Skeleton > >& elements,
154 const std::vector< Area_Skeleton::Id_Type >& ids, bool invert_ids,
155 Resource_Manager& rman, File_Properties& file_prop)
1575145 q Request_Context context(this, rman);
1585145 q if (!invert_ids)
1595044 q collect_items_flat(context, file_prop,
1605044 q Id_Predicate< Area_Skeleton >(ids), elements);
16111 q else
16211 q collect_items_flat(context, file_prop,
16311 q Not_Predicate< Area_Skeleton, Id_Predicate< Area_Skeleton > >
16411 q (Id_Predicate< Area_Skeleton >(ids)), elements);
168template< typename TIndex, typename TObject >
169void clear_empty_indices
170 (std::map< TIndex, std::vector< TObject > >& modify)
1726153507 q for (typename std::map< TIndex, std::vector< TObject > >::iterator it = modify.begin();
1733534487507 q it != modify.end();)
1743529096442 q {
1753529096442 q if (!it->second.empty())
1761366352400 q {
1771366352400 q ++it;
1781366352400 q continue;
1791366352400 q }
1802162744334 q typename std::map< TIndex, std::vector< TObject > >::iterator next_it = it;
1812162744334 q if (++next_it == modify.end())
183762303 q modify.erase(it);
184762303 q break;
1862161982320 q else
1872161982320 q {
1882161982320 q TIndex idx = next_it->first;
1892161982320 q modify.erase(it);
1902161982320 q it = modify.find(idx);
1912161982320 q }
1922162744334 q }
196template< typename Id_Type >
197void filter_ids_by_ntags
198 (const std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > >& keys,
199 const Block_Backend< Tag_Index_Local, Id_Type >& items_db,
200 typename Block_Backend< Tag_Index_Local, Id_Type >::Range_Iterator& tag_it,
201 uint32 coarse_index,
202 std::vector< Id_Type >& new_ids)
203127725 q{
204127725 q std::vector< Id_Type > removed_ids;
205127725 q std::string last_key, last_value;
206127725 q bool key_relevant = false;
207127725 q bool valid = false;
208127725 q std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > >::const_iterator
209127725 q key_it = keys.begin();
211525748525 q while ((!(tag_it == items_db.range_end())) &&
212525748525 q (((tag_it.index().index) & 0x7fffff00) == coarse_index))
213525740424 q {
214525740424 q if (tag_it.index().key != last_key)
2154443024 q {
2164443024 q last_value = void_tag_value() + " ";
2184443024 q if (key_relevant)
21988015 q {
22088015 q ++key_it;
22188015 q sort(removed_ids.begin(), removed_ids.end());
22288015 q removed_ids.erase(unique(removed_ids.begin(), removed_ids.end()), removed_ids.end());
22388015 q new_ids.erase(set_difference(new_ids.begin(), new_ids.end(),
22488015 q removed_ids.begin(), removed_ids.end(), new_ids.begin()), new_ids.end());
22588015 q }
2264443024 q key_relevant = false;
2284443024 q last_key = tag_it.index().key;
2294483324 q while (key_it != keys.end() && last_key > key_it->first)
23040322 q ++key_it;
2324443024 q if (key_it == keys.end())
233119624 q break;
2354323424 q if (last_key == key_it->first)
23688015 q {
23788015 q key_relevant = true;
23888015 q removed_ids.clear();
23988015 q }
2404323424 q }
242525620824 q if (key_relevant)
2438087515 q {
2448087515 q if (tag_it.index().value != last_value)
245369215 q {
246369215 q valid = false;
247369215 q for (std::vector< Regular_Expression* >::const_iterator rit = key_it->second.first.begin();
248397615 q rit != key_it->second.first.end(); ++rit)
2492849 q valid |= (tag_it.index().value != void_tag_value() && (*rit)->matches(tag_it.index().value));
250369215 q for (std::vector< std::string >::const_iterator rit = key_it->second.second.begin();
251715715 q rit != key_it->second.second.end(); ++rit)
25234656 q valid |= (*rit == tag_it.index().value);
253369215 q last_value = tag_it.index().value;
254369215 q }
2568087515 q if (valid)
257281212 q removed_ids.push_back(tag_it.object());
2588087515 q }
260525620824 q ++tag_it;
261525620824 q }
262120402225 q while ((!(tag_it == items_db.range_end())) &&
263120402225 q (((tag_it.index().index) & 0x7fffff00) == coarse_index))
264120274524 q ++tag_it;
266127725 q sort(removed_ids.begin(), removed_ids.end());
267127725 q removed_ids.erase(unique(removed_ids.begin(), removed_ids.end()), removed_ids.end());
268127725 q new_ids.erase(set_difference(new_ids.begin(), new_ids.end(),
269127725 q removed_ids.begin(), removed_ids.end(), new_ids.begin()), new_ids.end());
271127725 q sort(new_ids.begin(), new_ids.end());
272127725 q}
275template< typename Id_Type >
276void filter_ids_by_ntags
277 (const std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > >& keys,
278 uint64 timestamp,
279 const Block_Backend< Tag_Index_Local, Id_Type >& items_db,
280 typename Block_Backend< Tag_Index_Local, Id_Type >::Range_Iterator& tag_it,
281 const Block_Backend< Tag_Index_Local, Attic< Id_Type > >& attic_items_db,
282 typename Block_Backend< Tag_Index_Local, Attic< Id_Type > >::Range_Iterator& attic_tag_it,
283 uint32 coarse_index,
284 std::vector< Id_Type >& new_ids)
285387527 q{
286387527 q for (std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > >::const_iterator
287807227 q key_it = keys.begin(); key_it != keys.end(); ++key_it)
288419727 q {
289419727 q std::map< Id_Type, std::pair< uint64, uint64 > > timestamps;
290345291827 q for (typename std::vector< Id_Type >::const_iterator it = new_ids.begin(); it != new_ids.end(); ++it)
291344872123 q timestamps[*it];
293384368727 q while ((!(tag_it == items_db.range_end())) &&
294384368727 q ((tag_it.index().index) & 0x7fffff00) == coarse_index &&
295384368727 q tag_it.index().key < key_it->first)
296383949026 q ++tag_it;
297665451827 q while ((!(attic_tag_it == attic_items_db.range_end())) &&
298665451827 q ((attic_tag_it.index().index) & 0x7fffff00) == coarse_index &&
299665451827 q attic_tag_it.index().key < key_it->first)
300665032127 q ++attic_tag_it;
302419727 q bool valid = false;
303419727 q std::string last_value = void_tag_value() + " ";
30410101127 q while ((!(tag_it == items_db.range_end())) &&
30510101127 q ((tag_it.index().index) & 0x7fffff00) == coarse_index &&
30610101127 q tag_it.index().key == key_it->first)
3079681420 q {
3089681420 q if (std::binary_search(new_ids.begin(), new_ids.end(), tag_it.object()))
309518312 q {
310518312 q std::pair< uint64, uint64 >& timestamp_ref = timestamps[tag_it.object()];
311518312 q timestamp_ref.second = NOW;
313518312 q if (tag_it.index().value != last_value)
314108712 q {
315108712 q valid = false;
316108712 q for (std::vector< Regular_Expression* >::const_iterator rit = key_it->second.first.begin();
317124112 q rit != key_it->second.first.end(); ++rit)
31815411 q valid |= (tag_it.index().value != void_tag_value() && (*rit)->matches(tag_it.index().value));
319108712 q for (std::vector< std::string >::const_iterator rit = key_it->second.second.begin();
320202012 q rit != key_it->second.second.end(); ++rit)
3219333 q valid |= (*rit == tag_it.index().value);
322108712 q last_value = tag_it.index().value;
323108712 q }
325518312 q if (valid)
32644810 q timestamp_ref.first = NOW;
327518312 q }
3289681420 q ++tag_it;
3299681420 q }
331419727 q last_value = void_tag_value() + " ";
33214834927 q while ((!(attic_tag_it == attic_items_db.range_end())) &&
33314834927 q ((attic_tag_it.index().index) & 0x7fffff00) == coarse_index &&
33414834927 q attic_tag_it.index().key == key_it->first)
33514415222 q {
33614415222 q if (std::binary_search(new_ids.begin(), new_ids.end(), Id_Type(attic_tag_it.object())))
3375112312 q {
3385112312 q std::pair< uint64, uint64 >& timestamp_ref = timestamps[attic_tag_it.object()];
3395112312 q if (timestamp < attic_tag_it.object().timestamp &&
3405112312 q (timestamp_ref.second == 0 || timestamp_ref.second > attic_tag_it.object().timestamp))
34126207 q timestamp_ref.second = attic_tag_it.object().timestamp;
3435112312 q if (attic_tag_it.index().value != last_value)
34496812 q {
34596812 q valid = false;
34696812 q if (attic_tag_it.index().value != void_tag_value())
34763211 q {
34863211 q for (std::vector< Regular_Expression* >::const_iterator rit = key_it->second.first.begin();
34979211 q rit != key_it->second.first.end(); ++rit)
3501609 q valid |= (attic_tag_it.index().value != void_tag_value()
3511609 q && (*rit)->matches(attic_tag_it.index().value));
35263211 q for (std::vector< std::string >::const_iterator rit = key_it->second.second.begin();
353110411 q rit != key_it->second.second.end(); ++rit)
3544723 q valid |= (*rit == attic_tag_it.index().value);
35563211 q }
35696812 q last_value = attic_tag_it.index().value;
35796812 q }
3595112312 q if (valid && timestamp < attic_tag_it.object().timestamp &&
3605112312 q (timestamp_ref.first == 0 || timestamp_ref.first > attic_tag_it.object().timestamp))
3613736 q timestamp_ref.first = attic_tag_it.object().timestamp;
3625112312 q }
36314415222 q ++attic_tag_it;
36414415222 q }
366419727 q new_ids.clear();
367419727 q new_ids.reserve(timestamps.size());
368419727 q for (typename std::map< Id_Type, std::pair< uint64, uint64 > >::const_iterator
369345291827 q it = timestamps.begin(); it != timestamps.end(); ++it)
370344872123 q {
371344872123 q if (!(0 < it->second.first && it->second.first <= it->second.second))
372344841823 q new_ids.push_back(it->first);
373344872123 q }
374419727 q }
375126499127 q while ((!(tag_it == items_db.range_end())) &&
376126499127 q ((tag_it.index().index) & 0x7fffff00) == coarse_index)
377126111626 q ++tag_it;
378336843927 q while ((!(attic_tag_it == attic_items_db.range_end())) &&
379336843927 q ((attic_tag_it.index().index) & 0x7fffff00) == coarse_index)
380336456427 q ++attic_tag_it;
381387527 q}
384template< class TIndex, class TObject >
385void filter_by_ids(
386 const std::map< uint32, std::vector< typename TObject::Id_Type > >& ids_by_coarse,
387 std::map< TIndex, std::vector< TObject > >& items,
388 std::map< TIndex, std::vector< Attic< TObject > > >* attic_items)
390606154 q std::map< TIndex, std::vector< TObject > > result;
391606154 q std::map< TIndex, std::vector< Attic< TObject > > > attic_result;
393606154 q typename std::map< TIndex, std::vector< TObject > >::const_iterator item_it = items.begin();
395606154 q if (!attic_items)
3960 {
3970 for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::const_iterator
3980 it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
3990 {
4000 while ((item_it != items.end()) &&
4010 ((item_it->first.val() & 0x7fffff00) == it->first))
4020 {
4030 for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
4040 eit != item_it->second.end(); ++eit)
4050 {
4060 if (std::binary_search(it->second.begin(), it->second.end(), eit->id))
4070 result[item_it->first.val()].push_back(*eit);
4080 }
4090 ++item_it;
4100 }
4110 }
4120 }
413606154 q else
415606154 q typename std::map< TIndex, std::vector< Attic< TObject > > >::const_iterator attic_item_it
416606154 q = attic_items->begin();
418606154 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::const_iterator
41910247154 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
4209641118 q {
421473905118 q while ((item_it != items.end()) &&
422473905118 q ((item_it->first.val() & 0x7fffff00) == it->first))
423464264115 q {
424464264115 q for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
42529677164115 q eit != item_it->second.end(); ++eit)
4262921290087 q {
4272921290087 q if (std::binary_search(it->second.begin(), it->second.end(), eit->id))
428348820367 q result[item_it->first.val()].push_back(*eit);
4292921290087 q }
430464264115 q ++item_it;
431464264115 q }
433109943118 q while ((attic_item_it != attic_items->end()) &&
434109943118 q ((attic_item_it->first.val() & 0x7fffff00) == it->first))
43510030262 q {
43610030262 q for (typename std::vector< Attic< TObject > >::const_iterator eit = attic_item_it->second.begin();
43729326162 q eit != attic_item_it->second.end(); ++eit)
43819295934 q {
43919295934 q if (std::binary_search(it->second.begin(), it->second.end(), eit->id))
44016674627 q attic_result[attic_item_it->first.val()].push_back(*eit);
44119295934 q }
44210030262 q ++attic_item_it;
44310030262 q }
4449641118 q }
447606154 q items.swap(result);
448606154 q if (attic_items)
449606154 q attic_items->swap(attic_result);
453template< class TIndex, class TObject >
454void Query_Statement::filter_by_tags
455 (std::map< TIndex, std::vector< TObject > >& items,
456 std::map< TIndex, std::vector< Attic< TObject > > >* attic_items,
457 uint64 timestamp, const File_Properties& file_prop, const File_Properties* attic_file_prop,
458 Resource_Manager& rman, Transaction& transaction)
4601629378 q if (keys.empty() && key_values.empty() && key_regexes.empty() && regkey_regexes.empty()
4611629378 q && key_nregexes.empty() && key_nvalues.empty())
4621023272 q return;
464 // generate set of relevant coarse indices
465606154 q std::map< uint32, std::vector< typename TObject::Id_Type > > ids_by_coarse;
466606154 q generate_ids_by_coarse(ids_by_coarse, items);
467606154 q if (timestamp != NOW)
46827672 q generate_ids_by_coarse(ids_by_coarse, *attic_items);
470 // formulate range query
471606154 q Ranges< Tag_Index_Local > ranges = formulate_range_query(ids_by_coarse);
473 // prepare straight keys
474606154 q std::map< std::string, std::pair< std::string, std::vector< Regular_Expression* > > > key_union;
475720154 q for (std::vector< std::string >::const_iterator it = keys.begin(); it != keys.end();
476606154 q ++it)
47711430 q key_union[*it];
478837154 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = key_values.begin(); it != key_values.end();
479606154 q ++it)
48023157 q key_union[it->first].first = it->second;
481606154 q for (std::vector< std::pair< std::string, Regular_Expression* > >::const_iterator
482666154 q it = key_regexes.begin(); it != key_regexes.end(); ++it)
4836014 q key_union[it->first].second.push_back(it->second);
485 // iterate over the result
486606154 q std::map< TIndex, std::vector< TObject > > result;
487606154 q std::map< TIndex, std::vector< Attic< TObject > > > attic_result;
488606154 q uint coarse_count = 0;
490606154 q Block_Backend< Tag_Index_Local, typename TObject::Id_Type > items_db
491606154 q (transaction.data_index(&file_prop));
492606154 q auto tag_it = items_db.range_begin(ranges);
494606154 q if (timestamp == NOW)
49533094 q {
49633094 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
497459494 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
498426458 q {
499426458 q if (++coarse_count >= 1024)
50122 q coarse_count = 0;
50222 q rman.health_check(*this);
504426458 q filter_ids_by_tags(key_union, regkey_regexes, items_db, tag_it, it->first, it->second);
505426458 q }
50633094 q }
50727672 q else
50827672 q {
50927672 q Block_Backend< Tag_Index_Local, Attic< typename TObject::Id_Type > > attic_items_db
51027672 q (transaction.data_index(attic_file_prop));
51127672 q auto attic_tag_it = attic_items_db.range_begin(ranges);
51327672 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
514565372 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
515537762 q {
516537762 q if (++coarse_count >= 1024)
5170 {
5180 coarse_count = 0;
5190 rman.health_check(*this);
5200 }
521537762 q filter_ids_by_tags(key_union, regkey_regexes, timestamp, items_db, tag_it, attic_items_db, attic_tag_it,
522537762 q it->first, it->second);
523537762 q }
52427672 q }
526606154 q if (key_nregexes.empty() && key_nvalues.empty())
528417107 q filter_by_ids(ids_by_coarse, items, attic_items);
529417107 q return;
532 // prepare negated keys
53318956 q std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > > nkey_union;
53418956 q for (std::vector< std::pair< std::string, Regular_Expression* > >::const_iterator
53530956 q it = key_nregexes.begin(); it != key_nregexes.end(); ++it)
53612035 q nkey_union[it->first].first.push_back(it->second);
53718956 q for (std::vector< std::pair< std::string, std::string > >::const_iterator
53828556 q it = key_nvalues.begin(); it != key_nvalues.end(); ++it)
5399626 q nkey_union[it->first].second.push_back(it->second);
541 // iterate over the result
54218956 q result.clear();
54318956 q attic_result.clear();
54418956 q coarse_count = 0;
54518956 q auto ntag_it = items_db.range_begin(ranges);
54718956 q if (timestamp == NOW)
5499330 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
550137030 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
551127725 q {
552127725 q if (++coarse_count >= 1024)
5530 {
5540 coarse_count = 0;
5550 rman.health_check(*this);
5560 }
557127725 q filter_ids_by_ntags(nkey_union, items_db, ntag_it, it->first, it->second);
558127725 q }
5609628 q else
5629628 q Block_Backend< Tag_Index_Local, Attic< typename TObject::Id_Type > > attic_items_db
5639628 q (transaction.data_index(attic_file_prop));
5649628 q auto attic_ntag_it = attic_items_db.range_begin(ranges);
5669628 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
567397128 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
568387527 q {
569387527 q if (++coarse_count >= 1024)
5700 {
5710 coarse_count = 0;
5720 rman.health_check(*this);
5730 }
574387527 q filter_ids_by_ntags(nkey_union, timestamp, items_db, ntag_it, attic_items_db, attic_ntag_it,
575387527 q it->first, it->second);
576387527 q }
57918956 q filter_by_ids(ids_by_coarse, items, attic_items);
583template< class TIndex, class TObject >
584void Query_Statement::filter_by_tags
585 (std::map< TIndex, std::vector< TObject > >& items,
586 const File_Properties& file_prop,
587 Resource_Manager& rman, Transaction& transaction)
5899367 q if (keys.empty() && key_values.empty() && key_regexes.empty() && regkey_regexes.empty()
5909367 q && key_nregexes.empty() && key_nvalues.empty())
5916254 q return;
593 // generate set of relevant coarse indices
5943124 q std::map< uint32, std::vector< typename TObject::Id_Type > > ids_by_coarse;
5953124 q generate_ids_by_coarse(ids_by_coarse, items);
597 // formulate range query
5983124 q Ranges< Tag_Index_Local > ranges = formulate_range_query(ids_by_coarse);
600 // prepare straight keys
6013124 q std::map< std::string, std::pair< std::string, std::vector< Regular_Expression* > > > key_union;
6023824 q for (std::vector< std::string >::const_iterator it = keys.begin(); it != keys.end();
6033124 q ++it)
60475 q key_union[*it];
6054924 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = key_values.begin(); it != key_values.end();
6063124 q ++it)
6071812 q key_union[it->first].first = it->second;
6083124 q for (std::vector< std::pair< std::string, Regular_Expression* > >::const_iterator
6093524 q it = key_regexes.begin(); it != key_regexes.end(); ++it)
61043 q key_union[it->first].second.push_back(it->second);
612 // iterate over the result
6133124 q std::map< TIndex, std::vector< TObject > > result;
6143124 q std::map< TIndex, std::vector< Attic< TObject > > > attic_result;
6153124 q uint coarse_count = 0;
6173124 q Block_Backend< Tag_Index_Local, typename TObject::Id_Type > items_db
6183124 q (transaction.data_index(&file_prop));
6193124 q auto tag_it = items_db.range_begin(ranges);
6213124 q typename std::map< TIndex, std::vector< TObject > >::const_iterator item_it
6223124 q = items.begin();
6253124 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator it = ids_by_coarse.begin();
62673024 q it != ids_by_coarse.end(); ++it)
6276993 q {
6286993 q if (++coarse_count >= 1024)
6290 {
6300 coarse_count = 0;
6310 rman.health_check(*this);
6320 }
6336993 q std::vector< typename TObject::Id_Type >& ids_by_coarse_ = it->second;
6356993 q filter_ids_by_tags_old(ids_by_coarse_, key_union, regkey_regexes, items_db, tag_it, it->first);
63715703 q while ((item_it != items.end()) &&
63815703 q ((item_it->first.val() & 0x7fffff00) == it->first))
6398713 q {
6408713 q for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
64186823 q eit != item_it->second.end(); ++eit)
64278113 q {
64378113 q if (std::binary_search(ids_by_coarse_.begin(), ids_by_coarse_.end(), eit->id))
64432113 q result[item_it->first.val()].push_back(*eit);
64578113 q }
6468713 q ++item_it;
6478713 q }
6486993 q }
6513124 q items.swap(result);
6533124 q if (key_nregexes.empty() && key_nvalues.empty())
6542619 q return;
656 // prepare negated keys
65755 q std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > > nkey_union;
65855 q for (std::vector< std::pair< std::string, Regular_Expression* > >::const_iterator
65995 q it = key_nregexes.begin(); it != key_nregexes.end(); ++it)
66043 q nkey_union[it->first].first.push_back(it->second);
66155 q for (std::vector< std::pair< std::string, std::string > >::const_iterator
66285 q it = key_nvalues.begin(); it != key_nvalues.end(); ++it)
66332 q nkey_union[it->first].second.push_back(it->second);
665 // iterate over the result
66655 q result.clear();
66755 q attic_result.clear();
66855 q coarse_count = 0;
66955 q auto ntag_it = items_db.range_begin(ranges);
67055 q item_it = items.begin();
67355 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator it = ids_by_coarse.begin();
67455 q it != ids_by_coarse.end(); ++it)
6750 {
6760 if (++coarse_count >= 1024)
6770 {
6780 coarse_count = 0;
6790 rman.health_check(*this);
6800 }
6810 std::vector< typename TObject::Id_Type >& ids_by_coarse_ = it->second;
6830 sort(ids_by_coarse_.begin(), ids_by_coarse_.end());
6850 filter_ids_by_ntags(nkey_union, items_db, ntag_it, it->first, ids_by_coarse_);
6870 while ((item_it != items.end()) &&
6880 ((item_it->first.val() & 0x7fffff00) == it->first))
6890 {
6900 for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
6910 eit != item_it->second.end(); ++eit)
6920 {
6930 if (std::binary_search(ids_by_coarse_.begin(), ids_by_coarse_.end(), eit->id))
6940 result[item_it->first.val()].push_back(*eit);
6950 }
6960 ++item_it;
6970 }
6980 }
70155 q items.swap(result);
705template< typename Conditions, typename Tags, typename Single_Match >
706bool matches_all_conditions(const Conditions& conds, const Tags& tags, const Single_Match& lambda)
7070{
7080 for (auto it_c = conds.begin(); it_c != conds.end(); ++it_c)
7090 {
7100 auto it_tags = tags.begin();
7110 for (; it_tags != tags.end(); ++it_tags)
7120 {
7130 if (lambda(*it_c, *it_tags))
7140 break;
7150 }
7160 if (it_tags == tags.end())
7170 return false;
7180 }
7190 return true;
7200}
723template< typename Conditions, typename Tags, typename Single_Match >
724bool matches_some_conditions(const Conditions& conds, const Tags& tags, const Single_Match& lambda)
7250{
7260 for (auto it_c = conds.begin(); it_c != conds.end(); ++it_c)
7270 {
7280 for (auto it_tags = tags.begin(); it_tags != tags.end(); ++it_tags)
7290 {
7300 if (lambda(*it_c, *it_tags))
7310 return true;
7320 }
7330 }
7340 return false;
7350}
738void Query_Statement::filter_by_tags(std::map< Uint31_Index, std::vector< Derived_Structure > >& items)
7390{
7400 typedef std::pair< std::string, std::string > Tag_Pair;
7420 for (std::map< Uint31_Index, std::vector< Derived_Structure > >::iterator it_idx = items.begin();
7430 it_idx != items.end(); ++it_idx)
7440 {
7450 std::vector< Derived_Structure > result;
7460 for (std::vector< Derived_Structure >::const_iterator it_elem = it_idx->second.begin();
7470 it_elem != it_idx->second.end(); ++it_elem)
7480 {
7490 if (matches_all_conditions(key_values, it_elem->tags,
7500 [](const std::pair< std::string, std::string >& cond, const Tag_Pair& tag)
7510 { return tag.first == cond.first && tag.second == cond.second; })
7520 && matches_all_conditions(keys, it_elem->tags,
7530 [](const std::string& cond, const Tag_Pair& tag)
7540 { return tag.first == cond; })
7550 && matches_all_conditions(key_regexes, it_elem->tags,
7560 [](const std::pair< std::string, Regular_Expression* >& cond, const Tag_Pair& tag)
7570 { return tag.first == cond.first && cond.second->matches(tag.second); })
7580 && !matches_some_conditions(key_nvalues, it_elem->tags,
7590 [](const std::pair< std::string, std::string >& cond, const Tag_Pair& tag)
7600 { return tag.first == cond.first && cond.second == tag.second; })
7610 && !matches_some_conditions(key_nregexes, it_elem->tags,
7620 [](const std::pair< std::string, Regular_Expression* >& cond, const Tag_Pair& tag)
7630 { return tag.first == cond.first && cond.second->matches(tag.second); }))
7640 result.push_back(*it_elem);
7650 }
7660 result.swap(it_idx->second);
7670 }
7680}
771template< typename Id >
772void Id_Constraint< Id >::restrict_to(const std::vector< Id >& rhs)
7744633 q if (invert)
7763930 q std::vector< Id > new_ids(rhs.size());
7773930 q new_ids.erase(std::set_difference(
7783930 q rhs.begin(), rhs.end(), ids.begin(), ids.end(), new_ids.begin()), new_ids.end());
7793930 q ids.swap(new_ids);
7803930 q invert = false;
78273 q else
78473 q std::vector< Id > new_ids(std::min(ids.size(), rhs.size()));
78573 q new_ids.erase(std::set_intersection(
78673 q ids.begin(), ids.end(), rhs.begin(), rhs.end(), new_ids.begin()), new_ids.end());
78773 q ids.swap(new_ids);
792template< class Id_Type >
793void Query_Statement::collect_nodes(
794 const Id_Constraint< Id_Type >& ids, Answer_State& answer_state, Set& into, Resource_Manager& rman)
796446299 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
797755299 q it != constraints.end() && answer_state < data_collected; ++it)
799309207 q if ((*it)->collect_nodes(rman, into, ids.ids, ids.invert))
8002519 q answer_state = data_collected;
805template< typename Id_Type >
806void Query_Statement::collect_elems(
807 int type, const Id_Constraint< Id_Type >& ids, Answer_State& answer_state, Set& into, Resource_Manager& rman)
809976458 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
8101687458 q it != constraints.end() && answer_state < data_collected; ++it)
812711359 q if ((*it)->collect(rman, into, type, ids.ids, ids.invert))
8136152 q answer_state = data_collected;
818void Query_Statement::collect_elems(Answer_State& answer_state, Set& into, Resource_Manager& rman)
8190{
8200 for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
8210 it != constraints.end() && answer_state < data_collected; ++it)
8220 {
8230 if ((*it)->collect(rman, into))
8240 answer_state = data_collected;
8250 }
8260}
829template< typename Index >
830Ranges< Index > intersect_ranges(const Ranges< Index >& range_a, std::vector< Index >& range_vec)
832343196 q Ranges< Index > result;
834343196 q unsigned long long sum = 0;
83535137196 q for (auto it = range_a.begin(); it != range_a.end(); ++it)
83634794195 q sum += difference(it.lower_bound(), it.upper_bound());
838343196 q if (sum/256 < range_vec.size())
8394328 q return range_a;
841300180 q std::sort(range_vec.begin(), range_vec.end());
843300180 q auto it_a = range_a.begin();
844300180 q auto it_vec = range_vec.begin();
8461149176180 q while (it_a != range_a.end() && it_vec != range_vec.end())
8471148876180 q {
8481148876180 q if (!(it_a.lower_bound() < Index(it_vec->val() + 0x100)))
849209 q ++it_vec;
8501148856180 q else if (!(*it_vec < it_a.upper_bound()))
8511622618 q ++it_a;
8521132630177 q else if (Index(it_vec->val() + 0x100) < it_a.upper_bound())
8531132563175 q {
8541132563175 q result.push_back(std::max(it_a.lower_bound(), *it_vec), Index(it_vec->val() + 0x100));
8551132563175 q ++it_vec;
8561132563175 q }
857674 q else
858674 q {
859674 q result.push_back(std::max(it_a.lower_bound(), *it_vec), it_a.upper_bound());
860674 q ++it_a;
861674 q }
8621148876180 q }
864300180 q return result;
868void Query_Statement::apply_all_filters(
869 Resource_Manager& rman, uint64 timestamp, Query_Filter_Strategy check_keys_late, Set& into)
871879507 q set_progress(5);
872879507 q rman.health_check(*this);
874879507 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
8751630507 q it != constraints.end(); ++it)
876751401 q (*it)->filter(rman, into);
878879507 q set_progress(6);
879879507 q rman.health_check(*this);
881879507 q filter_attic_elements(rman, timestamp, into.nodes, into.attic_nodes);
882879507 q filter_attic_elements(rman, timestamp, into.ways, into.attic_ways);
883879507 q filter_attic_elements(rman, timestamp, into.relations, into.attic_relations);
885879507 q set_progress(7);
886879507 q rman.health_check(*this);
888879507 q if (check_keys_late == prefer_ranges)
890543378 q filter_by_tags(into.nodes, &into.attic_nodes, timestamp,
891543378 q *osm_base_settings().NODE_TAGS_LOCAL, attic_settings().NODE_TAGS_LOCAL,
892543378 q rman, *rman.get_transaction());
893543378 q filter_by_tags(into.ways, &into.attic_ways, timestamp,
894543378 q *osm_base_settings().WAY_TAGS_LOCAL, attic_settings().WAY_TAGS_LOCAL,
895543378 q rman, *rman.get_transaction());
896543378 q filter_by_tags(into.relations, &into.attic_relations, timestamp,
897543378 q *osm_base_settings().RELATION_TAGS_LOCAL, attic_settings().RELATION_TAGS_LOCAL,
898543378 q rman, *rman.get_transaction());
899543378 q if (rman.get_area_transaction())
9009367 q filter_by_tags(into.areas,
9019367 q *area_settings().AREA_TAGS_LOCAL,
9029367 q rman, *rman.get_transaction());
905879507 q set_progress(8);
906879507 q rman.health_check(*this);
908879507 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
9091630507 q it != constraints.end(); ++it)
910751401 q (*it)->filter(*this, rman, into);
914void filter_elems_for_closed_ways(Set& arg)
91610848 q filter_elems_for_closed_ways(arg.ways);
91710848 q filter_elems_for_closed_ways(arg.attic_ways);
921void Query_Statement::execute(Resource_Manager& rman)
923879507 q Cpu_Timer cpu(rman, 1);
925879507 q Answer_State node_answer_state = nothing;
926879507 q Answer_State way_answer_state = nothing;
927879507 q Answer_State relation_answer_state = nothing;
928879507 q Answer_State area_answer_state = nothing;
929879507 q Answer_State derived_answer_state = nothing;
930879507 q Set into;
931879507 q Set filtered;
932879507 q uint64 timestamp = rman.get_desired_timestamp();
933879507 q if (timestamp == 0)
9340 timestamp = NOW;
936879507 q set_progress(1);
937879507 q rman.health_check(*this);
939879507 q Query_Filter_Strategy check_keys_late = ids_required;
9401630507 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin(); it != constraints.end(); ++it)
941751401 q check_keys_late = std::max(check_keys_late, (*it)->delivers_data(rman));
944879507 q Id_Constraint< Node::Id_Type > node_ids;
945879507 q Id_Constraint< Way::Id_Type > way_ids;
946879507 q Id_Constraint< Relation::Id_Type > relation_ids;
947879507 q Id_Constraint< Area_Skeleton::Id_Type > area_ids;
949879507 q std::vector< Uint32_Index > range_vec_32;
950879507 q std::vector< Uint31_Index > way_range_vec_31;
951879507 q std::vector< Uint31_Index > relation_range_vec_31;
953879507 q if (type & QUERY_NODE)
955446299 q progress_1< Node_Skeleton, Node::Id_Type, Uint32_Index >(
956446299 q keys, key_values, key_regexes, regkey_regexes, key_nvalues, key_nregexes, regkey_nregexes,
957446299 q node_ids, range_vec_32, timestamp, check_keys_late, rman, *this);
958446299 q if (node_ids.empty())
95911152 q node_answer_state = data_collected;
960446299 q collect_nodes(node_ids, node_answer_state, into, rman);
962879507 q if (type & QUERY_WAY)
964562389 q progress_1< Way_Skeleton, Way::Id_Type, Uint31_Index >(
965562389 q keys, key_values, key_regexes, regkey_regexes, key_nvalues, key_nregexes, regkey_nregexes,
966562389 q way_ids, way_range_vec_31, timestamp, check_keys_late, rman, *this);
967562389 q if (way_ids.empty())
9685548 q way_answer_state = data_collected;
969562389 q collect_elems(QUERY_WAY, way_ids, way_answer_state, into, rman);
970562389 q if (type & QUERY_CLOSED_WAY)
9715448 q filter_elems_for_closed_ways(into);
973879507 q if (type & QUERY_RELATION)
975360279 q progress_1< Relation_Skeleton, Relation::Id_Type, Uint31_Index >(
976360279 q keys, key_values, key_regexes, regkey_regexes, key_nvalues, key_nregexes, regkey_nregexes,
977360279 q relation_ids, relation_range_vec_31, timestamp, check_keys_late, rman, *this);
978360279 q if (relation_ids.empty())
9796457 q relation_answer_state = data_collected;
980360279 q collect_elems(QUERY_RELATION, relation_ids, relation_answer_state, into, rman);
982879507 q if (type & QUERY_DERIVED)
9830 {
9840 collect_elems(derived_answer_state, into, rman);
9850 filter_by_tags(into.deriveds);
9860 }
987879507 q if (type & QUERY_AREA)
9895448 q try
9915448 q progress_1(
9925448 q keys, key_values, key_regexes, regkey_regexes, key_nvalues, key_nregexes, regkey_nregexes,
9935448 q area_ids, check_keys_late, rman, *this);
9945448 q if (area_ids.empty())
99533 q area_answer_state = data_collected;
9965448 q collect_elems(QUERY_AREA, area_ids, area_answer_state, into, rman);
9985448 q catch (const File_Error& e)
10000 if (e.error_number != ENOENT)
10010 throw;
10020 area_answer_state = data_collected;
10030 }
1006879507 q set_progress(2);
1007879507 q rman.health_check(*this);
1009879507 q if ((type & QUERY_NODE) && check_keys_late == prefer_ranges)
1011255205 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1012531205 q it != constraints.end() && node_answer_state < data_collected; ++it)
1014276187 q std::vector< Node::Id_Type > constraint_node_ids;
1015276187 q if ((*it)->get_node_ids(rman, constraint_node_ids))
10171513 q node_ids.restrict_to(constraint_node_ids);
10181513 q if (node_ids.empty())
101942 q node_answer_state = data_collected;
1023879507 q if ((type & QUERY_WAY) && check_keys_late == prefer_ranges)
1025349268 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1026706268 q it != constraints.end() && way_answer_state < data_collected; ++it)
1028357251 q std::vector< Way::Id_Type > constraint_way_ids;
1029357251 q if ((*it)->get_way_ids(rman, constraint_way_ids))
10311512 q way_ids.restrict_to(constraint_way_ids);
10321512 q if (way_ids.empty())
103342 q way_answer_state = data_collected;
1037879507 q if ((type & QUERY_RELATION) && check_keys_late == prefer_ranges)
1039243199 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1040491199 q it != constraints.end() && relation_answer_state < data_collected; ++it)
1042248187 q std::vector< Relation::Id_Type > constraint_relation_ids;
1043248187 q if ((*it)->get_relation_ids(rman, constraint_relation_ids))
10451513 q relation_ids.restrict_to(constraint_relation_ids);
10461513 q if (relation_ids.empty())
104721 q relation_answer_state = data_collected;
1051879507 q if ((type & QUERY_AREA) && check_keys_late == prefer_ranges)
105365 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1054115 q it != constraints.end() && area_answer_state < data_collected; ++it)
105654 q std::vector< Area_Skeleton::Id_Type > constraint_area_ids;
105754 q if ((*it)->get_area_ids(rman, constraint_area_ids))
105911 q area_ids.restrict_to(constraint_area_ids);
106011 q if (area_ids.empty())
10610 area_answer_state = data_collected;
1066879507 q Ranges< Uint32_Index > node_ranges = Ranges< Uint32_Index >::global();
1067879507 q Ranges< Uint31_Index > way_ranges = Ranges< Uint31_Index >::global();
1068879507 q Ranges< Uint31_Index > rel_ranges = Ranges< Uint31_Index >::global();
1070879507 q if ((type & QUERY_NODE) && node_answer_state < data_collected)
1072306247 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1073585247 q it != constraints.end(); ++it)
1074279192 q node_ranges.intersect((*it)->get_node_ranges(rman)).swap(node_ranges);
1076306247 q if (!range_vec_32.empty())
10779980 q intersect_ranges(node_ranges, range_vec_32).swap(node_ranges);
1079879507 q if ((type & QUERY_WAY) && way_answer_state < data_collected)
1081465353 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1082838353 q it != constraints.end(); ++it)
1083373264 q way_ranges.intersect((*it)->get_way_ranges(rman)).swap(way_ranges);
1085465353 q if (!way_range_vec_31.empty())
1086180147 q intersect_ranges(way_ranges, way_range_vec_31).swap(way_ranges);
1088879507 q if ((type & QUERY_RELATION) && relation_answer_state < data_collected)
1090271234 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1091534234 q it != constraints.end(); ++it)
1092263200 q rel_ranges.intersect((*it)->get_relation_ranges(rman)).swap(rel_ranges);
1094271234 q if (!relation_range_vec_31.empty())
10956457 q intersect_ranges(rel_ranges, relation_range_vec_31).swap(rel_ranges);
1098879507 q set_progress(3);
1099879507 q rman.health_check(*this);
1101879507 q if (type & QUERY_NODE)
1103446299 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1104725299 q it != constraints.end() && node_answer_state < data_collected; ++it)
1106279192 q if ((*it)->get_data(*this, rman, into, node_ranges, node_ids.ids, node_ids.invert))
11071110 q node_answer_state = data_collected;
1110879507 q if (type & QUERY_WAY)
1112562389 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1113935389 q it != constraints.end() && way_answer_state < data_collected; ++it)
1115373264 q if ((*it)->get_data(*this, rman, into, way_ranges, type & QUERY_WAY, way_ids.ids, way_ids.invert))
11172320 q if (type & QUERY_CLOSED_WAY)
11180 filter_elems_for_closed_ways(into);
11192320 q way_answer_state = data_collected;
1123879507 q if (type & QUERY_RELATION)
1125360279 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1126623279 q it != constraints.end() && relation_answer_state < data_collected; ++it)
1128263200 q if ((*it)->get_data(*this, rman, into, rel_ranges, type & QUERY_RELATION,
1129263200 q relation_ids.ids, relation_ids.invert))
11302928 q relation_answer_state = data_collected;
1133879507 q if (type & QUERY_AREA)
11355448 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
11365948 q it != constraints.end() && area_answer_state < data_collected; ++it)
113854 q if ((*it)->get_data(*this, rman, into, {}, type & QUERY_AREA, area_ids.ids, area_ids.invert))
11390 area_answer_state = data_collected;
1143879507 q set_progress(4);
1144879507 q rman.health_check(*this);
1146879507 q if (type & QUERY_NODE)
1148446299 q if (node_answer_state < data_collected)
1150295241 q if (node_ranges.is_global())
115222 q if (node_ids.invert)
115422 q if (node_ids.ids.empty())
115522 q runtime_error("Filters too weak in query statement: specify in addition a bbox, a tag filter, or similar.");
11570 else
11580 {
11590 node_ranges = Ranges< Uint32_Index >();
11600 std::vector< Uint32_Index > req = get_indexes_< Uint32_Index, Node_Skeleton >(node_ids.ids, rman);
11610 for (std::vector< Uint32_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
11620 node_ranges.push_back(*it, ++Uint32_Index(*it));
11630 node_ranges.sort();
11640 }
1167295241 q Collect_Items< Uint32_Index, Node_Skeleton > db_reader(
1168295241 q node_ids.ids, node_ids.invert, node_ranges, *this, rman);
1169295241 q while (db_reader.get_chunk(into.nodes, into.attic_nodes))
11700 {
11710 Set to_filter;
11720 to_filter.nodes.swap(into.nodes);
11730 to_filter.attic_nodes.swap(into.attic_nodes);
11740 apply_all_filters(rman, timestamp, check_keys_late, to_filter);
11750 indexed_set_union(filtered.nodes, to_filter.nodes);
11760 indexed_set_union(filtered.attic_nodes, to_filter.attic_nodes);
11770 }
1180879507 q if (type & QUERY_WAY)
1182562389 q if (way_answer_state < data_collected)
1184442343 q if (way_ranges.is_global())
11861110 q if (way_ids.invert)
118898 q if (way_ids.ids.empty())
118933 q runtime_error("Filters too weak in query statement: specify in addition a bbox, a tag filter, or similar.");
119122 q else
119322 q way_ranges = Ranges< Uint31_Index >();
119422 q std::vector< Uint31_Index > req = get_indexes_< Uint31_Index, Way_Skeleton >(way_ids.ids, rman);
119583592 q for (std::vector< Uint31_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
119683572 q way_ranges.push_back(*it, inc(*it));
119722 q way_ranges.sort();
1201442343 q Collect_Items< Uint31_Index, Way_Skeleton > db_reader(
1202442343 q way_ids.ids, way_ids.invert, way_ranges, *this, rman);
1203442343 q while (db_reader.get_chunk(into.ways, into.attic_ways))
12040 {
12050 Set to_filter;
12060 to_filter.ways.swap(into.ways);
12070 to_filter.attic_ways.swap(into.attic_ways);
12080 if (type & QUERY_CLOSED_WAY)
12090 {
12100 filter_elems_for_closed_ways(to_filter.ways);
12110 filter_elems_for_closed_ways(to_filter.attic_ways);
12120 }
12130 apply_all_filters(rman, timestamp, check_keys_late, to_filter);
12140 indexed_set_union(filtered.ways, to_filter.ways);
12150 indexed_set_union(filtered.attic_ways, to_filter.attic_ways);
12160 }
1219879507 q if (type & QUERY_RELATION)
1221360279 q if (relation_answer_state < data_collected)
1223242213 q if (rel_ranges.is_global())
12251816 q if (!relation_ids.invert)
122722 q rel_ranges = Ranges< Uint31_Index >();
122822 q std::vector< Uint31_Index > req = get_indexes_< Uint31_Index, Relation_Skeleton >(relation_ids.ids, rman);
1229101792 q for (std::vector< Uint31_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
1230101772 q rel_ranges.push_back(*it, inc(*it));
123122 q rel_ranges.sort();
1235242213 q Collect_Items< Uint31_Index, Relation_Skeleton > db_reader(
1236242213 q relation_ids.ids, relation_ids.invert, rel_ranges, *this, rman);
1237242213 q while (db_reader.get_chunk(into.relations, into.attic_relations))
12380 {
12390 Set to_filter;
12400 to_filter.relations.swap(into.relations);
12410 to_filter.attic_relations.swap(into.attic_relations);
12420 apply_all_filters(rman, timestamp, check_keys_late, to_filter);
12430 indexed_set_union(filtered.relations, to_filter.relations);
12440 indexed_set_union(filtered.attic_relations, to_filter.attic_relations);
12450 }
1248879507 q if (type & QUERY_AREA)
12505448 q if (area_answer_state == nothing && area_ids.empty())
12510 runtime_error("Filters too weak in query statement: specify in addition a bbox, a tag filter, or similar.");
12525448 q try
12545448 q if (area_answer_state < data_collected)
12555145 q get_elements_by_id_from_db(into.areas, area_ids.ids, area_ids.invert, rman, *area_settings().AREAS);
12575448 q catch (const File_Error& e)
12590 if (e.error_number != ENOENT)
12600 throw;
12610 }
1265879507 q if (type & QUERY_CLOSED_WAY)
12665448 q filter_elems_for_closed_ways(into);
1267879507 q apply_all_filters(rman, timestamp, check_keys_late, into);
1268879507 q indexed_set_union(into.nodes, filtered.nodes);
1269879507 q indexed_set_union(into.attic_nodes, filtered.attic_nodes);
1270879507 q indexed_set_union(into.ways, filtered.ways);
1271879507 q indexed_set_union(into.attic_ways, filtered.attic_ways);
1272879507 q indexed_set_union(into.relations, filtered.relations);
1273879507 q indexed_set_union(into.attic_relations, filtered.attic_relations);
1274879507 q indexed_set_union(into.areas, filtered.areas);
1275879507 q indexed_set_union(into.deriveds, filtered.deriveds);
1277879507 q set_progress(9);
1278879507 q rman.health_check(*this);
1280879507 q clear_empty_indices(into.nodes);
1281879507 q clear_empty_indices(into.attic_nodes);
1282879507 q clear_empty_indices(into.ways);
1283879507 q clear_empty_indices(into.attic_ways);
1284879507 q clear_empty_indices(into.relations);
1285879507 q clear_empty_indices(into.deriveds);
1286879507 q clear_empty_indices(into.areas);
1288879507 q transfer_output(rman, into);
1289879507 q rman.health_check(*this);
1292//-----------------------------------------------------------------------------
1294Generic_Statement_Maker< Has_Kv_Statement > Has_Kv_Statement::statement_maker("has-kv");
1296Has_Kv_Statement::Has_Kv_Statement
1297 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings)
12981599333 q : Statement(line_number_), regex(0), key_regex(0), straight(true), case_sensitive(false)
13001599333 q std::map< std::string, std::string > attributes;
13021599333 q attributes["k"] = "";
13031599333 q attributes["regk"] = "";
13041599333 q attributes["v"] = "";
13051599333 q attributes["regv"] = "";
13061599333 q attributes["modv"] = "";
13071599333 q attributes["case"] = "sensitive";
13091599333 q eval_attributes_array(get_name(), attributes, input_attributes);
13111599333 q key = attributes["k"];
13121599333 q value = attributes["v"];
13141599333 q if (key == "" && attributes["regk"] == "")
13150 {
13160 std::ostringstream temp("");
13170 temp<<"For the attribute \"k\" of the element \"has-kv\""
13180 <<" the only allowed values are non-empty strings.";
13190 add_static_error(temp.str());
13200 }
13221599333 q if (attributes["case"] != "ignore")
13231581332 q {
13241581332 q if (attributes["case"] != "sensitive")
13250 add_static_error("For the attribute \"case\" of the element \"has-kv\""
13260 " the only allowed values are \"sensitive\" or \"ignore\".");
13271581332 q case_sensitive = true;
13281581332 q }
13301599333 q if (attributes["regk"] != "")
133214442 q if (key != "")
13330 {
13340 std::ostringstream temp("");
13350 temp<<"In the element \"has-kv\" only one of the attributes \"k\" and \"regk\""
13360 " can be nonempty.";
13370 add_static_error(temp.str());
13380 }
133914442 q if (value != "")
13400 {
13410 std::ostringstream temp("");
13420 temp<<"In the element \"has-kv\" the attribute \"regk\" must be combined with \"regv\".";
13430 add_static_error(temp.str());
13440 }
134614442 q try
134814442 q key_regex = new Regular_Expression(attributes["regk"], case_sensitive);
134914442 q key = attributes["regk"];
135114442 q catch (Regular_Expression_Error e)
13530 add_static_error("Invalid regular expression: \"" + attributes["regk"] + "\"");
13540 }
13571599333 q if (attributes["regv"] != "")
1359465126 q if (value != "")
13600 {
13610 std::ostringstream temp("");
13620 temp<<"In the element \"has-kv\" only one of the attributes \"v\" and \"regv\""
13630 " can be nonempty.";
13640 add_static_error(temp.str());
13650 }
1367465126 q try
1369465126 q regex = new Regular_Expression(attributes["regv"], case_sensitive);
1370465126 q value = attributes["regv"];
1372465126 q catch (Regular_Expression_Error e)
13740 add_static_error("Invalid regular expression: \"" + attributes["regv"] + "\"");
13750 }
13781599333 q if (attributes["modv"] == "" || attributes["modv"] == "not")
13791599333 q {
13801599333 q if (attributes["modv"] == "not")
138232488 q if (attributes["regk"] == "")
138332488 q straight = false;
13840 else
13850 add_static_error("In the element \"has-kv\" regular expressions on keys cannot be combined"
13860 " with negation.");
13881599333 q }
13890 else
13900 {
13910 std::ostringstream temp("");
13920 temp<<"In the element \"has-kv\" the attribute \"modv\" can only be empty or std::set to \"not\".";
13930 add_static_error(temp.str());
13940 }
1398Has_Kv_Statement::~Has_Kv_Statement()
14001599333 q delete key_regex;
14011599333 q delete regex;