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

overpass_api/statements/query.cc

917 of 1124 instrumented lines run by the suite (81.6%) 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)
462567582 q : Output_Statement(line_number_), global_bbox_statement(0)
472567582 q{
482567582 q std::map< std::string, std::string > attributes;
502567582 q attributes["into"] = "_";
512567582 q attributes["type"] = "";
532567582 q eval_attributes_array(get_name(), attributes, input_attributes);
552567582 q set_output(attributes["into"]);
562567582 q if (attributes["type"] == "node")
57475139 q type = QUERY_NODE;
582092499 q else if (attributes["type"] == "way")
59598171 q type = QUERY_WAY;
601494396 q else if (attributes["type"] == "relation")
61462132 q type = QUERY_RELATION;
621032304 q else if (attributes["type"] == "derived")
630 type = QUERY_DERIVED;
641032304 q else if (attributes["type"] == "nwr")
65356115 q type = (QUERY_NODE | QUERY_WAY | QUERY_RELATION);
66676212 q else if (attributes["type"] == "nw")
6728293 q type = (QUERY_NODE | QUERY_WAY);
68394122 q else if (attributes["type"] == "wr")
6920166 q type = (QUERY_WAY | QUERY_RELATION);
7019358 q else if (attributes["type"] == "nr")
710 type = (QUERY_NODE | QUERY_RELATION);
7219358 q else if (attributes["type"] == "area")
7319057 q {
7419057 q type = QUERY_AREA | QUERY_WAY | QUERY_CLOSED_WAY;
7519057 q area_query_exists_ = true;
7619057 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());
862567582 q if (global_settings.get_global_bbox_limitation().valid())
874222 q {
884222 q global_bbox_statement = new Bbox_Query_Statement(global_settings.get_global_bbox_limitation());
894222 q constraints.push_back(global_bbox_statement->get_query_constraint());
904222 q }
912567582 q}
94Query_Statement::~Query_Statement()
952567582 q{
962567582 q delete global_bbox_statement;
972567582 q}
100void Query_Statement::add_statement(Statement* statement, std::string text)
1023921574 q assure_no_text(text, this->get_name());
1043921574 q Has_Kv_Statement* has_kv(dynamic_cast<Has_Kv_Statement*>(statement));
1053921574 q if (has_kv)
1061731376 q {
1071731376 q substatements.push_back(statement);
1091731376 q if (has_kv->get_value() != "")
111996260 q if (has_kv->get_straight())
112879244 q key_values.push_back(std::make_pair< std::string, std::string >
113879244 q (has_kv->get_key(), has_kv->get_value()));
11411736 q else
11511736 q key_nvalues.push_back(std::make_pair< std::string, std::string >
11611736 q (has_kv->get_key(), has_kv->get_value()));
118735180 q else if (has_kv->get_key_regex())
11915345 q {
12015345 q if (has_kv->get_straight())
12115345 q regkey_regexes.push_back(std::make_pair< Regular_Expression*, Regular_Expression* >
12215345 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()));
12615345 q }
127582145 q else if (has_kv->get_regex())
12835796 q {
12935796 q if (has_kv->get_straight())
13016845 q key_regexes.push_back(std::make_pair< std::string, Regular_Expression* >
13116845 q (has_kv->get_key(), has_kv->get_regex()));
13218957 q else
13318957 q key_nregexes.push_back(std::make_pair< std::string, Regular_Expression* >
13418957 q (has_kv->get_key(), has_kv->get_regex()));
13535796 q }
13622559 q else
13722559 q keys.push_back(has_kv->get_key());
1381731376 q return;
1391731376 q }
1412190463 q Query_Constraint* constraint = statement->get_query_constraint();
1422190463 q if (constraint)
1432190463 q {
1442190463 q constraints.push_back(constraint);
1452190463 q substatements.push_back(statement);
1462190463 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)
1576153 q Request_Context context(this, rman);
1586153 q if (!invert_ids)
1596053 q collect_items_flat(context, file_prop,
1606053 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)
1726902567 q for (typename std::map< TIndex, std::vector< TObject > >::iterator it = modify.begin();
1731208032567 q it != modify.end();)
1741201785473 q {
1751201785473 q if (!it->second.empty())
176655057415 q {
177655057415 q ++it;
178655057415 q continue;
179655057415 q }
180546728351 q typename std::map< TIndex, std::vector< TObject > >::iterator next_it = it;
181546728351 q if (++next_it == modify.end())
183655299 q modify.erase(it);
184655299 q break;
186546073335 q else
187546073335 q {
188546073335 q TIndex idx = next_it->first;
189546073335 q modify.erase(it);
190546073335 q it = modify.find(idx);
191546073335 q }
192546728351 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)
20422527 q std::vector< Id_Type > removed_ids;
20522527 q std::string last_key, last_value;
20622527 q bool key_relevant = false;
20722527 q bool valid = false;
20822527 q std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > >::const_iterator
20922527 q key_it = keys.begin();
211311188827 q while ((!(tag_it == items_db.range_end())) &&
212311188827 q (((tag_it.index().index) & 0x7fffff00) == coarse_index))
213311188226 q {
214311188226 q if (tag_it.index().key != last_key)
2152854126 q {
2162854126 q last_value = void_tag_value() + " ";
2182854126 q if (key_relevant)
21913718 q {
22013718 q ++key_it;
22113718 q sort(removed_ids.begin(), removed_ids.end());
22213718 q removed_ids.erase(unique(removed_ids.begin(), removed_ids.end()), removed_ids.end());
22313718 q new_ids.erase(set_difference(new_ids.begin(), new_ids.end(),
22413718 q removed_ids.begin(), removed_ids.end(), new_ids.begin()), new_ids.end());
22513718 q }
2262854126 q key_relevant = false;
2282854126 q last_key = tag_it.index().key;
2292868326 q while (key_it != keys.end() && last_key > key_it->first)
23014220 q ++key_it;
2322854126 q if (key_it == keys.end())
23321925 q break;
2352832226 q if (last_key == key_it->first)
23613718 q {
23713718 q key_relevant = true;
23813718 q removed_ids.clear();
23913718 q }
2402832226 q }
242311166326 q if (key_relevant)
2432858518 q {
2442858518 q if (tag_it.index().value != last_value)
24580518 q {
24680518 q valid = false;
24780518 q for (std::vector< Regular_Expression* >::const_iterator rit = key_it->second.first.begin();
248127418 q rit != key_it->second.first.end(); ++rit)
24946912 q valid |= (tag_it.index().value != void_tag_value() && (*rit)->matches(tag_it.index().value));
25080518 q for (std::vector< std::string >::const_iterator rit = key_it->second.second.begin();
251114118 q rit != key_it->second.second.end(); ++rit)
2523367 q valid |= (*rit == tag_it.index().value);
25380518 q last_value = tag_it.index().value;
25480518 q }
2562858518 q if (valid)
2571401213 q removed_ids.push_back(tag_it.object());
2582858518 q }
260311166326 q ++tag_it;
261311166326 q }
262246983127 q while ((!(tag_it == items_db.range_end())) &&
263246983127 q (((tag_it.index().index) & 0x7fffff00) == coarse_index))
264246960625 q ++tag_it;
26622527 q sort(removed_ids.begin(), removed_ids.end());
26722527 q removed_ids.erase(unique(removed_ids.begin(), removed_ids.end()), removed_ids.end());
26822527 q new_ids.erase(set_difference(new_ids.begin(), new_ids.end(),
26922527 q removed_ids.begin(), removed_ids.end(), new_ids.begin()), new_ids.end());
27122527 q sort(new_ids.begin(), new_ids.end());
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)
28671632 q for (std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > >::const_iterator
287151932 q key_it = keys.begin(); key_it != keys.end(); ++key_it)
28880332 q {
28980332 q std::map< Id_Type, std::pair< uint64, uint64 > > timestamps;
29091274032 q for (typename std::vector< Id_Type >::const_iterator it = new_ids.begin(); it != new_ids.end(); ++it)
29191193728 q timestamps[*it];
2931026105632 q while ((!(tag_it == items_db.range_end())) &&
2941026105632 q ((tag_it.index().index) & 0x7fffff00) == coarse_index &&
2951026105632 q tag_it.index().key < key_it->first)
2961026025331 q ++tag_it;
297855139732 q while ((!(attic_tag_it == attic_items_db.range_end())) &&
298855139732 q ((attic_tag_it.index().index) & 0x7fffff00) == coarse_index &&
299855139732 q attic_tag_it.index().key < key_it->first)
300855059432 q ++attic_tag_it;
30280332 q bool valid = false;
30380332 q std::string last_value = void_tag_value() + " ";
30413055632 q while ((!(tag_it == items_db.range_end())) &&
30513055632 q ((tag_it.index().index) & 0x7fffff00) == coarse_index &&
30613055632 q tag_it.index().key == key_it->first)
30712975328 q {
30812975328 q if (std::binary_search(new_ids.begin(), new_ids.end(), tag_it.object()))
309206316 q {
310206316 q std::pair< uint64, uint64 >& timestamp_ref = timestamps[tag_it.object()];
311206316 q timestamp_ref.second = NOW;
313206316 q if (tag_it.index().value != last_value)
31429516 q {
31529516 q valid = false;
31629516 q for (std::vector< Regular_Expression* >::const_iterator rit = key_it->second.first.begin();
31753716 q rit != key_it->second.first.end(); ++rit)
31824211 q valid |= (tag_it.index().value != void_tag_value() && (*rit)->matches(tag_it.index().value));
31929516 q for (std::vector< std::string >::const_iterator rit = key_it->second.second.begin();
32034816 q rit != key_it->second.second.end(); ++rit)
321536 q valid |= (*rit == tag_it.index().value);
32229516 q last_value = tag_it.index().value;
32329516 q }
325206316 q if (valid)
326125113 q timestamp_ref.first = NOW;
327206316 q }
32812975328 q ++tag_it;
32912975328 q }
33180332 q last_value = void_tag_value() + " ";
3328118832 q while ((!(attic_tag_it == attic_items_db.range_end())) &&
3338118832 q ((attic_tag_it.index().index) & 0x7fffff00) == coarse_index &&
3348118832 q attic_tag_it.index().key == key_it->first)
3358038530 q {
3368038530 q if (std::binary_search(new_ids.begin(), new_ids.end(), Id_Type(attic_tag_it.object())))
337108018 q {
338108018 q std::pair< uint64, uint64 >& timestamp_ref = timestamps[attic_tag_it.object()];
339108018 q if (timestamp < attic_tag_it.object().timestamp &&
340108018 q (timestamp_ref.second == 0 || timestamp_ref.second > attic_tag_it.object().timestamp))
34142317 q timestamp_ref.second = attic_tag_it.object().timestamp;
343108018 q if (attic_tag_it.index().value != last_value)
34422218 q {
34522218 q valid = false;
34622218 q if (attic_tag_it.index().value != void_tag_value())
34715815 q {
34815815 q for (std::vector< Regular_Expression* >::const_iterator rit = key_it->second.first.begin();
34927815 q rit != key_it->second.first.end(); ++rit)
35012011 q valid |= (attic_tag_it.index().value != void_tag_value()
35112011 q && (*rit)->matches(attic_tag_it.index().value));
35215815 q for (std::vector< std::string >::const_iterator rit = key_it->second.second.begin();
35319615 q rit != key_it->second.second.end(); ++rit)
354385 q valid |= (*rit == attic_tag_it.index().value);
35515815 q }
35622218 q last_value = attic_tag_it.index().value;
35722218 q }
359108018 q if (valid && timestamp < attic_tag_it.object().timestamp &&
360108018 q (timestamp_ref.first == 0 || timestamp_ref.first > attic_tag_it.object().timestamp))
36114110 q timestamp_ref.first = attic_tag_it.object().timestamp;
362108018 q }
3638038530 q ++attic_tag_it;
3648038530 q }
36680332 q new_ids.clear();
36780332 q new_ids.reserve(timestamps.size());
36880332 q for (typename std::map< Id_Type, std::pair< uint64, uint64 > >::const_iterator
36991274032 q it = timestamps.begin(); it != timestamps.end(); ++it)
37091193728 q {
37191193728 q if (!(0 < it->second.first && it->second.first <= it->second.second))
37291075628 q new_ids.push_back(it->first);
37391193728 q }
37480332 q }
375685966832 q while ((!(tag_it == items_db.range_end())) &&
376685966832 q ((tag_it.index().index) & 0x7fffff00) == coarse_index)
377685895231 q ++tag_it;
378868700832 q while ((!(attic_tag_it == attic_items_db.range_end())) &&
379868700832 q ((attic_tag_it.index().index) & 0x7fffff00) == coarse_index)
380868629232 q ++attic_tag_it;
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)
390780199 q std::map< TIndex, std::vector< TObject > > result;
391780199 q std::map< TIndex, std::vector< Attic< TObject > > > attic_result;
393780199 q typename std::map< TIndex, std::vector< TObject > >::const_iterator item_it = items.begin();
395780199 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 }
413780199 q else
415780199 q typename std::map< TIndex, std::vector< Attic< TObject > > >::const_iterator attic_item_it
416780199 q = attic_items->begin();
418780199 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::const_iterator
4194445199 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
4203665155 q {
421129639155 q while ((item_it != items.end()) &&
422129639155 q ((item_it->first.val() & 0x7fffff00) == it->first))
423125974153 q {
424125974153 q for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
4256195580153 q eit != item_it->second.end(); ++eit)
4266069606126 q {
4276069606126 q if (std::binary_search(it->second.begin(), it->second.end(), eit->id))
428106771097 q result[item_it->first.val()].push_back(*eit);
4296069606126 q }
430125974153 q ++item_it;
431125974153 q }
43342746155 q while ((attic_item_it != attic_items->end()) &&
43442746155 q ((attic_item_it->first.val() & 0x7fffff00) == it->first))
4353908181 q {
4363908181 q for (typename std::vector< Attic< TObject > >::const_iterator eit = attic_item_it->second.begin();
43731253481 q eit != attic_item_it->second.end(); ++eit)
43827345363 q {
43927345363 q if (std::binary_search(it->second.begin(), it->second.end(), eit->id))
44021294050 q attic_result[attic_item_it->first.val()].push_back(*eit);
44127345363 q }
4423908181 q ++attic_item_it;
4433908181 q }
4443665155 q }
447780199 q items.swap(result);
448780199 q if (attic_items)
449780199 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)
4602019447 q if (keys.empty() && key_values.empty() && key_regexes.empty() && regkey_regexes.empty()
4612019447 q && key_nregexes.empty() && key_nvalues.empty())
4621239308 q return;
464 // generate set of relevant coarse indices
465780199 q std::map< uint32, std::vector< typename TObject::Id_Type > > ids_by_coarse;
466780199 q generate_ids_by_coarse(ids_by_coarse, items);
467780199 q if (timestamp != NOW)
46835793 q generate_ids_by_coarse(ids_by_coarse, *attic_items);
470 // formulate range query
471780199 q Ranges< Tag_Index_Local > ranges = formulate_range_query(ids_by_coarse);
473 // prepare straight keys
474780199 q std::map< std::string, std::pair< std::string, std::vector< Regular_Expression* > > > key_union;
475918199 q for (std::vector< std::string >::const_iterator it = keys.begin(); it != keys.end();
476780199 q ++it)
47713831 q key_union[*it];
4781134199 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = key_values.begin(); it != key_values.end();
479780199 q ++it)
48035497 q key_union[it->first].first = it->second;
481780199 q for (std::vector< std::pair< std::string, Regular_Expression* > >::const_iterator
482867199 q it = key_regexes.begin(); it != key_regexes.end(); ++it)
4838723 q key_union[it->first].second.push_back(it->second);
485 // iterate over the result
486780199 q std::map< TIndex, std::vector< TObject > > result;
487780199 q std::map< TIndex, std::vector< Attic< TObject > > > attic_result;
488780199 q uint coarse_count = 0;
490780199 q Block_Backend< Tag_Index_Local, typename TObject::Id_Type > items_db
491780199 q (transaction.data_index(&file_prop));
492780199 q auto tag_it = items_db.range_begin(ranges);
494780199 q if (timestamp == NOW)
496423119 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
4972358119 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
498193584 q {
499193584 q if (++coarse_count >= 1024)
5000 {
5010 coarse_count = 0;
5020 rman.health_check(*this);
5030 }
504193584 q filter_ids_by_tags(key_union, regkey_regexes, items_db, tag_it, it->first, it->second);
505193584 q }
50735793 q else
50835793 q {
50935793 q Block_Backend< Tag_Index_Local, Attic< typename TObject::Id_Type > > attic_items_db
51035793 q (transaction.data_index(attic_file_prop));
51135793 q auto attic_tag_it = attic_items_db.range_begin(ranges);
51335793 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
514208793 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
515173081 q {
516173081 q if (++coarse_count >= 1024)
5170 {
5180 coarse_count = 0;
5190 rman.health_check(*this);
5200 }
521173081 q filter_ids_by_tags(key_union, regkey_regexes, timestamp, items_db, tag_it, attic_items_db, attic_tag_it,
522173081 q it->first, it->second);
523173081 q }
52435793 q }
526780199 q if (key_nregexes.empty() && key_nvalues.empty())
528573146 q filter_by_ids(ids_by_coarse, items, attic_items);
529573146 q return;
532 // prepare negated keys
53320760 q std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > > nkey_union;
53420760 q for (std::vector< std::pair< std::string, Regular_Expression* > >::const_iterator
53534860 q it = key_nregexes.begin(); it != key_nregexes.end(); ++it)
53614140 q nkey_union[it->first].first.push_back(it->second);
53720760 q for (std::vector< std::pair< std::string, std::string > >::const_iterator
53829760 q it = key_nvalues.begin(); it != key_nvalues.end(); ++it)
5399025 q nkey_union[it->first].second.push_back(it->second);
541 // iterate over the result
54220760 q result.clear();
54320760 q attic_result.clear();
54420760 q coarse_count = 0;
54520760 q auto ntag_it = items_db.range_begin(ranges);
54720760 q if (timestamp == NOW)
5499029 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
55031529 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
55122527 q {
55222527 q if (++coarse_count >= 1024)
5530 {
5540 coarse_count = 0;
5550 rman.health_check(*this);
5560 }
55722527 q filter_ids_by_ntags(nkey_union, items_db, ntag_it, it->first, it->second);
55822527 q }
56011734 q else
56111734 q {
56211734 q Block_Backend< Tag_Index_Local, Attic< typename TObject::Id_Type > > attic_items_db
56311734 q (transaction.data_index(attic_file_prop));
56411734 q auto attic_ntag_it = attic_items_db.range_begin(ranges);
56611734 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator
56783334 q it = ids_by_coarse.begin(); it != ids_by_coarse.end(); ++it)
56871632 q {
56971632 q if (++coarse_count >= 1024)
5700 {
5710 coarse_count = 0;
5720 rman.health_check(*this);
5730 }
57471632 q filter_ids_by_ntags(nkey_union, timestamp, items_db, ntag_it, attic_items_db, attic_ntag_it,
57571632 q it->first, it->second);
57671632 q }
57711734 q }
57920760 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)
58915389 q if (keys.empty() && key_values.empty() && key_regexes.empty() && regkey_regexes.empty()
59015389 q && key_nregexes.empty() && key_nvalues.empty())
59111372 q return;
593 // generate set of relevant coarse indices
5944030 q std::map< uint32, std::vector< typename TObject::Id_Type > > ids_by_coarse;
5954030 q generate_ids_by_coarse(ids_by_coarse, items);
597 // formulate range query
5984030 q Ranges< Tag_Index_Local > ranges = formulate_range_query(ids_by_coarse);
600 // prepare straight keys
6014030 q std::map< std::string, std::pair< std::string, std::vector< Regular_Expression* > > > key_union;
6024630 q for (std::vector< std::string >::const_iterator it = keys.begin(); it != keys.end();
6034030 q ++it)
60463 q key_union[*it];
6056430 q for (std::vector< std::pair< std::string, std::string > >::const_iterator it = key_values.begin(); it != key_values.end();
6064030 q ++it)
6072420 q key_union[it->first].first = it->second;
6084030 q for (std::vector< std::pair< std::string, Regular_Expression* > >::const_iterator
6094630 q it = key_regexes.begin(); it != key_regexes.end(); ++it)
61064 q key_union[it->first].second.push_back(it->second);
612 // iterate over the result
6134030 q std::map< TIndex, std::vector< TObject > > result;
6144030 q std::map< TIndex, std::vector< Attic< TObject > > > attic_result;
6154030 q uint coarse_count = 0;
6174030 q Block_Backend< Tag_Index_Local, typename TObject::Id_Type > items_db
6184030 q (transaction.data_index(&file_prop));
6194030 q auto tag_it = items_db.range_begin(ranges);
6214030 q typename std::map< TIndex, std::vector< TObject > >::const_iterator item_it
6224030 q = items.begin();
6254030 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator it = ids_by_coarse.begin();
6264530 q it != ids_by_coarse.end(); ++it)
62853 q if (++coarse_count >= 1024)
6290 {
6300 coarse_count = 0;
6310 rman.health_check(*this);
6320 }
63353 q std::vector< typename TObject::Id_Type >& ids_by_coarse_ = it->second;
63553 q filter_ids_by_tags_old(ids_by_coarse_, key_union, regkey_regexes, items_db, tag_it, it->first);
637103 q while ((item_it != items.end()) &&
638103 q ((item_it->first.val() & 0x7fffff00) == it->first))
64053 q for (typename std::vector< TObject >::const_iterator eit = item_it->second.begin();
641173 q eit != item_it->second.end(); ++eit)
642123 q {
643123 q if (std::binary_search(ids_by_coarse_.begin(), ids_by_coarse_.end(), eit->id))
644123 q result[item_it->first.val()].push_back(*eit);
645123 q }
64653 q ++item_it;
6514030 q items.swap(result);
6534030 q if (key_nregexes.empty() && key_nvalues.empty())
6543326 q return;
656 // prepare negated keys
65776 q std::map< std::string, std::pair< std::vector< Regular_Expression* >, std::vector< std::string > > > nkey_union;
65876 q for (std::vector< std::pair< std::string, Regular_Expression* > >::const_iterator
659136 q it = key_nregexes.begin(); it != key_nregexes.end(); ++it)
66065 q nkey_union[it->first].first.push_back(it->second);
66176 q for (std::vector< std::pair< std::string, std::string > >::const_iterator
662106 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
66676 q result.clear();
66776 q attic_result.clear();
66876 q coarse_count = 0;
66976 q auto ntag_it = items_db.range_begin(ranges);
67076 q item_it = items.begin();
67376 q for (typename std::map< uint32, std::vector< typename TObject::Id_Type > >::iterator it = ids_by_coarse.begin();
67476 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 }
70176 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)
77411366 q if (invert)
7769960 q std::vector< Id > new_ids(rhs.size());
7779960 q new_ids.erase(std::set_difference(
7789960 q rhs.begin(), rhs.end(), ids.begin(), ids.end(), new_ids.begin()), new_ids.end());
7799960 q ids.swap(new_ids);
7809960 q invert = false;
7821410 q else
7841410 q std::vector< Id > new_ids(std::min(ids.size(), rhs.size()));
7851410 q new_ids.erase(std::set_intersection(
7861410 q ids.begin(), ids.end(), rhs.begin(), rhs.end(), new_ids.begin()), new_ids.end());
7871410 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)
796468311 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
797808311 q it != constraints.end() && answer_state < data_collected; ++it)
799340222 q if ((*it)->collect_nodes(rman, into, ids.ids, ids.invert))
8004034 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)
8091020489 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
8101804489 q it != constraints.end() && answer_state < data_collected; ++it)
812784396 q if ((*it)->collect(rman, into, type, ids.ids, ids.invert))
8137461 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)
832338216 q Ranges< Index > result;
834338216 q unsigned long long sum = 0;
835150404216 q for (auto it = range_a.begin(); it != range_a.end(); ++it)
836150066214 q sum += difference(it.lower_bound(), it.upper_bound());
838338216 q if (sum/256 < range_vec.size())
83910469 q return range_a;
841234166 q std::sort(range_vec.begin(), range_vec.end());
843234166 q auto it_a = range_a.begin();
844234166 q auto it_vec = range_vec.begin();
8461022500166 q while (it_a != range_a.end() && it_vec != range_vec.end())
8471022266166 q {
8481022266166 q if (!(it_a.lower_bound() < Index(it_vec->val() + 0x100)))
8495712 q ++it_vec;
8501022209166 q else if (!(*it_vec < it_a.upper_bound()))
85112138419 q ++it_a;
852900825161 q else if (Index(it_vec->val() + 0x100) < it_a.upper_bound())
853900790156 q {
854900790156 q result.push_back(std::max(it_a.lower_bound(), *it_vec), Index(it_vec->val() + 0x100));
855900790156 q ++it_vec;
856900790156 q }
857357 q else
858357 q {
859357 q result.push_back(std::max(it_a.lower_bound(), *it_vec), it_a.upper_bound());
860357 q ++it_a;
861357 q }
8621022266166 q }
864234166 q return result;
868void Query_Statement::apply_all_filters(
869 Resource_Manager& rman, uint64 timestamp, Query_Filter_Strategy check_keys_late, Set& into)
871990567 q set_progress(5);
872990567 q rman.health_check(*this);
874990567 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
8751904567 q it != constraints.end(); ++it)
876914469 q (*it)->filter(rman, into);
878990567 q set_progress(6);
879990567 q rman.health_check(*this);
881990567 q filter_attic_elements(rman, timestamp, into.nodes, into.attic_nodes);
882990567 q filter_attic_elements(rman, timestamp, into.ways, into.attic_ways);
883990567 q filter_attic_elements(rman, timestamp, into.relations, into.attic_relations);
885990567 q set_progress(7);
886990567 q rman.health_check(*this);
888990567 q if (check_keys_late == prefer_ranges)
890673447 q filter_by_tags(into.nodes, &into.attic_nodes, timestamp,
891673447 q *osm_base_settings().NODE_TAGS_LOCAL, attic_settings().NODE_TAGS_LOCAL,
892673447 q rman, *rman.get_transaction());
893673447 q filter_by_tags(into.ways, &into.attic_ways, timestamp,
894673447 q *osm_base_settings().WAY_TAGS_LOCAL, attic_settings().WAY_TAGS_LOCAL,
895673447 q rman, *rman.get_transaction());
896673447 q filter_by_tags(into.relations, &into.attic_relations, timestamp,
897673447 q *osm_base_settings().RELATION_TAGS_LOCAL, attic_settings().RELATION_TAGS_LOCAL,
898673447 q rman, *rman.get_transaction());
899673447 q if (rman.get_area_transaction())
90015389 q filter_by_tags(into.areas,
90115389 q *area_settings().AREA_TAGS_LOCAL,
90215389 q rman, *rman.get_transaction());
905990567 q set_progress(8);
906990567 q rman.health_check(*this);
908990567 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
9091904567 q it != constraints.end(); ++it)
910914469 q (*it)->filter(*this, rman, into);
914void filter_elems_for_closed_ways(Set& arg)
91613457 q filter_elems_for_closed_ways(arg.ways);
91713457 q filter_elems_for_closed_ways(arg.attic_ways);
921void Query_Statement::execute(Resource_Manager& rman)
923986567 q Cpu_Timer cpu(rman, 1);
925986567 q Answer_State node_answer_state = nothing;
926986567 q Answer_State way_answer_state = nothing;
927986567 q Answer_State relation_answer_state = nothing;
928986567 q Answer_State area_answer_state = nothing;
929986567 q Answer_State derived_answer_state = nothing;
930986567 q Set into;
931986567 q Set filtered;
932986567 q uint64 timestamp = rman.get_desired_timestamp();
933986567 q if (timestamp == 0)
9340 timestamp = NOW;
936986567 q set_progress(1);
937986567 q rman.health_check(*this);
939986567 q Query_Filter_Strategy check_keys_late = ids_required;
9401897567 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin(); it != constraints.end(); ++it)
941911469 q check_keys_late = std::max(check_keys_late, (*it)->delivers_data(rman));
944986567 q Id_Constraint< Node::Id_Type > node_ids;
945986567 q Id_Constraint< Way::Id_Type > way_ids;
946986567 q Id_Constraint< Relation::Id_Type > relation_ids;
947986567 q Id_Constraint< Area_Skeleton::Id_Type > area_ids;
949986567 q std::vector< Uint32_Index > range_vec_32;
950986567 q std::vector< Uint31_Index > way_range_vec_31;
951986567 q std::vector< Uint31_Index > relation_range_vec_31;
953986567 q if (type & QUERY_NODE)
955468311 q progress_1< Node_Skeleton, Node::Id_Type, Uint32_Index >(
956468311 q keys, key_values, key_regexes, regkey_regexes, key_nvalues, key_nregexes, regkey_nregexes,
957468311 q node_ids, range_vec_32, timestamp, check_keys_late, rman, *this);
958468311 q if (node_ids.empty())
95912056 q node_answer_state = data_collected;
960468311 q collect_nodes(node_ids, node_answer_state, into, rman);
962986567 q if (type & QUERY_WAY)
964592413 q progress_1< Way_Skeleton, Way::Id_Type, Uint31_Index >(
965592413 q keys, key_values, key_regexes, regkey_regexes, key_nvalues, key_nregexes, regkey_nregexes,
966592413 q way_ids, way_range_vec_31, timestamp, check_keys_late, rman, *this);
967592413 q if (way_ids.empty())
9687969 q way_answer_state = data_collected;
969592413 q collect_elems(QUERY_WAY, way_ids, way_answer_state, into, rman);
970592413 q if (type & QUERY_CLOSED_WAY)
9716757 q filter_elems_for_closed_ways(into);
973986567 q if (type & QUERY_RELATION)
975361281 q progress_1< Relation_Skeleton, Relation::Id_Type, Uint31_Index >(
976361281 q keys, key_values, key_regexes, regkey_regexes, key_nvalues, key_nregexes, regkey_nregexes,
977361281 q relation_ids, relation_range_vec_31, timestamp, check_keys_late, rman, *this);
978361281 q if (relation_ids.empty())
9797562 q relation_answer_state = data_collected;
980361281 q collect_elems(QUERY_RELATION, relation_ids, relation_answer_state, into, rman);
982986567 q if (type & QUERY_DERIVED)
9830 {
9840 collect_elems(derived_answer_state, into, rman);
9850 filter_by_tags(into.deriveds);
9860 }
987986567 q if (type & QUERY_AREA)
9896757 q try
9916757 q progress_1(
9926757 q keys, key_values, key_regexes, regkey_regexes, key_nvalues, key_nregexes, regkey_nregexes,
9936757 q area_ids, check_keys_late, rman, *this);
9946757 q if (area_ids.empty())
99565 q area_answer_state = data_collected;
9966757 q collect_elems(QUERY_AREA, area_ids, area_answer_state, into, rman);
9986757 q catch (const File_Error& e)
10000 if (e.error_number != ENOENT)
10010 throw;
10020 area_answer_state = data_collected;
10030 }
1006986567 q set_progress(2);
1007986567 q rman.health_check(*this);
1009986567 q if ((type & QUERY_NODE) && check_keys_late == prefer_ranges)
1011286220 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1012571220 q it != constraints.end() && node_answer_state < data_collected; ++it)
1014285191 q std::vector< Node::Id_Type > constraint_node_ids;
1015285191 q if ((*it)->get_node_ids(rman, constraint_node_ids))
10172518 q node_ids.restrict_to(constraint_node_ids);
10182518 q if (node_ids.empty())
101942 q node_answer_state = data_collected;
1023986567 q if ((type & QUERY_WAY) && check_keys_late == prefer_ranges)
1025414307 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1026831307 q it != constraints.end() && way_answer_state < data_collected; ++it)
1028417278 q std::vector< Way::Id_Type > constraint_way_ids;
1029417278 q if ((*it)->get_way_ids(rman, constraint_way_ids))
10313934 q way_ids.restrict_to(constraint_way_ids);
10323934 q if (way_ids.empty())
103332 q way_answer_state = data_collected;
1037986567 q if ((type & QUERY_RELATION) && check_keys_late == prefer_ranges)
1039246201 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1040480201 q it != constraints.end() && relation_answer_state < data_collected; ++it)
1042234179 q std::vector< Relation::Id_Type > constraint_relation_ids;
1043234179 q if ((*it)->get_relation_ids(rman, constraint_relation_ids))
10452621 q relation_ids.restrict_to(constraint_relation_ids);
10462621 q if (relation_ids.empty())
104742 q relation_answer_state = data_collected;
1051986567 q if ((type & QUERY_AREA) && check_keys_late == prefer_ranges)
10532824 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
10545624 q it != constraints.end() && area_answer_state < data_collected; ++it)
10562823 q std::vector< Area_Skeleton::Id_Type > constraint_area_ids;
10572823 q if ((*it)->get_area_ids(rman, constraint_area_ids))
10592320 q area_ids.restrict_to(constraint_area_ids);
10602320 q if (area_ids.empty())
10610 area_answer_state = data_collected;
1066986567 q Ranges< Uint32_Index > node_ranges = Ranges< Uint32_Index >::global();
1067986567 q Ranges< Uint31_Index > way_ranges = Ranges< Uint31_Index >::global();
1068986567 q Ranges< Uint31_Index > rel_ranges = Ranges< Uint31_Index >::global();
1070986567 q if ((type & QUERY_NODE) && node_answer_state < data_collected)
1072304250 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1073594250 q it != constraints.end(); ++it)
1074290200 q node_ranges.intersect((*it)->get_node_ranges(rman)).swap(node_ranges);
1076304250 q if (!range_vec_32.empty())
107710084 q intersect_ranges(node_ranges, range_vec_32).swap(node_ranges);
1079986567 q if ((type & QUERY_WAY) && way_answer_state < data_collected)
1081468357 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1082894357 q it != constraints.end(); ++it)
1083426288 q way_ranges.intersect((*it)->get_way_ranges(rman)).swap(way_ranges);
1085468357 q if (!way_range_vec_31.empty())
1086164142 q intersect_ranges(way_ranges, way_range_vec_31).swap(way_ranges);
1088986567 q if ((type & QUERY_RELATION) && relation_answer_state < data_collected)
1090250225 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1091497225 q it != constraints.end(); ++it)
1092247194 q rel_ranges.intersect((*it)->get_relation_ranges(rman)).swap(rel_ranges);
1094250225 q if (!relation_range_vec_31.empty())
10957465 q intersect_ranges(rel_ranges, relation_range_vec_31).swap(rel_ranges);
1098986567 q set_progress(3);
1099986567 q rman.health_check(*this);
1101986567 q if (type & QUERY_NODE)
1103468311 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1104758311 q it != constraints.end() && node_answer_state < data_collected; ++it)
1106290200 q if ((*it)->get_data(*this, rman, into, node_ranges, node_ids.ids, node_ids.invert))
1107119 q node_answer_state = data_collected;
1110986567 q if (type & QUERY_WAY)
1112592413 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
11131018413 q it != constraints.end() && way_answer_state < data_collected; ++it)
1115426288 q if ((*it)->get_data(*this, rman, into, way_ranges, type & QUERY_WAY, way_ids.ids, way_ids.invert))
11172523 q if (type & QUERY_CLOSED_WAY)
11180 filter_elems_for_closed_ways(into);
11192523 q way_answer_state = data_collected;
1123986567 q if (type & QUERY_RELATION)
1125361281 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
1126608281 q it != constraints.end() && relation_answer_state < data_collected; ++it)
1128247194 q if ((*it)->get_data(*this, rman, into, rel_ranges, type & QUERY_RELATION,
1129247194 q relation_ids.ids, relation_ids.invert))
11303030 q relation_answer_state = data_collected;
1133986567 q if (type & QUERY_AREA)
11356757 q for (std::vector< Query_Constraint* >::iterator it = constraints.begin();
11369557 q it != constraints.end() && area_answer_state < data_collected; ++it)
11382823 q if ((*it)->get_data(*this, rman, into, {}, type & QUERY_AREA, area_ids.ids, area_ids.invert))
11390 area_answer_state = data_collected;
1143986567 q set_progress(4);
1144986567 q rman.health_check(*this);
1146986567 q if (type & QUERY_NODE)
1148468311 q if (node_answer_state < data_collected)
1150293242 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 }
1167293242 q Collect_Items< Uint32_Index, Node_Skeleton > db_reader(
1168293242 q node_ids.ids, node_ids.invert, node_ranges, *this, rman);
1169293242 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 }
1180986567 q if (type & QUERY_WAY)
1182592413 q if (way_answer_state < data_collected)
1184443344 q if (way_ranges.is_global())
118644 q if (way_ids.invert)
118833 q if (way_ids.ids.empty())
118922 q runtime_error("Filters too weak in query statement: specify in addition a bbox, a tag filter, or similar.");
119111 q else
119311 q way_ranges = Ranges< Uint31_Index >();
119411 q std::vector< Uint31_Index > req = get_indexes_< Uint31_Index, Way_Skeleton >(way_ids.ids, rman);
1195120941 q for (std::vector< Uint31_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
1196120931 q way_ranges.push_back(*it, inc(*it));
119711 q way_ranges.sort();
1201443344 q Collect_Items< Uint31_Index, Way_Skeleton > db_reader(
1202443344 q way_ids.ids, way_ids.invert, way_ranges, *this, rman);
1203447344 q while (db_reader.get_chunk(into.ways, into.attic_ways))
120544 q Set to_filter;
120644 q to_filter.ways.swap(into.ways);
120744 q to_filter.attic_ways.swap(into.attic_ways);
120844 q 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 }
121344 q apply_all_filters(rman, timestamp, check_keys_late, to_filter);
121444 q indexed_set_union(filtered.ways, to_filter.ways);
121544 q indexed_set_union(filtered.attic_ways, to_filter.attic_ways);
1219986567 q if (type & QUERY_RELATION)
1221361281 q if (relation_answer_state < data_collected)
1223220201 q if (rel_ranges.is_global())
12251111 q if (!relation_ids.invert)
122711 q rel_ranges = Ranges< Uint31_Index >();
122811 q std::vector< Uint31_Index > req = get_indexes_< Uint31_Index, Relation_Skeleton >(relation_ids.ids, rman);
1229120711 q for (std::vector< Uint31_Index >::const_iterator it = req.begin(); it != req.end(); ++it)
1230120701 q rel_ranges.push_back(*it, inc(*it));
123111 q rel_ranges.sort();
1235220201 q Collect_Items< Uint31_Index, Relation_Skeleton > db_reader(
1236220201 q relation_ids.ids, relation_ids.invert, rel_ranges, *this, rman);
1237220201 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 }
1248986567 q if (type & QUERY_AREA)
12506757 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.");
12526757 q try
12546757 q if (area_answer_state < data_collected)
12556153 q get_elements_by_id_from_db(into.areas, area_ids.ids, area_ids.invert, rman, *area_settings().AREAS);
12576757 q catch (const File_Error& e)
12590 if (e.error_number != ENOENT)
12600 throw;
12610 }
1265986567 q if (type & QUERY_CLOSED_WAY)
12666757 q filter_elems_for_closed_ways(into);
1267986567 q apply_all_filters(rman, timestamp, check_keys_late, into);
1268986567 q indexed_set_union(into.nodes, filtered.nodes);
1269986567 q indexed_set_union(into.attic_nodes, filtered.attic_nodes);
1270986567 q indexed_set_union(into.ways, filtered.ways);
1271986567 q indexed_set_union(into.attic_ways, filtered.attic_ways);
1272986567 q indexed_set_union(into.relations, filtered.relations);
1273986567 q indexed_set_union(into.attic_relations, filtered.attic_relations);
1274986567 q indexed_set_union(into.areas, filtered.areas);
1275986567 q indexed_set_union(into.deriveds, filtered.deriveds);
1277986567 q set_progress(9);
1278986567 q rman.health_check(*this);
1280986567 q clear_empty_indices(into.nodes);
1281986567 q clear_empty_indices(into.attic_nodes);
1282986567 q clear_empty_indices(into.ways);
1283986567 q clear_empty_indices(into.attic_ways);
1284986567 q clear_empty_indices(into.relations);
1285986567 q clear_empty_indices(into.deriveds);
1286986567 q clear_empty_indices(into.areas);
1288986567 q transfer_output(rman, into);
1289986567 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)
12981731376 q : Statement(line_number_), regex(0), key_regex(0), straight(true), case_sensitive(false)
13001731376 q std::map< std::string, std::string > attributes;
13021731376 q attributes["k"] = "";
13031731376 q attributes["regk"] = "";
13041731376 q attributes["v"] = "";
13051731376 q attributes["regv"] = "";
13061731376 q attributes["modv"] = "";
13071731376 q attributes["case"] = "sensitive";
13091731376 q eval_attributes_array(get_name(), attributes, input_attributes);
13111731376 q key = attributes["k"];
13121731376 q value = attributes["v"];
13141731376 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 }
13221731376 q if (attributes["case"] != "ignore")
13231713376 q {
13241713376 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\".");
13271713376 q case_sensitive = true;
13281713376 q }
13301731376 q if (attributes["regk"] != "")
133215345 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 }
133915345 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 }
134615345 q try
134815345 q key_regex = new Regular_Expression(attributes["regk"], case_sensitive);
134915345 q key = attributes["regk"];
135115345 q catch (Regular_Expression_Error e)
13530 add_static_error("Invalid regular expression: \"" + attributes["regk"] + "\"");
13540 }
13571731376 q if (attributes["regv"] != "")
1359513138 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 }
1367513138 q try
1369513138 q regex = new Regular_Expression(attributes["regv"], case_sensitive);
1370513138 q value = attributes["regv"];
1372513138 q catch (Regular_Expression_Error e)
137431 q add_static_error("Invalid regular expression: \"" + attributes["regv"] + "\"");
13781731376 q if (attributes["modv"] == "" || attributes["modv"] == "not")
13791731376 q {
13801731376 q if (attributes["modv"] == "not")
138230685 q if (attributes["regk"] == "")
138330685 q straight = false;
13840 else
13850 add_static_error("In the element \"has-kv\" regular expressions on keys cannot be combined"
13860 " with negation.");
13881731376 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()
14001731376 q delete key_regex;
14011731376 q delete regex;