1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al. 3 * This file is part of Overpass_API. 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. 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. 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/>. 26#include "../../template_db/block_backend.h" 27#include "../../template_db/random_file.h" 28#include "../core/settings.h" 29#include "../data/abstract_processing.h" 30#include "../data/collect_members.h" 31#include "../data/utils.h" 35const unsigned int RECURSE_RELATION_RELATION = 1; 36const unsigned int RECURSE_RELATION_BACKWARDS = 2; 37const unsigned int RECURSE_RELATION_WAY = 3; 38const unsigned int RECURSE_RELATION_NODE = 4; 39const unsigned int RECURSE_RELATION_NWR = 5; 40const unsigned int RECURSE_RELATION_NW = 6; 41const unsigned int RECURSE_RELATION_WR = 7; 42const unsigned int RECURSE_RELATION_NR = 8; 43const unsigned int RECURSE_WAY_NODE = 9; 44const unsigned int RECURSE_WAY_LINK = 10; 45const unsigned int RECURSE_WAY_COUNT = 11; 46const unsigned int RECURSE_WAY_RELATION = 12; 47const unsigned int RECURSE_NODE_RELATION = 13; 48const unsigned int RECURSE_NODE_WAY = 14; 49const unsigned int RECURSE_NODE_WR = 15; 50const unsigned int RECURSE_DOWN = 16; 51const unsigned int RECURSE_DOWN_REL = 17; 52const unsigned int RECURSE_UP = 18; 53const unsigned int RECURSE_UP_REL = 19; 56Recurse_Statement::Statement_Maker Recurse_Statement::statement_maker; 57Recurse_Statement::Criterion_Maker_1 Recurse_Statement::criterion_maker_1; 58Recurse_Statement::Criterion_Maker_2 Recurse_Statement::criterion_maker_2; 61Statement* Recurse_Statement::Criterion_Maker_1::create_criterion(const Token_Node_Ptr& input_tree, 62 const std::string& result_type, const std::string& into, 63 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output) 65724150 q Token_Node_Ptr tree_it = input_tree; 66724150 q uint line_nr = tree_it->line_col.first; 69724150 q std::vector< std::string > roles; 70724150 q std::string lower, upper; 71724150 q bool role_found = false; 73732150 q while (tree_it->token == "," && tree_it->rhs && tree_it->lhs) 7582 q roles.push_back(tree_it.rhs()->token); 7682 q tree_it = tree_it.lhs(); 79724150 q if (tree_it->token == ":" && tree_it->rhs) 8230871 q if (tree_it.rhs()->token == "-") 8413231 q if (tree_it.rhs()->lhs) 8513231 q lower = tree_it.rhs().lhs()->token; 8613231 q if (tree_it.rhs()->rhs) 87246 q upper = tree_it.rhs().rhs()->token; 8917641 q else if (!tree_it.rhs()->lhs && !tree_it.rhs()->rhs) 9017641 q roles.push_back(decode_json(tree_it.rhs()->token, error_output)); 920 error_output->add_parse_error("Simple role token expected, structured syntax tree found.", line_nr); 9330871 q tree_it = tree_it.lhs(); 96724150 q if (tree_it->token == "." && tree_it->rhs) 98684146 q from = tree_it.rhs()->token; 99684146 q tree_it = tree_it.lhs(); 102724150 q std::string type = tree_it->token; 103724150 q std::map< std::string, std::string > attributes; 10916038 q if (result_type == "node") 1104010 q attributes["type"] = "relation-node"; 11112029 q else if (result_type == "way") 1126416 q attributes["type"] = "relation-way"; 1135614 q else if (result_type == "relation") 1145614 q attributes["type"] = "relation-relation"; 1150 else if (result_type == "nwr") 1160 attributes["type"] = "relation-nwr"; 1170 else if (result_type == "nw") 1180 attributes["type"] = "relation-nw"; 1190 else if (result_type == "wr") 1200 attributes["type"] = "relation-wr"; 1210 else if (result_type == "nr") 1220 attributes["type"] = "relation-nr"; 1230 else if (error_output) 1240 error_output->add_parse_error("A recursion of type 'r' produces nodes, ways, or relations.", line_nr); 1289223 q if (result_type == "node") 1299223 q attributes["type"] = "way-node"; 1300 else if (error_output) 1310 error_output->add_parse_error("A recursion of type 'w' produces nodes.", line_nr); 133472110 q else if (type == "way_link") 1357218 q if (result_type == "node") 1367218 q attributes["type"] = "way-link"; 1370 else if (error_output) 1380 error_output->add_parse_error("A recursion of type 'way_link' produces nodes.", line_nr); 14040095 q else if (type == "way_cnt") 14212029 q if (result_type == "node") 14312029 q attributes["type"] = "way-count"; 1440 else if (error_output) 1450 error_output->add_parse_error("A recursion of type 'way_cnt' produces nodes.", line_nr); 1494812 q if (result_type == "relation") 1504812 q attributes["type"] = "relation-backwards"; 1510 else if (error_output) 1520 error_output->add_parse_error("A recursion of type 'br' produces relations.", line_nr); 1566416 q if (result_type == "relation") 1576416 q attributes["type"] = "way-relation"; 1580 else if (error_output) 1590 error_output->add_parse_error("A recursion of type 'bw' produces relations.", line_nr); 16316842 q if (result_type == "way") 1647619 q attributes["type"] = "node-way"; 1659223 q else if (result_type == "relation") 1665213 q attributes["type"] = "node-relation"; 1674010 q else if (result_type == "wr") 1684010 q attributes["type"] = "node-wr"; 1690 else if (error_output) 1700 error_output->add_parse_error("A recursion of type 'bn' produces ways or relations.", line_nr); 17730871 q if (type == "r" || result_type == "relation") 1799222 q attributes["role"] = roles.back(); 1809222 q attributes["role-restricted"] = "yes"; 18221651 q else if (type == "w" || result_type == "way") 184246 q attributes["pos"] = roles[0]; 185326 q for (uint i = 1; i < roles.size(); ++i) 18682 q attributes["pos"] += "," + roles[i]; 18819246 q else if (type == "way_cnt" || type == "way_link") 19413231 q attributes["lower"] = lower; 19513231 q attributes["upper"] = upper; 1996015 q attributes["lower"] = roles.back(); 2006015 q attributes["upper"] = roles.back(); 2030 else if (error_output) 2040 error_output->add_parse_error("A recursion of type 'way_cnt' or 'way_link' must have a parameter.", line_nr); 2060 else if (error_output) 2070 error_output->add_parse_error("A recursion of type '" + type + "' cannot have restrictions.", line_nr); 209724150 q return new Recurse_Statement(line_nr, attributes, global_settings); 213Statement* Recurse_Statement::Criterion_Maker_2::create_criterion(const Token_Node_Ptr& input_tree, 214 const std::string& result_type, const std::string& into, 215 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output) 21741 q Token_Node_Ptr tree_it = input_tree; 21841 q uint line_nr = tree_it->line_col.first; 22041 q std::string from = "_"; 22241 q if (tree_it->token == "." && tree_it->rhs) 2240 from = tree_it.rhs()->token; 2250 tree_it = tree_it.lhs(); 22841 q std::string type = tree_it->token; 22941 q std::map< std::string, std::string > attributes; 23041 q attributes["from"] = from; 23141 q attributes["into"] = into; 23441 q attributes["type"] = "down"; 2350 else if (type == ">>") 2360 attributes["type"] = "down-rel"; 2370 else if (type == "<") 2380 attributes["type"] = "up"; 2390 else if (type == "<<") 2400 attributes["type"] = "up-rel"; 24441 q return new Recurse_Statement(line_nr, attributes, global_settings); 248//----------------------------------------------------------------------------- 251template< class TSourceIndex, class TSourceObject > 252Timeless< Uint31_Index, Relation_Skeleton > collect_relations 253 (const Statement& stmt, Resource_Manager& rman, 254 const std::map< TSourceIndex, std::vector< TSourceObject > >& sources, 255 const std::map< TSourceIndex, std::vector< Attic< TSourceObject > > >& attic_sources, 257 const std::vector< Relation::Id_Type >& ids, bool invert_ids) 25922173 q Timeless< Uint31_Index, Relation_Skeleton > result; 26122173 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources); 26222173 q std::set< Uint31_Index > req = extract_parent_indices(sources); 26322173 q rman.health_check(stmt); 26522173 q if (rman.get_desired_timestamp() != NOW) 2676334 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources); 2686334 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_sources); 2716334 q std::vector< Uint64 > children_ids; 2726334 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 2736334 q std::back_inserter(children_ids)); 274409934 q for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it) 2766334 q current_ids.swap(children_ids); 27922173 q Request_Context context(&stmt, rman); 28166 q collect_items_discrete(context, req, 28266 q And_Predicate< Relation_Skeleton, 28366 q Id_Predicate< Relation_Skeleton >, Get_Parent_Rels_Predicate > 28466 q (Id_Predicate< Relation_Skeleton >(ids), 28566 q Get_Parent_Rels_Predicate(current_ids, source_type)), result.current, result.attic); 28721568 q collect_items_discrete(context, req, 28821568 q Get_Parent_Rels_Predicate(current_ids, source_type), result.current, result.attic); 2900 collect_items_discrete(context, req, 2910 And_Predicate< Relation_Skeleton, 2920 Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > >, 2930 Get_Parent_Rels_Predicate > 2940 (Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > > 2950 (Id_Predicate< Relation_Skeleton >(ids)), 2960 Get_Parent_Rels_Predicate(current_ids, source_type)), result.current, result.attic); 302template< class TSourceIndex, class TSourceObject > 303Timeless< Uint31_Index, Relation_Skeleton > collect_relations 304 (const Statement& stmt, Resource_Manager& rman, 305 const std::map< TSourceIndex, std::vector< TSourceObject > >& sources, 306 const std::map< TSourceIndex, std::vector< Attic< TSourceObject > > >& attic_sources, 308 const std::vector< Relation::Id_Type >& ids, bool invert_ids, uint32 role_id) 31076 q Timeless< Uint31_Index, Relation_Skeleton > result; 31276 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources); 31376 q rman.health_check(stmt); 31476 q std::set< Uint31_Index > req = extract_parent_indices(sources); 31576 q rman.health_check(stmt); 31776 q if (rman.get_desired_timestamp() != NOW) 31933 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources); 32033 q rman.health_check(stmt); 32133 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_sources); 32233 q rman.health_check(stmt); 32433 q std::vector< Uint64 > children_ids; 32533 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 32633 q std::back_inserter(children_ids)); 3271473 q for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it) 32933 q current_ids.swap(children_ids); 33276 q Request_Context context(&stmt, rman); 33411 q collect_items_discrete(context, req, 33511 q And_Predicate< Relation_Skeleton, 33611 q Id_Predicate< Relation_Skeleton >, Get_Parent_Rels_Role_Predicate > 33711 q (Id_Predicate< Relation_Skeleton >(ids), 33811 q Get_Parent_Rels_Role_Predicate(current_ids, source_type, role_id)), result.current, result.attic); 34065 q collect_items_discrete(context, req, 34165 q Get_Parent_Rels_Role_Predicate(current_ids, source_type, role_id), result.current, result.attic); 3430 collect_items_discrete(context, req, 3440 And_Predicate< Relation_Skeleton, 3450 Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > >, 3460 Get_Parent_Rels_Role_Predicate > 3470 (Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > > 3480 (Id_Predicate< Relation_Skeleton >(ids)), 3490 Get_Parent_Rels_Role_Predicate(current_ids, source_type, role_id)), result.current, result.attic); 355Timeless< Uint31_Index, Relation_Skeleton > collect_relations 356 (const Statement& stmt, Resource_Manager& rman, 357 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& sources, 358 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_sources, 359 const std::vector< Relation::Id_Type >& ids, bool invert_ids) 3616530 q Timeless< Uint31_Index, Relation_Skeleton > result; 3636530 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources); 3666530 q if (rman.get_desired_timestamp() != NOW) 3681812 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources); 3711812 q std::vector< Uint64 > children_ids; 3721812 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 3731812 q std::back_inserter(children_ids)); 3741812 q current_ids.swap(children_ids); 3776530 q Request_Context context(&stmt, rman); 37922 q collect_items_flat(context, 38022 q And_Predicate< Relation_Skeleton, 38122 q Id_Predicate< Relation_Skeleton >, Get_Parent_Rels_Predicate > 38222 q (Id_Predicate< Relation_Skeleton >(ids), 38322 q Get_Parent_Rels_Predicate(current_ids, Relation_Entry::RELATION)), 38422 q result.current, result.attic); 3866328 q collect_items_flat(context, 3876328 q Get_Parent_Rels_Predicate(current_ids, Relation_Entry::RELATION), result.current, result.attic); 3890 collect_items_flat(context, 3900 And_Predicate< Relation_Skeleton, 3910 Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > >, 3920 Get_Parent_Rels_Predicate > 3930 (Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > > 3940 (Id_Predicate< Relation_Skeleton >(ids)), 3950 Get_Parent_Rels_Predicate(current_ids, Relation_Entry::RELATION)), 3960 result.current, result.attic); 402Timeless< Uint31_Index, Relation_Skeleton > collect_relations 403 (const Statement& stmt, Resource_Manager& rman, 404 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& sources, 405 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_sources, 406 const std::vector< Relation::Id_Type >& ids, bool invert_ids, uint32 role_id) 40822 q Timeless< Uint31_Index, Relation_Skeleton > result; 41022 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources); 41122 q rman.health_check(stmt); 41322 q Request_Context context(&stmt, rman); 41422 q if (rman.get_desired_timestamp() != NOW) 41611 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources); 41711 q rman.health_check(stmt); 41911 q std::vector< Uint64 > children_ids; 42011 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 42111 q std::back_inserter(children_ids)); 42211 q current_ids.swap(children_ids); 4260 collect_items_flat(context, 4270 And_Predicate< Relation_Skeleton, 4280 Id_Predicate< Relation_Skeleton >, Get_Parent_Rels_Role_Predicate > 4290 (Id_Predicate< Relation_Skeleton >(ids), 4300 Get_Parent_Rels_Role_Predicate(current_ids, Relation_Entry::RELATION, role_id)), 4310 result.current, result.attic); 43322 q collect_items_flat(context, 43422 q Get_Parent_Rels_Role_Predicate(current_ids, Relation_Entry::RELATION, role_id), 43522 q result.current, result.attic); 4370 collect_items_flat(context, 4380 And_Predicate< Relation_Skeleton, 4390 Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > >, 4400 Get_Parent_Rels_Role_Predicate > 4410 (Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > > 4420 (Id_Predicate< Relation_Skeleton >(ids)), 4430 Get_Parent_Rels_Role_Predicate(current_ids, Relation_Entry::RELATION, role_id)), 4440 result.current, result.attic); 450Timeless< Uint31_Index, Relation_Skeleton > relations_loop( 451 const Statement& query, Resource_Manager& rman, 452 const std::map< Uint31_Index, std::vector< Relation_Skeleton > >& source, 453 const std::map< Uint31_Index, std::vector< Attic< Relation_Skeleton > > >& attic_source) 4551816 q Request_Context context(&query, rman); 4561816 q auto working_set = Timeless< Uint31_Index, Relation_Skeleton >{ source, attic_source }; 4591816 q uint new_rel_count = count(working_set.current) + count(working_set.attic); 4603516 q while (old_rel_count < new_rel_count) 4621712 q old_rel_count = new_rel_count; 4631712 q auto new_results = relation_relation_members( 4641712 q context, working_set.current, working_set.attic, Ranges< Uint31_Index >::global(), {}, true); 4651712 q working_set.set_union(new_results.sort()); 4661712 q keep_matching_skeletons(working_set.current, working_set.attic, context.get_desired_timestamp()); 4671712 q new_rel_count = count(working_set.current) + count(working_set.attic); 473Timeless< Uint31_Index, Relation_Skeleton > relations_up_loop( 474 const Statement& query, Resource_Manager& rman, 475 Timeless< Uint31_Index, Relation_Skeleton >&& working_set) 4793226 q uint new_rel_count = count(working_set.current) + count(working_set.attic); 4808626 q while (old_rel_count < new_rel_count) 4825420 q old_rel_count = new_rel_count; 4835420 q auto new_results = collect_relations(query, rman, working_set.current, working_set.attic, {}, true); 4845420 q working_set.set_union(new_results.sort()); 4855420 q keep_matching_skeletons(working_set.current, working_set.attic, rman.get_desired_timestamp()); 4865420 q new_rel_count = count(working_set.current) + count(working_set.attic); 4883226 q return std::move(working_set); 492template< typename Index, typename Object > 493Ranges< Uint31_Index > extract_parent_indices( 494 const std::map< Index, std::vector< Object > >& cur_elems, 495 const std::map< Index, std::vector< Attic< Object > > >& attic_elems) 4972927 q Ranges< Uint31_Index > result; 4992927 q std::set< Uint31_Index > req = extract_parent_indices(cur_elems); 5011922027 q result.push_back(i, inc(i)); 5032927 q if (!attic_elems.empty()) 50566 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_elems); 50666 q for (auto i : attic_req) 5074906 q result.push_back(i, inc(i)); 515Timeless< Uint32_Index, Node_Skeleton > recurse_down_nodes( 516 const Statement& query, Resource_Manager& rman, 517 const Ranges< Uint32_Index >& ranges, const std::vector< Node::Id_Type >& ids, bool invert_ids, 518 const Timeless< Uint31_Index, Relation_Skeleton >& rels) 5200 Request_Context context(&query, rman); 5220 Timeless< Uint32_Index, Node_Skeleton > rel_nodes = 5230 relation_node_members(context, rels.current, rels.attic, ranges, ids, invert_ids); 5260 relation_way_members(context, rels.current, rels.attic, Ranges< Uint31_Index >::global(), {}, true); 5280 Timeless< Uint32_Index, Node_Skeleton > way_nodes = 5290 way_members(context, rel_ways.current, rel_ways.attic, 0, ranges, ids, invert_ids); 5300 way_nodes.sort().set_union(rel_nodes.sort()); 5310 keep_matching_skeletons(way_nodes.current, way_nodes.attic, rman.get_desired_timestamp()); 537//----------------------------------------------------------------------------- 539class Recurse_Constraint : public Query_Constraint 54217455 q Recurse_Constraint(Recurse_Statement& stmt_) : stmt(&stmt_) {} 544 Ranges< Uint32_Index > get_node_ranges(Resource_Manager& rman) override; 545 Ranges< Uint31_Index > get_way_ranges(Resource_Manager& rman) override; 546 Ranges< Uint31_Index > get_relation_ranges(Resource_Manager& rman) override; 5486655 q Query_Filter_Strategy delivers_data(Resource_Manager& rman) override { return prefer_ranges; } 550 virtual bool get_data(const Statement& query, Resource_Manager& rman, Set& into, 551 const Ranges< Uint32_Index >& ranges, 552 const std::vector< Node::Id_Type >& ids, 553 bool invert_ids) override; 554 virtual bool get_data(const Statement& query, Resource_Manager& rman, Set& into, 555 const Ranges< Uint31_Index >& ranges, 557 const std::vector< Uint32_Index >& ids, 558 bool invert_ids) override; 559 void filter(Resource_Manager& rman, Set& into) override; 560 void filter(const Statement& query, Resource_Manager& rman, Set& into) override; 5610 virtual ~Recurse_Constraint() {} 564 Recurse_Statement* stmt; 568Ranges< Uint32_Index > Recurse_Constraint::get_node_ranges(Resource_Manager& rman) 57098 q const Set* input = rman.get_set(stmt->get_input()); 57222 q return Ranges< Uint32_Index >(); 57476 q if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 57576 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR) 57622 q return relation_node_member_indices(input->relations, input->attic_relations); 57754 q else if (stmt->get_type() == RECURSE_WAY_NODE || stmt->get_type() == RECURSE_WAY_LINK 57854 q || stmt->get_type() == RECURSE_WAY_COUNT) 57954 q return way_nd_indices(input->ways, input->attic_ways); 5810 return Ranges< Uint32_Index >::global(); 585Ranges< Uint31_Index > Recurse_Constraint::get_way_ranges(Resource_Manager& rman) 5872421 q const Set* input = rman.get_set(stmt->get_input()); 58921 q return Ranges< Uint31_Index >(); 5912220 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR 5922220 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_WR) 59354 q return relation_way_member_indices(input->relations, input->attic_relations); 5941716 q else if (stmt->get_type() == RECURSE_NODE_WAY) 5951312 q return extract_parent_indices(input->nodes, input->attic_nodes); 59744 q return Ranges< Uint31_Index >::global(); 601Ranges< Uint31_Index > Recurse_Constraint::get_relation_ranges(Resource_Manager& rman) 6033029 q const Set* input = rman.get_set(stmt->get_input()); 6050 return Ranges< Uint31_Index >(); 6073029 q if (stmt->get_type() == RECURSE_NODE_RELATION) 60866 q return extract_parent_indices(input->nodes, input->attic_nodes); 6092423 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 610109 q return extract_parent_indices(input->ways, input->attic_ways); 6121414 q return Ranges< Uint31_Index >::global(); 616bool Recurse_Constraint::get_data 617 (const Statement& query, Resource_Manager& rman, Set& into, 618 const Ranges< Uint32_Index >& ranges, 619 const std::vector< Node::Id_Type >& ids, 62298 q const Set* input = rman.get_set(stmt->get_input()); 62676 q Request_Context context(&query, rman); 62911 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role()); 63011 q if (role_id != std::numeric_limits< uint32 >::max() 63111 q && (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 63211 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR)) 63311 q relation_node_members( 63411 q context, input->relations, input->attic_relations, ranges, ids, invert_ids, &role_id) 63511 q .swap(into.nodes, into.attic_nodes); 63765 q else if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 63865 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR) 63911 q relation_node_members( 64011 q context, input->relations, input->attic_relations, ranges, ids, invert_ids) 64111 q .swap(into.nodes, into.attic_nodes); 64254 q else if (stmt->get_type() == RECURSE_WAY_NODE) 64454 q context, input->ways, input->attic_ways, stmt->get_pos(), ranges, ids, invert_ids) 64554 q .swap(into.nodes, into.attic_nodes); 6460 else if (stmt->get_type() == RECURSE_WAY_COUNT) 6480 context, input->ways, input->attic_ways, stmt->get_lower(), stmt->get_upper(), 6490 ranges, ids, invert_ids) 6500 .swap(into.nodes, into.attic_nodes); 6510 else if (stmt->get_type() == RECURSE_WAY_LINK) 6530 context, input->ways, input->attic_ways, stmt->get_lower(), stmt->get_upper(), 6540 ranges, ids, invert_ids) 6550 .swap(into.nodes, into.attic_nodes); 6560 else if (stmt->get_type() == RECURSE_DOWN) 6570 recurse_down_nodes(query, rman, ranges, ids, invert_ids, {input->relations, input->attic_relations}) 6580 .swap(into.nodes, into.attic_nodes); 6590 else if (stmt->get_type() == RECURSE_DOWN_REL) 6610 query, rman, ranges, ids, invert_ids, 6620 relations_loop(query, rman, input->relations, input->attic_relations)) 6630 .swap(into.nodes, into.attic_nodes); 669bool Recurse_Constraint::get_data 670 (const Statement& query, Resource_Manager& rman, Set& into, 671 const Ranges< Uint31_Index >& ranges, 673 const std::vector< Uint32_Index >& ids, 6765445 q const Set* input = rman.get_set(stmt->get_input()); 6805244 q Request_Context context(&query, rman); 68375 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role()); 68475 q if (role_id == std::numeric_limits< uint32 >::max()) 68775 q if (stmt->get_type() == RECURSE_RELATION_WAY 68875 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_WAY) 68975 q || (stmt->get_type() == RECURSE_RELATION_NW && type == QUERY_WAY) 69075 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_WAY)) 69121 q collect_ways(context, input->relations, input->attic_relations, ranges, ids, invert_ids, &role_id) 69221 q .swap(into.ways, into.attic_ways); 69354 q else if (stmt->get_type() == RECURSE_RELATION_RELATION 69454 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_RELATION) 69554 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_RELATION) 69654 q || (stmt->get_type() == RECURSE_RELATION_NR && type == QUERY_RELATION)) 6970 relation_relation_members( 6980 context, input->relations, input->attic_relations, ranges, ids, invert_ids, &role_id) 6990 .swap(into.relations, into.attic_relations); 70054 q else if (stmt->get_type() == RECURSE_NODE_RELATION) 7020 query, rman, input->nodes, input->attic_nodes, Relation_Entry::NODE, ids, invert_ids, role_id) 7030 .swap(into.relations, into.attic_relations); 70454 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 70554 q collect_relations(query, rman, input->ways, input->attic_ways, Relation_Entry::WAY, ids, invert_ids, role_id) 70654 q .swap(into.relations, into.attic_relations); 7070 else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS) 7080 collect_relations(query, rman, input->relations, input->attic_relations, ids, invert_ids, role_id) 7090 .swap(into.relations, into.attic_relations); 7134539 q else if (stmt->get_type() == RECURSE_RELATION_WAY 7144539 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_WAY) 7154539 q || (stmt->get_type() == RECURSE_RELATION_NW && type == QUERY_WAY) 7164539 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_WAY)) 71733 q collect_ways(context, input->relations, input->attic_relations, ranges, ids, invert_ids) 71833 q .swap(into.ways, into.attic_ways); 7194236 q else if (stmt->get_type() == RECURSE_RELATION_RELATION 7204236 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_RELATION) 7214236 q || (stmt->get_type() == RECURSE_RELATION_NR && type == QUERY_RELATION) 7224236 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_RELATION)) 72355 q relation_relation_members( 72455 q context, input->relations, input->attic_relations, ranges, ids, invert_ids, 0) 72555 q .swap(into.relations, into.attic_relations); 7263732 q else if (stmt->get_type() == RECURSE_DOWN) 7280 if (type != QUERY_WAY) 7300 collect_ways(context, input->relations, input->attic_relations, ranges, ids, invert_ids) 7310 .swap(into.ways, into.attic_ways); 7333732 q else if (stmt->get_type() == RECURSE_DOWN_REL) 7350 Timeless< Uint31_Index, Relation_Skeleton > rel_rels = 7360 relations_loop(query, rman, input->relations, input->attic_relations); 7380 if (type == QUERY_WAY) 7390 collect_ways(context, rel_rels.current, rel_rels.attic, ranges, ids, invert_ids) 7400 .swap(into.ways, into.attic_ways); 7460 rel_rels.filter_items(Id_Predicate< Relation_Skeleton >(ids)); 7480 rel_rels.filter_items( 7490 Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > >( 7500 Id_Predicate< Relation_Skeleton >(ids))); 7520 keep_matching_skeletons(rel_rels.current, rel_rels.attic, rman.get_desired_timestamp()); 7530 rel_rels.swap(into.relations, into.attic_relations); 7563732 q else if (stmt->get_type() == RECURSE_NODE_WAY) 7571312 q collect_ways(context, input->nodes, input->attic_nodes, stmt->get_pos(), ids, invert_ids) 7581312 q .swap(into.ways, into.attic_ways); 7592420 q else if (stmt->get_type() == RECURSE_NODE_RELATION) 76066 q collect_relations(query, rman, input->nodes, input->attic_nodes, Relation_Entry::NODE, ids, invert_ids) 76166 q .swap(into.relations, into.attic_relations); 7621814 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 76355 q collect_relations(query, rman, input->ways, input->attic_ways, Relation_Entry::WAY, ids, invert_ids) 76455 q .swap(into.relations, into.attic_relations); 765139 q else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS) 76655 q collect_relations(query, rman, input->relations, input->attic_relations, ids, invert_ids) 76755 q .swap(into.relations, into.attic_relations); 76884 q else if (stmt->get_type() == RECURSE_UP) 7700 if (type == QUERY_WAY) 7710 collect_ways(context, input->nodes, input->attic_nodes, 0, ids, invert_ids) 7720 .swap(into.ways, into.attic_ways); 7750 auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input->ways, input->attic_ways }; 7770 rel_ways.set_union(collect_ways(context, input->nodes, input->attic_nodes, 0, {}, true).sort()); 7800 collect_relations(query, rman, rel_ways.current, rel_ways.attic, Relation_Entry::WAY, ids, invert_ids); 7830 collect_relations(query, rman, input->nodes, input->attic_nodes, Relation_Entry::NODE, ids, invert_ids) 7850 result.swap(into.relations, into.attic_relations); 78884 q else if (stmt->get_type() == RECURSE_UP_REL) 7900 if (type == QUERY_WAY) 7910 collect_ways(context, input->nodes, input->attic_nodes, 0, ids, invert_ids) 7920 .swap(into.ways, into.attic_ways); 7950 auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input->ways, input->attic_ways }; 7970 rel_ways.set_union(collect_ways(context, input->nodes, input->attic_nodes, 0, {}, true).sort()); 7990 auto rel_rels = Timeless< Uint31_Index, Relation_Skeleton >{ input->relations, input->attic_relations }; 8010 rel_rels.set_union(collect_relations( 8020 query, rman, rel_ways.current, rel_ways.attic, Relation_Entry::WAY, {}, true).sort()); 8030 rel_rels.set_union(collect_relations( 8040 query, rman, input->nodes, input->attic_nodes, Relation_Entry::NODE, {}, true).sort()); 8060 Timeless< Uint31_Index, Relation_Skeleton > result = relations_up_loop(query, rman, std::move(rel_rels)); 8110 result.filter_items(Id_Predicate< Relation_Skeleton >(ids)); 8130 result.filter_items( 8140 Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > >( 8150 Id_Predicate< Relation_Skeleton >(ids))); 8170 result.swap(into.relations, into.attic_relations); 827void Recurse_Constraint::filter(Resource_Manager& rman, Set& into) 8296655 q const Set* input = rman.get_set(stmt->get_input()); 8366253 q if (stmt->get_type() == RECURSE_DOWN || stmt->get_type() == RECURSE_DOWN_REL) 84197 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role()); 84297 q if (role_id == std::numeric_limits< uint32 >::max()) 84597 q if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 84697 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR) 84722 q Timeless< Uint32_Index, Node_Skeleton >{}.swap(into.nodes, into.attic_nodes) 84822 q .filter_items(Id_Predicate< Node_Skeleton >( 84922 q relation_node_member_ids(input->relations, input->attic_relations, &role_id))) 85022 q .swap(into.nodes, into.attic_nodes); 85275 q Timeless< Uint32_Index, Node_Skeleton >{}.swap(into.nodes, into.attic_nodes); 85497 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR 85597 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_WR) 85621 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways) 85721 q .filter_items(Id_Predicate< Way_Skeleton >( 85821 q relation_way_member_ids(input->relations, input->attic_relations, &role_id))) 85921 q .swap(into.ways, into.attic_ways); 86176 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways); 86397 q if (stmt->get_type() == RECURSE_RELATION_RELATION || stmt->get_type() == RECURSE_RELATION_NWR 86497 q || stmt->get_type() == RECURSE_RELATION_WR || stmt->get_type() == RECURSE_RELATION_NR) 8650 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 8660 .filter_items(Id_Predicate< Relation_Skeleton >( 8670 relation_relation_member_ids(input->relations, input->attic_relations, &role_id))) 8680 .swap(into.relations, into.attic_relations); 86997 q else if (stmt->get_type() == RECURSE_NODE_RELATION) 8700 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 8710 .filter_items(Get_Parent_Rels_Role_Predicate( 8720 extract_ids(input->nodes, input->attic_nodes), Relation_Entry::NODE, role_id)) 8730 .swap(into.relations, into.attic_relations); 87497 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 87554 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 87654 q .filter_items(Get_Parent_Rels_Role_Predicate( 87754 q extract_ids(input->ways, input->attic_ways), Relation_Entry::WAY, role_id)) 87854 q .swap(into.relations, into.attic_relations); 87943 q else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS) 8800 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 8810 .filter_items(Get_Parent_Rels_Role_Predicate( 8820 extract_ids(input->relations), Relation_Entry::RELATION, role_id)) 8830 .swap(into.relations, into.attic_relations); 88443 q else if (stmt->get_type() == RECURSE_UP || stmt->get_type() == RECURSE_UP_REL) 88743 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations); 8935346 q std::vector< Node::Id_Type > ids; 8945346 q if (stmt->get_type() == RECURSE_WAY_NODE) 89654 q ids = way_nd_ids(input->ways, input->attic_ways, stmt->get_pos()); 89754 q rman.health_check(*stmt); 8994843 q else if (stmt->get_type() == RECURSE_WAY_COUNT) 9010 ids = way_cnt_nd_ids(input->ways, input->attic_ways, stmt->get_lower(), stmt->get_upper()); 9020 rman.health_check(*stmt); 9044843 q else if (stmt->get_type() == RECURSE_WAY_LINK) 9060 ids = way_link_nd_ids(input->ways, input->attic_ways, stmt->get_lower(), stmt->get_upper()); 9070 rman.health_check(*stmt); 9094843 q else if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 9104843 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR) 91211 q ids = relation_node_member_ids(input->relations, input->attic_relations); 91311 q rman.health_check(*stmt); 9165346 q filter_items(Id_Predicate< Node_Skeleton >(ids), into.nodes); 9175346 q filter_items(Id_Predicate< Node_Skeleton >(ids), into.attic_nodes); 9205346 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR 9215346 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_WR) 92233 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways) 92333 q .filter_items(Id_Predicate< Way_Skeleton >( 92433 q relation_way_member_ids(input->relations, input->attic_relations))) 92533 q .swap(into.ways, into.attic_ways); 9265043 q else if (stmt->get_type() == RECURSE_NODE_WAY || stmt->get_type() == RECURSE_UP 9275043 q || stmt->get_type() == RECURSE_UP_REL) 9281312 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways) 9291312 q .filter_items(Get_Parent_Ways_Predicate(extract_ids(input->nodes, input->attic_nodes), stmt->get_pos())) 9301312 q .swap(into.ways, into.attic_ways); 9323732 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways); 9345346 q if (stmt->get_type() == RECURSE_RELATION_RELATION || stmt->get_type() == RECURSE_RELATION_NWR 9355346 q || stmt->get_type() == RECURSE_RELATION_WR || stmt->get_type() == RECURSE_RELATION_NR) 93686 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 93786 q .filter_items(Id_Predicate< Relation_Skeleton >( 93886 q relation_relation_member_ids(input->relations, input->attic_relations))) 93986 q .swap(into.relations, into.attic_relations); 9404542 q else if (stmt->get_type() == RECURSE_NODE_RELATION) 94177 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 94277 q .filter_items(Get_Parent_Rels_Predicate( 94377 q extract_ids(input->nodes, input->attic_nodes), Relation_Entry::NODE)) 94477 q .swap(into.relations, into.attic_relations); 9453835 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 94676 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 94776 q .filter_items(Get_Parent_Rels_Predicate( 94876 q extract_ids(input->ways, input->attic_ways), Relation_Entry::WAY)) 94976 q .swap(into.relations, into.attic_relations); 9503129 q else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS) 95155 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 95255 q .filter_items(Get_Parent_Rels_Predicate( 95355 q extract_ids(input->relations, input->attic_relations), Relation_Entry::RELATION)) 95455 q .swap(into.relations, into.attic_relations); 9552624 q else if (stmt->get_type() == RECURSE_UP || stmt->get_type() == RECURSE_UP_REL) 962void Recurse_Constraint::filter(const Statement& query, Resource_Manager& rman, Set& into) 9646655 q const Set* input = rman.get_set(stmt->get_input()); 9676253 q if (stmt->get_type() != RECURSE_DOWN && stmt->get_type() != RECURSE_DOWN_REL 9686253 q && stmt->get_type() != RECURSE_UP && stmt->get_type() != RECURSE_UP_REL) 9710 Request_Context context(&query, rman); 9720 if (stmt->get_type() == RECURSE_DOWN) 9740 std::vector< Node::Id_Type > rel_ids 9750 = relation_node_member_ids(input->relations, input->attic_relations); 9760 Timeless< Uint31_Index, Way_Skeleton > intermediate_ways = 9770 collect_ways(context, input->relations, input->attic_relations, 9780 Ranges< Uint31_Index >::global(), std::vector< Way::Id_Type >{}, true); 9800 std::vector< Node::Id_Type > way_ids = way_nd_ids(intermediate_ways.current, intermediate_ways.attic, 0); 9810 rman.health_check(*stmt); 9830 std::vector< Node::Id_Type > ids; 9840 set_union(way_ids.begin(), way_ids.end(), rel_ids.begin(), rel_ids.end(), back_inserter(ids)); 9850 Timeless< Uint32_Index, Node_Skeleton >{}.swap(into.nodes, into.attic_nodes) 9860 .filter_items(Id_Predicate< Node_Skeleton >(ids)).swap(into.nodes, into.attic_nodes); 9880 Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways) 9890 .filter_items(Id_Predicate< Way_Skeleton >( 9900 relation_way_member_ids(input->relations, input->attic_relations))) 9910 .swap(into.ways, into.attic_ways); 9930 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations); 9950 else if (stmt->get_type() == RECURSE_DOWN_REL) 9970 Timeless< Uint31_Index, Relation_Skeleton > rel_rels = 9980 relations_loop(query, rman, input->relations, input->attic_relations); 10000 std::vector< Node::Id_Type > rel_ids = relation_node_member_ids(rel_rels.current, rel_rels.attic); 10020 Timeless< Uint31_Index, Way_Skeleton > intermediate_ways = 10030 collect_ways(context, rel_rels.current, rel_rels.attic, 10040 Ranges< Uint31_Index >::global(), std::vector< Way::Id_Type >{}, true); 10050 std::vector< Node::Id_Type > way_ids = way_nd_ids(intermediate_ways.current, intermediate_ways.attic, 0); 10060 rman.health_check(*stmt); 10080 std::vector< Node::Id_Type > ids; 10090 set_union(way_ids.begin(), way_ids.end(), rel_ids.begin(), rel_ids.end(), back_inserter(ids)); 10100 Timeless< Uint32_Index, Node_Skeleton >{}.swap(into.nodes, into.attic_nodes) 10110 .filter_items(Id_Predicate< Node_Skeleton >(ids)).swap(into.nodes, into.attic_nodes); 10130 Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways) 10140 .filter_items(Id_Predicate< Way_Skeleton >( 10150 relation_way_member_ids(rel_rels.current, rel_rels.attic))) 10160 .swap(into.ways, into.attic_ways); 10180 if (rman.get_desired_timestamp() == NOW) 10190 filter_items(Id_Predicate< Relation_Skeleton >(filter_for_ids(rel_rels.current)), into.relations); 10220 item_filter_map(into.relations, rel_rels.current); 10230 item_filter_map(into.attic_relations, rel_rels.attic); 10260 else if (stmt->get_type() == RECURSE_UP && !into.relations.empty()) 10280 auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input->ways, input->attic_ways }; 10300 rel_ways.set_union(collect_ways(context, input->nodes, input->attic_nodes, 0, {}, true).sort()); 10320 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 10330 .filter_items(Or_Predicate< Relation_Skeleton, Get_Parent_Rels_Predicate, Get_Parent_Rels_Predicate > 10340 (Get_Parent_Rels_Predicate(extract_ids(input->nodes, input->attic_nodes), Relation_Entry::NODE), 10350 Get_Parent_Rels_Predicate(extract_ids(rel_ways.current, rel_ways.attic), Relation_Entry::WAY))) 10360 .swap(into.relations, into.attic_relations); 10380 else if (stmt->get_type() == RECURSE_UP_REL && !into.relations.empty()) 10400 auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input->ways, input->attic_ways }; 10420 rel_ways.set_union(collect_ways(context, input->nodes, input->attic_nodes, 0, {}, true).sort()); 10440 auto rel_rels = Timeless< Uint31_Index, Relation_Skeleton >{ input->relations, input->attic_relations }; 10460 rel_rels.set_union( 10470 collect_relations(query, rman, rel_ways.current, rel_ways.attic, Relation_Entry::WAY, {}, true).sort()); 10480 rel_rels.set_union( 10490 collect_relations(query, rman, input->nodes, input->attic_nodes, Relation_Entry::NODE, {}, true).sort()); 10510 rel_rels = relations_up_loop(query, rman, std::move(rel_rels)); 10530 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 10540 .filter_items(Id_Predicate< Relation_Skeleton >( 10550 extract_ids< Uint31_Index, Relation_Skeleton, Relation::Id_Type >(rel_rels.current, rel_rels.attic))) 10560 .swap(into.relations, into.attic_relations); 1060//----------------------------------------------------------------------------- 1062Recurse_Statement::Recurse_Statement 1063 (int line_number_, const std::map< std::string, std::string >& input_attributes, Parsed_Query& global_settings) 10641007205 q : Output_Statement(line_number_), restrict_to_role(false), lower(1), upper(0) 10661007205 q std::map< std::string, std::string > attributes; 10741007205 q attributes["role-restricted"] = "no"; 10771007205 q eval_attributes_array(get_name(), attributes, input_attributes); 10801007205 q set_output(attributes["into"]); 10821007205 q if (attributes["type"] == "relation-relation") 10835614 q type = RECURSE_RELATION_RELATION; 1084951200 q else if (attributes["type"] == "relation-backwards") 10854812 q type = RECURSE_RELATION_BACKWARDS; 1086903194 q else if (attributes["type"] == "relation-way") 1088833183 q else if (attributes["type"] == "relation-node") 10894010 q type = RECURSE_RELATION_NODE; 1090793176 q else if (attributes["type"] == "relation-nwr") 10910 type = RECURSE_RELATION_NWR; 1092793176 q else if (attributes["type"] == "relation-nw") 10930 type = RECURSE_RELATION_NW; 1094793176 q else if (attributes["type"] == "relation-wr") 10950 type = RECURSE_RELATION_WR; 1096793176 q else if (attributes["type"] == "relation-nr") 10970 type = RECURSE_RELATION_NR; 1098793176 q else if (attributes["type"] == "way-node") 1100701164 q else if (attributes["type"] == "way-link") 1102629153 q else if (attributes["type"] == "way-count") 1104509129 q else if (attributes["type"] == "down") 1106445115 q else if (attributes["type"] == "down-rel") 1108397104 q else if (attributes["type"] == "way-relation") 111033391 q else if (attributes["type"] == "node-relation") 11115213 q type = RECURSE_NODE_RELATION; 111228180 q else if (attributes["type"] == "node-way") 111419961 q else if (attributes["type"] == "node-wr") 111615951 q else if (attributes["type"] == "up") 11187826 q else if (attributes["type"] == "up-rel") 11230 std::ostringstream temp; 11240 temp<<"For the attribute \"type\" of the element \"recurse\"" 11250 <<" the only allowed values are \"relation-relation\", \"relation-backwards\"," 11260 <<"\"relation-way\", \"relation-node\", \"way-node\", \"way-relation\"," 11270 <<"\"node-relation\", \"node-way\", \"down\", \"down-rel\", \"up\", or \"up-rel\"."; 11280 add_static_error(temp.str()); 11311007205 q if (!attributes["role"].empty() || attributes["role-restricted"] == "yes") 11339222 q if (type != RECURSE_RELATION_RELATION && type != RECURSE_RELATION_BACKWARDS 11349222 q && type != RECURSE_RELATION_WAY && type != RECURSE_RELATION_NODE 11359222 q && type != RECURSE_RELATION_NWR && type != RECURSE_RELATION_NW && type != RECURSE_RELATION_WR 11369222 q && type != RECURSE_RELATION_NR 11379222 q && type != RECURSE_NODE_RELATION && type != RECURSE_WAY_RELATION) 11390 std::ostringstream temp; 11400 temp<<"A role can only be specified for values \"relation-relation\", \"relation-backwards\"," 11410 <<"\"relation-way\", \"relation-node\", \"way-relation\"," 11420 <<"or \"node-relation\"."; 11430 add_static_error(temp.str()); 11521007205 q if (!attributes["pos"].empty()) 1154246 q if (type != RECURSE_WAY_NODE && type != RECURSE_NODE_WAY) 11550 add_static_error("A role can only be specified for values \"way-node\" or \"node-way\","); 1158246 q std::string::size_type startpos = 0; 1159246 q std::string::size_type endpos = attributes["pos"].find(","); 1160326 q while (endpos != std::string::npos) 116282 q pos.push_back(atoll(&attributes["pos"][startpos])); 11640 add_static_error("Invalid pos '" 11650 + (endpos != std::string::npos ? 11660 attributes["pos"].substr(startpos,endpos-startpos) : attributes["pos"].substr(startpos)) 11670 + "' in positions list."); 116982 q endpos = attributes["pos"].find(",", startpos); 1171246 q pos.push_back(atoll(&attributes["pos"][startpos])); 11730 add_static_error("Invalid pos '" + attributes["pos"].substr(startpos) + "' in positions list."); 1176246 q std::sort(pos.begin(), pos.end()); 11791007205 q if (!attributes["lower"].empty() || !attributes["upper"].empty()) 118119246 q int64_t lower_i = atoll(attributes["lower"].c_str()); 118219246 q int64_t upper_i = atoll(attributes["upper"].c_str()); 11840 add_static_error("lower must be an integer greater or equal 1"); 118519246 q if (attributes["upper"].empty()) 118610826 q upper_i = std::numeric_limits< unsigned int >::max(); 11880 add_static_error("upper must be an integer greater or equal lower"); 1195std::string Recurse_Statement::to_target_type(int type) 1197434165 q if (type == RECURSE_RELATION_RELATION || type == RECURSE_RELATION_BACKWARDS 1198434165 q || type == RECURSE_WAY_RELATION || type == RECURSE_NODE_RELATION) 1200380150 q else if (type == RECURSE_RELATION_WAY || type == RECURSE_NODE_WAY) 1202336137 q else if (type == RECURSE_RELATION_NODE || type == RECURSE_WAY_NODE 1203336137 q || type == RECURSE_WAY_LINK || type == RECURSE_WAY_COUNT) 120519087 q else if (type == RECURSE_RELATION_NWR) 120719087 q else if (type == RECURSE_RELATION_NW) 120919087 q else if (type == RECURSE_RELATION_WR || type == RECURSE_NODE_WR) 121117882 q else if (type == RECURSE_RELATION_NR) 1218std::string Recurse_Statement::to_xml_representation(int type) 1220182151 q if (type == RECURSE_RELATION_RELATION) 1222168143 q else if (type == RECURSE_RELATION_BACKWARDS) 1224156135 q else if (type == RECURSE_RELATION_WAY) 1226140124 q else if (type == RECURSE_RELATION_NODE) 1228130115 q else if (type == RECURSE_RELATION_NWR) 12290 return "relation-nwr"; 1230130115 q else if (type == RECURSE_RELATION_NW) 12310 return "relation-nw"; 1232130115 q else if (type == RECURSE_RELATION_WR) 12330 return "relation-wr"; 1234130115 q else if (type == RECURSE_RELATION_NR) 12350 return "relation-nr"; 1236130115 q else if (type == RECURSE_WAY_NODE) 1238107100 q else if (type == RECURSE_WAY_LINK) 12408985 q else if (type == RECURSE_WAY_COUNT) 12425958 q else if (type == RECURSE_WAY_RELATION) 12444343 q else if (type == RECURSE_NODE_RELATION) 12463030 q else if (type == RECURSE_NODE_WR) 12482020 q else if (type == RECURSE_NODE_WAY) 125011 q else if (type == RECURSE_DOWN) 12520 else if (type == RECURSE_DOWN_REL) 12540 else if (type == RECURSE_UP) 12560 else if (type == RECURSE_UP_REL) 1263std::string Recurse_Statement::to_ql_representation(int type) 1265550205 q if (type == RECURSE_RELATION_RELATION) 1267522200 q else if (type == RECURSE_RELATION_BACKWARDS) 1269498194 q else if (type == RECURSE_RELATION_WAY || type == RECURSE_RELATION_NODE || type == RECURSE_RELATION_NWR 1270498194 q || type == RECURSE_RELATION_WR || type == RECURSE_RELATION_NW || type == RECURSE_RELATION_NR) 1272442176 q else if (type == RECURSE_WAY_NODE) 1274396164 q else if (type == RECURSE_WAY_LINK) 1276360153 q else if (type == RECURSE_WAY_COUNT) 1278300129 q else if (type == RECURSE_WAY_RELATION) 1280268117 q else if (type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WAY || type == RECURSE_NODE_WR) 128218083 q else if (type == RECURSE_DOWN) 128413866 q else if (type == RECURSE_DOWN_REL) 128610651 q else if (type == RECURSE_UP) 12885226 q else if (type == RECURSE_UP_REL) 1295void Recurse_Statement::execute(Resource_Manager& rman) 12992636163 q const Set* input_set = rman.get_set(input); 130265 q transfer_output(rman, into); 13062630162 q Request_Context context(this, rman); 13091414 q uint32 role_id = determine_role_id(*rman.get_transaction(), role); 13101414 q if (role_id == std::numeric_limits< uint32 >::max()) 13120 transfer_output(rman, into); 13161414 q if (type == RECURSE_RELATION_RELATION || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_WR 13171414 q || type == RECURSE_RELATION_NR) 131833 q relation_relation_members( 131933 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true, &role_id) 132033 q .swap(into.relations, into.attic_relations); 13211414 q if (type == RECURSE_RELATION_WAY || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW 13221414 q || type == RECURSE_RELATION_WR) 132444 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true, &role_id) 132544 q .swap(into.ways, into.attic_ways); 13261414 q if (type == RECURSE_RELATION_NODE || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW 13271414 q || type == RECURSE_RELATION_NR) 132933 q context, input_set->relations, input_set->attic_relations, 133033 q Ranges< Uint32_Index >::global(), {}, true, &role_id) 133133 q .swap(into.nodes, into.attic_nodes); 13321111 q else if (type == RECURSE_RELATION_BACKWARDS) 133322 q collect_relations(*this, rman, input_set->relations, input_set->attic_relations, {}, true, role_id) 133422 q .swap(into.relations, into.attic_relations); 133599 q else if (type == RECURSE_NODE_RELATION) 133711 q *this, rman, input_set->nodes, input_set->attic_nodes, Relation_Entry::NODE, {}, true, role_id) 133811 q .swap(into.relations, into.attic_relations); 133988 q else if (type == RECURSE_WAY_RELATION) 134111 q *this, rman, input_set->ways, input_set->attic_ways, Relation_Entry::WAY, {}, true, role_id) 134211 q .swap(into.relations, into.attic_relations); 13442616152 q else if (type == RECURSE_RELATION_RELATION) 134555 q relation_relation_members( 134655 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true) 134755 q .swap(into.relations, into.attic_relations); 13482611149 q else if (type == RECURSE_RELATION_BACKWARDS) 134965 q collect_relations(*this, rman, input_set->relations, input_set->attic_relations, {}, true) 135065 q .swap(into.relations, into.attic_relations); 13512605146 q else if (type == RECURSE_RELATION_WAY) 1353118 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true) 1354118 q .swap(into.ways, into.attic_ways); 13552594140 q else if (type == RECURSE_RELATION_NODE) 135743 q context, input_set->relations, input_set->attic_relations, 135843 q Ranges< Uint32_Index >::global(), {}, true) 135943 q .swap(into.nodes, into.attic_nodes); 13602590139 q else if (type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW || type == RECURSE_RELATION_WR 13612590139 q || type == RECURSE_RELATION_NR) 13630 if (type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NR || type == RECURSE_RELATION_WR) 13640 relation_relation_members( 13650 context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true) 13660 .swap(into.relations, into.attic_relations); 13680 if (type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW || type == RECURSE_RELATION_WR) 13690 relation_way_members( 13700 context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true) 13710 .swap(into.ways, into.attic_ways); 13730 if (type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW || type == RECURSE_RELATION_NR) 13740 relation_node_members( 13750 context, input_set->relations, input_set->attic_relations, 13760 Ranges< Uint32_Index >::global(), {}, true) 13770 .swap(into.nodes, into.attic_nodes); 13792590139 q else if (type == RECURSE_WAY_NODE) 13801513 q way_members(context, input_set->ways, input_set->attic_ways, get_pos(), 13811513 q Ranges< Uint32_Index >::global(), {}, true) 13821513 q .swap(into.nodes, into.attic_nodes); 13832575130 q else if (type == RECURSE_WAY_COUNT) 13843928 q way_cnt_members(context, input_set->ways, input_set->attic_ways, lower, upper, 13853928 q Ranges< Uint32_Index >::global(), {}, true) 13863928 q .swap(into.nodes, into.attic_nodes); 13872536108 q else if (type == RECURSE_WAY_LINK) 13882118 q way_link_members(context, input_set->ways, input_set->attic_ways, lower, upper, 13892118 q Ranges< Uint32_Index >::global(), {}, true) 13902118 q .swap(into.nodes, into.attic_nodes); 1391251596 q else if (type == RECURSE_DOWN) 1392237319 q add_nw_member_objects(context, *input_set, into); 139314284 q else if (type == RECURSE_DOWN_REL) 13951816 q relations_loop(*this, rman, input_set->relations, input_set->attic_relations) 13961816 q .swap(into.relations, into.attic_relations); 13981816 q context, into.relations, into.attic_relations, Ranges< Uint31_Index >::global(), {}, true) 13991816 q .swap(into.ways, into.attic_ways); 14001816 q auto source_ways = Timeless< Uint31_Index, Way_Skeleton >{ input_set->ways, input_set->attic_ways }; 14031816 q Timeless< Uint31_Index, Way_Skeleton > result_ways; 14041816 q source_ways.set_union(result_ways.swap(into.ways, into.attic_ways).sort()); 14051816 q result_ways.swap(into.ways, into.attic_ways); 14071816 q Timeless< Uint32_Index, Node_Skeleton > rel_nodes = relation_node_members( 14081816 q context, into.relations, into.attic_relations, Ranges< Uint32_Index >::global(), {}, true); 14111816 q Timeless< Uint32_Index, Node_Skeleton > more_nodes 14121816 q = way_members(context, source_ways.current, source_ways.attic, 0, 14131816 q Ranges< Uint32_Index >::global(), {}, true); 14141816 q rel_nodes.set_union(more_nodes.sort()); 14161816 q keep_matching_skeletons(rel_nodes.current, rel_nodes.attic, rman.get_desired_timestamp()); 14171816 q rel_nodes.swap(into.nodes, into.attic_nodes); 141912470 q else if (type == RECURSE_NODE_WAY || type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WR) 14212218 q if (type == RECURSE_NODE_WAY || type == RECURSE_NODE_WR) 14221613 q collect_ways(context, input_set->nodes, input_set->attic_nodes, get_pos(), {}, true) 14231613 q .swap(into.ways, into.attic_ways); 14242218 q if (type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WR) 14251311 q collect_relations(*this, rman, input_set->nodes, input_set->attic_nodes, Relation_Entry::NODE, {}, true) 14261311 q .swap(into.relations, into.attic_relations); 142810255 q else if (type == RECURSE_WAY_RELATION) 142975 q collect_relations(*this, rman, input_set->ways, input_set->attic_ways, Relation_Entry::WAY, {}, true) 143075 q .swap(into.relations, into.attic_relations); 14319550 q else if (type == RECURSE_UP || type == RECURSE_UP_REL) 14339550 q auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input_set->ways, input_set->attic_ways}; 14359550 q auto node_ways = collect_ways(context, input_set->nodes, input_set->attic_nodes, 0, {}, true); 14369550 q rel_ways.set_union(node_ways.sort()); 14379550 q node_ways.swap(into.ways, into.attic_ways); 14399550 q auto rel_rels = Timeless< Uint31_Index, Relation_Skeleton >{ input_set->relations, input_set->attic_relations }; 14429550 q collect_relations(*this, rman, rel_ways.current, rel_ways.attic, Relation_Entry::WAY, {}, true).sort()); 14449550 q collect_relations(*this, rman, input_set->nodes, input_set->attic_nodes, Relation_Entry::NODE, {}, true) 14486326 q rel_rels.swap(into.relations, into.attic_relations); 14503226 q relations_up_loop(*this, rman, std::move(rel_rels)).swap(into.relations, into.attic_relations); 14532630162 q if (rman.get_desired_timestamp() != NOW) 1455179273 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.nodes, into.attic_nodes); 1456179273 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.ways, into.attic_ways); 1457179273 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.relations, into.attic_relations); 1465Recurse_Statement::~Recurse_Statement() 14671007205 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin(); 1473Query_Constraint* Recurse_Statement::get_query_constraint() 147517455 q constraints.push_back(new Recurse_Constraint(*this));