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) 65768159 q Token_Node_Ptr tree_it = input_tree; 66768159 q uint line_nr = tree_it->line_col.first; 69768159 q std::vector< std::string > roles; 70768159 q std::string lower, upper; 71768159 q bool role_found = false; 73776159 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(); 79768159 q if (tree_it->token == ":" && tree_it->rhs) 8227666 q if (tree_it.rhs()->token == "-") 8410024 q if (tree_it.rhs()->lhs) 8510024 q lower = tree_it.rhs().lhs()->token; 8610024 q if (tree_it.rhs()->rhs) 87205 q upper = tree_it.rhs().rhs()->token; 8917643 q else if (!tree_it.rhs()->lhs && !tree_it.rhs()->rhs) 9017643 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); 9327666 q tree_it = tree_it.lhs(); 96768159 q if (tree_it->token == "." && tree_it->rhs) 98684151 q from = tree_it.rhs()->token; 99684151 q tree_it = tree_it.lhs(); 102768159 q std::string type = tree_it->token; 103768159 q std::map< std::string, std::string > attributes; 10917240 q if (result_type == "node") 110369 q attributes["type"] = "relation-node"; 11113633 q else if (result_type == "way") 1126015 q attributes["type"] = "relation-way"; 1137619 q else if (result_type == "relation") 1147619 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); 12814033 q if (result_type == "node") 12914033 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); 133456106 q else if (type == "way_link") 1356015 q if (result_type == "node") 1366015 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); 14039693 q else if (type == "way_cnt") 1428020 q if (result_type == "node") 1438020 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); 1494010 q if (result_type == "relation") 1504010 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); 15610025 q if (result_type == "relation") 15710025 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); 16317642 q if (result_type == "way") 1649223 q attributes["type"] = "node-way"; 1658421 q else if (result_type == "relation") 1664411 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); 17727666 q if (type == "r" || result_type == "relation") 17910425 q attributes["role"] = roles.back(); 18010425 q attributes["role-restricted"] = "yes"; 18217241 q else if (type == "w" || result_type == "way") 184328 q attributes["pos"] = roles[0]; 185408 q for (uint i = 1; i < roles.size(); ++i) 18682 q attributes["pos"] += "," + roles[i]; 18814034 q else if (type == "way_cnt" || type == "way_link") 19410024 q attributes["lower"] = lower; 19510024 q attributes["upper"] = upper; 1994010 q attributes["lower"] = roles.back(); 2004010 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); 209768159 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; 2340 attributes["type"] = "down"; 23541 q else if (type == ">>") 2360 attributes["type"] = "down-rel"; 23841 q 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) 25923469 q Timeless< Uint31_Index, Relation_Skeleton > result; 26123469 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources); 26223469 q std::set< Uint31_Index > req = extract_parent_indices(sources); 26323469 q rman.health_check(stmt); 26523469 q if (rman.get_desired_timestamp() != NOW) 2675431 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources); 2685431 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_sources); 2715431 q std::vector< Uint64 > children_ids; 2725431 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 2735431 q std::back_inserter(children_ids)); 274226731 q for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it) 2765431 q current_ids.swap(children_ids); 27923469 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); 28722863 q collect_items_discrete(context, req, 28822863 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) 3101211 q Timeless< Uint31_Index, Relation_Skeleton > result; 3121211 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources); 3141211 q std::set< Uint31_Index > req = extract_parent_indices(sources); 3171211 q if (rman.get_desired_timestamp() != NOW) 31944 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources); 32044 q rman.health_check(stmt); 32144 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_sources); 32244 q rman.health_check(stmt); 32444 q std::vector< Uint64 > children_ids; 32544 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 32644 q std::back_inserter(children_ids)); 32711874 q for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it) 32944 q current_ids.swap(children_ids); 3321211 q Request_Context context(&stmt, rman); 33422 q collect_items_discrete(context, req, 33522 q And_Predicate< Relation_Skeleton, 33622 q Id_Predicate< Relation_Skeleton >, Get_Parent_Rels_Role_Predicate > 33722 q (Id_Predicate< Relation_Skeleton >(ids), 33822 q Get_Parent_Rels_Role_Predicate(current_ids, source_type, role_id)), result.current, result.attic); 339109 q else if (ids.empty()) 340109 q collect_items_discrete(context, req, 341109 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) 3612917 q Timeless< Uint31_Index, Relation_Skeleton > result; 3632917 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources); 3662917 q if (rman.get_desired_timestamp() != NOW) 36822 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources); 36922 q rman.health_check(stmt); 37122 q std::vector< Uint64 > children_ids; 37222 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 37322 q std::back_inserter(children_ids)); 37422 q current_ids.swap(children_ids); 3772917 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); 3862715 q collect_items_flat(context, 3872715 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) 40811 q Timeless< Uint31_Index, Relation_Skeleton > result; 41011 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources); 41111 q rman.health_check(stmt); 41311 q Request_Context context(&stmt, rman); 41411 q if (rman.get_desired_timestamp() != NOW) 4160 std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources); 4170 rman.health_check(stmt); 4190 std::vector< Uint64 > children_ids; 4200 std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(), 4210 std::back_inserter(children_ids)); 4220 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); 43311 q collect_items_flat(context, 43411 q Get_Parent_Rels_Role_Predicate(current_ids, Relation_Entry::RELATION, role_id), 43511 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) 4551817 q Request_Context context(&query, rman); 4561817 q auto working_set = Timeless< Uint31_Index, Relation_Skeleton >{ source, attic_source }; 4591817 q uint new_rel_count = count(working_set.current) + count(working_set.attic); 4603417 q while (old_rel_count < new_rel_count) 462169 q old_rel_count = new_rel_count; 463169 q auto new_results = relation_relation_members( 464169 q context, working_set.current, working_set.attic, Ranges< Uint31_Index >::global(), {}, true); 465169 q working_set.set_union(new_results.sort()); 466169 q keep_matching_skeletons(working_set.current, working_set.attic, context.get_desired_timestamp()); 467169 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) 4791918 q uint new_rel_count = count(working_set.current) + count(working_set.attic); 4803918 q while (old_rel_count < new_rel_count) 482208 q old_rel_count = new_rel_count; 483208 q auto new_results = collect_relations(query, rman, working_set.current, working_set.attic, {}, true); 484208 q working_set.set_union(new_results.sort()); 485208 q keep_matching_skeletons(working_set.current, working_set.attic, rman.get_desired_timestamp()); 486208 q new_rel_count = count(working_set.current) + count(working_set.attic); 4881918 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) 4973029 q Ranges< Uint31_Index > result; 4993029 q std::set< Uint31_Index > req = extract_parent_indices(cur_elems); 5012162129 q result.push_back(i, inc(i)); 5033029 q if (!attic_elems.empty()) 50577 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_elems); 50677 q for (auto i : attic_req) 5078627 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 54216551 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; 5486051 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) 57086 q const Set* input = rman.get_set(stmt->get_input()); 57211 q return Ranges< Uint32_Index >(); 57475 q if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 57575 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); 57753 q else if (stmt->get_type() == RECURSE_WAY_NODE || stmt->get_type() == RECURSE_WAY_LINK 57853 q || stmt->get_type() == RECURSE_WAY_COUNT) 57953 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) 5872624 q const Set* input = rman.get_set(stmt->get_input()); 58932 q return Ranges< Uint31_Index >(); 5912322 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR 5922322 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_WR) 59355 q return relation_way_member_indices(input->relations, input->attic_relations); 5941817 q else if (stmt->get_type() == RECURSE_NODE_WAY) 5951413 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) 6032727 q const Set* input = rman.get_set(stmt->get_input()); 6050 return Ranges< Uint31_Index >(); 6072727 q if (stmt->get_type() == RECURSE_NODE_RELATION) 60855 q return extract_parent_indices(input->nodes, input->attic_nodes); 6092222 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 6101111 q return extract_parent_indices(input->ways, input->attic_ways); 6121111 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, 62286 q const Set* input = rman.get_set(stmt->get_input()); 62675 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); 63764 q else if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 63864 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); 64253 q else if (stmt->get_type() == RECURSE_WAY_NODE) 64453 q context, input->ways, input->attic_ways, stmt->get_pos(), ranges, ids, invert_ids) 64553 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, 6765345 q const Set* input = rman.get_set(stmt->get_input()); 6805043 q Request_Context context(&query, rman); 68366 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role()); 68466 q if (role_id == std::numeric_limits< uint32 >::max()) 68766 q if (stmt->get_type() == RECURSE_RELATION_WAY 68866 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_WAY) 68966 q || (stmt->get_type() == RECURSE_RELATION_NW && type == QUERY_WAY) 69066 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_WAY)) 69122 q collect_ways(context, input->relations, input->attic_relations, ranges, ids, invert_ids, &role_id) 69222 q .swap(into.ways, into.attic_ways); 69344 q else if (stmt->get_type() == RECURSE_RELATION_RELATION 69444 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_RELATION) 69544 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_RELATION) 69644 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); 70044 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); 70444 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 70544 q collect_relations(query, rman, input->ways, input->attic_ways, Relation_Entry::WAY, ids, invert_ids, role_id) 70644 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); 7134438 q else if (stmt->get_type() == RECURSE_RELATION_WAY 7144438 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_WAY) 7154438 q || (stmt->get_type() == RECURSE_RELATION_NW && type == QUERY_WAY) 7164438 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); 7194136 q else if (stmt->get_type() == RECURSE_RELATION_RELATION 7204136 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_RELATION) 7214136 q || (stmt->get_type() == RECURSE_RELATION_NR && type == QUERY_RELATION) 7224136 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); 7263632 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); 7333632 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); 7563632 q else if (stmt->get_type() == RECURSE_NODE_WAY) 7571413 q collect_ways(context, input->nodes, input->attic_nodes, stmt->get_pos(), ids, invert_ids) 7581413 q .swap(into.ways, into.attic_ways); 7592219 q else if (stmt->get_type() == RECURSE_NODE_RELATION) 76055 q collect_relations(query, rman, input->nodes, input->attic_nodes, Relation_Entry::NODE, ids, invert_ids) 76155 q .swap(into.relations, into.attic_relations); 7621714 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 76377 q collect_relations(query, rman, input->ways, input->attic_ways, Relation_Entry::WAY, ids, invert_ids) 76477 q .swap(into.relations, into.attic_relations); 765107 q else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS) 76633 q collect_relations(query, rman, input->relations, input->attic_relations, ids, invert_ids) 76733 q .swap(into.relations, into.attic_relations); 76874 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); 78874 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) 8296251 q const Set* input = rman.get_set(stmt->get_input()); 8365848 q if (stmt->get_type() == RECURSE_DOWN || stmt->get_type() == RECURSE_DOWN_REL) 84177 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role()); 84277 q if (role_id == std::numeric_limits< uint32 >::max()) 84577 q if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 84677 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR) 84711 q Timeless< Uint32_Index, Node_Skeleton >{}.swap(into.nodes, into.attic_nodes) 84811 q .filter_items(Id_Predicate< Node_Skeleton >( 84911 q relation_node_member_ids(input->relations, input->attic_relations, &role_id))) 85011 q .swap(into.nodes, into.attic_nodes); 85266 q Timeless< Uint32_Index, Node_Skeleton >{}.swap(into.nodes, into.attic_nodes); 85477 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR 85577 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_WR) 85622 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways) 85722 q .filter_items(Id_Predicate< Way_Skeleton >( 85822 q relation_way_member_ids(input->relations, input->attic_relations, &role_id))) 85922 q .swap(into.ways, into.attic_ways); 86155 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways); 86377 q if (stmt->get_type() == RECURSE_RELATION_RELATION || stmt->get_type() == RECURSE_RELATION_NWR 86477 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); 86977 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); 87477 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 87544 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 87644 q .filter_items(Get_Parent_Rels_Role_Predicate( 87744 q extract_ids(input->ways, input->attic_ways), Relation_Entry::WAY, role_id)) 87844 q .swap(into.relations, into.attic_relations); 87933 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); 88433 q else if (stmt->get_type() == RECURSE_UP || stmt->get_type() == RECURSE_UP_REL) 88733 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations); 8935142 q std::vector< Node::Id_Type > ids; 8945142 q if (stmt->get_type() == RECURSE_WAY_NODE) 89653 q ids = way_nd_ids(input->ways, input->attic_ways, stmt->get_pos()); 89753 q rman.health_check(*stmt); 8994640 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); 9044640 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); 9094640 q else if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR 9104640 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); 9165142 q filter_items(Id_Predicate< Node_Skeleton >(ids), into.nodes); 9175142 q filter_items(Id_Predicate< Node_Skeleton >(ids), into.attic_nodes); 9205142 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR 9215142 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); 9264840 q else if (stmt->get_type() == RECURSE_NODE_WAY || stmt->get_type() == RECURSE_UP 9274840 q || stmt->get_type() == RECURSE_UP_REL) 9281413 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways) 9291413 q .filter_items(Get_Parent_Ways_Predicate(extract_ids(input->nodes, input->attic_nodes), stmt->get_pos())) 9301413 q .swap(into.ways, into.attic_ways); 9323428 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways); 9345142 q if (stmt->get_type() == RECURSE_RELATION_RELATION || stmt->get_type() == RECURSE_RELATION_NWR 9355142 q || stmt->get_type() == RECURSE_RELATION_WR || stmt->get_type() == RECURSE_RELATION_NR) 93676 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 93776 q .filter_items(Id_Predicate< Relation_Skeleton >( 93876 q relation_relation_member_ids(input->relations, input->attic_relations))) 93976 q .swap(into.relations, into.attic_relations); 9404438 q else if (stmt->get_type() == RECURSE_NODE_RELATION) 94155 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 94255 q .filter_items(Get_Parent_Rels_Predicate( 94355 q extract_ids(input->nodes, input->attic_nodes), Relation_Entry::NODE)) 94455 q .swap(into.relations, into.attic_relations); 9453933 q else if (stmt->get_type() == RECURSE_WAY_RELATION) 94677 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 94777 q .filter_items(Get_Parent_Rels_Predicate( 94877 q extract_ids(input->ways, input->attic_ways), Relation_Entry::WAY)) 94977 q .swap(into.relations, into.attic_relations); 9503226 q else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS) 95133 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations) 95233 q .filter_items(Get_Parent_Rels_Predicate( 95333 q extract_ids(input->relations, input->attic_relations), Relation_Entry::RELATION)) 95433 q .swap(into.relations, into.attic_relations); 9552924 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) 9646251 q const Set* input = rman.get_set(stmt->get_input()); 9675848 q if (stmt->get_type() != RECURSE_DOWN && stmt->get_type() != RECURSE_DOWN_REL 9685848 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) 10641066222 q : Output_Statement(line_number_), restrict_to_role(false), lower(1), upper(0) 10661066222 q std::map< std::string, std::string > attributes; 10741066222 q attributes["role-restricted"] = "no"; 10771066222 q eval_attributes_array(get_name(), attributes, input_attributes); 10801066222 q set_output(attributes["into"]); 10821066222 q if (attributes["type"] == "relation-relation") 10837619 q type = RECURSE_RELATION_RELATION; 1084990212 q else if (attributes["type"] == "relation-backwards") 10854010 q type = RECURSE_RELATION_BACKWARDS; 1086950208 q else if (attributes["type"] == "relation-way") 1088884201 q else if (attributes["type"] == "relation-node") 1089369 q type = RECURSE_RELATION_NODE; 1090848196 q else if (attributes["type"] == "relation-nwr") 10910 type = RECURSE_RELATION_NWR; 1092848196 q else if (attributes["type"] == "relation-nw") 10930 type = RECURSE_RELATION_NW; 1094848196 q else if (attributes["type"] == "relation-wr") 10950 type = RECURSE_RELATION_WR; 1096848196 q else if (attributes["type"] == "relation-nr") 10970 type = RECURSE_RELATION_NR; 1098848196 q else if (attributes["type"] == "way-node") 1100708174 q else if (attributes["type"] == "way-link") 1102648161 q else if (attributes["type"] == "way-count") 1104568143 q else if (attributes["type"] == "down") 1106466118 q else if (attributes["type"] == "down-rel") 1108415104 q else if (attributes["type"] == "way-relation") 110910025 q type = RECURSE_WAY_RELATION; 111031583 q else if (attributes["type"] == "node-relation") 11115012 q type = RECURSE_NODE_RELATION; 111226572 q else if (attributes["type"] == "node-way") 111417352 q else if (attributes["type"] == "node-wr") 111613342 q else if (attributes["type"] == "up") 11185418 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()); 11311066222 q if (!attributes["role"].empty() || attributes["role-restricted"] == "yes") 113310425 q if (type != RECURSE_RELATION_RELATION && type != RECURSE_RELATION_BACKWARDS 113410425 q && type != RECURSE_RELATION_WAY && type != RECURSE_RELATION_NODE 113510425 q && type != RECURSE_RELATION_NWR && type != RECURSE_RELATION_NW && type != RECURSE_RELATION_WR 113610425 q && type != RECURSE_RELATION_NR 113710425 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()); 11521066222 q if (!attributes["pos"].empty()) 1154328 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\","); 1158328 q std::string::size_type startpos = 0; 1159328 q std::string::size_type endpos = attributes["pos"].find(","); 1160408 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); 1171328 q pos.push_back(atoll(&attributes["pos"][startpos])); 11730 add_static_error("Invalid pos '" + attributes["pos"].substr(startpos) + "' in positions list."); 1176328 q std::sort(pos.begin(), pos.end()); 11791066222 q if (!attributes["lower"].empty() || !attributes["upper"].empty()) 118114034 q int64_t lower_i = atoll(attributes["lower"].c_str()); 118214034 q int64_t upper_i = atoll(attributes["upper"].c_str()); 11840 add_static_error("lower must be an integer greater or equal 1"); 118514034 q if (attributes["upper"].empty()) 11868019 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) 1197472191 q if (type == RECURSE_RELATION_RELATION || type == RECURSE_RELATION_BACKWARDS 1198472191 q || type == RECURSE_WAY_RELATION || type == RECURSE_NODE_RELATION) 1200388162 q else if (type == RECURSE_RELATION_WAY || type == RECURSE_NODE_WAY) 1202348151 q else if (type == RECURSE_RELATION_NODE || type == RECURSE_WAY_NODE 1203348151 q || type == RECURSE_WAY_LINK || type == RECURSE_WAY_COUNT) 120520092 q else if (type == RECURSE_RELATION_NWR) 120720092 q else if (type == RECURSE_RELATION_NW) 120920092 q else if (type == RECURSE_RELATION_WR || type == RECURSE_NODE_WR) 121118887 q else if (type == RECURSE_RELATION_NR) 1218std::string Recurse_Statement::to_xml_representation(int type) 1220193160 q if (type == RECURSE_RELATION_RELATION) 1222174146 q else if (type == RECURSE_RELATION_BACKWARDS) 1224164141 q else if (type == RECURSE_RELATION_WAY) 1226149133 q else if (type == RECURSE_RELATION_NODE) 1228140125 q else if (type == RECURSE_RELATION_NWR) 12290 return "relation-nwr"; 1230140125 q else if (type == RECURSE_RELATION_NW) 12310 return "relation-nw"; 1232140125 q else if (type == RECURSE_RELATION_WR) 12330 return "relation-wr"; 1234140125 q else if (type == RECURSE_RELATION_NR) 12350 return "relation-nr"; 1236140125 q else if (type == RECURSE_WAY_NODE) 123810599 q else if (type == RECURSE_WAY_LINK) 12409086 q else if (type == RECURSE_WAY_COUNT) 12427066 q else if (type == RECURSE_WAY_RELATION) 12444543 q else if (type == RECURSE_NODE_RELATION) 12463432 q else if (type == RECURSE_NODE_WR) 12482424 q else if (type == RECURSE_NODE_WAY) 125011 q else if (type == RECURSE_DOWN) 125211 q else if (type == RECURSE_DOWN_REL) 125411 q else if (type == RECURSE_UP) 12560 else if (type == RECURSE_UP_REL) 1263std::string Recurse_Statement::to_ql_representation(int type) 1265582222 q if (type == RECURSE_RELATION_RELATION) 1267544212 q else if (type == RECURSE_RELATION_BACKWARDS) 1269524208 q else if (type == RECURSE_RELATION_WAY || type == RECURSE_RELATION_NODE || type == RECURSE_RELATION_NWR 1270524208 q || type == RECURSE_RELATION_WR || type == RECURSE_RELATION_NW || type == RECURSE_RELATION_NR) 1272472196 q else if (type == RECURSE_WAY_NODE) 1274402174 q else if (type == RECURSE_WAY_LINK) 1276372161 q else if (type == RECURSE_WAY_COUNT) 1278332143 q else if (type == RECURSE_WAY_RELATION) 1280282126 q else if (type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WAY || type == RECURSE_NODE_WR) 128219088 q else if (type == RECURSE_DOWN) 128412258 q else if (type == RECURSE_DOWN_REL) 12883618 q else if (type == RECURSE_UP_REL) 1295void Recurse_Statement::execute(Resource_Manager& rman) 129925825190 q const Set* input_set = rman.get_set(input); 130625812187 q Request_Context context(this, rman); 13092017 q uint32 role_id = determine_role_id(*rman.get_transaction(), role); 13102017 q if (role_id == std::numeric_limits< uint32 >::max()) 13120 transfer_output(rman, into); 13162017 q if (type == RECURSE_RELATION_RELATION || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_WR 13172017 q || type == RECURSE_RELATION_NR) 131822 q relation_relation_members( 131922 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true, &role_id) 132022 q .swap(into.relations, into.attic_relations); 13212017 q if (type == RECURSE_RELATION_WAY || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW 13222017 q || type == RECURSE_RELATION_WR) 132465 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true, &role_id) 132565 q .swap(into.ways, into.attic_ways); 13262017 q if (type == RECURSE_RELATION_NODE || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW 13272017 q || type == RECURSE_RELATION_NR) 132932 q context, input_set->relations, input_set->attic_relations, 133032 q Ranges< Uint32_Index >::global(), {}, true, &role_id) 133132 q .swap(into.nodes, into.attic_nodes); 13321715 q else if (type == RECURSE_RELATION_BACKWARDS) 133311 q collect_relations(*this, rman, input_set->relations, input_set->attic_relations, {}, true, role_id) 133411 q .swap(into.relations, into.attic_relations); 13351614 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); 13391513 q else if (type == RECURSE_WAY_RELATION) 134176 q *this, rman, input_set->ways, input_set->attic_ways, Relation_Entry::WAY, {}, true, role_id) 134276 q .swap(into.relations, into.attic_relations); 134425792177 q else if (type == RECURSE_RELATION_RELATION) 13461411 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true) 13471411 q .swap(into.relations, into.attic_relations); 134825778169 q else if (type == RECURSE_RELATION_BACKWARDS) 134966 q collect_relations(*this, rman, input_set->relations, input_set->attic_relations, {}, true) 135066 q .swap(into.relations, into.attic_relations); 135125772164 q else if (type == RECURSE_RELATION_WAY) 135365 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true) 135465 q .swap(into.ways, into.attic_ways); 135525766162 q else if (type == RECURSE_RELATION_NODE) 135744 q context, input_set->relations, input_set->attic_relations, 135844 q Ranges< Uint32_Index >::global(), {}, true) 135944 q .swap(into.nodes, into.attic_nodes); 136025762158 q else if (type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW || type == RECURSE_RELATION_WR 136125762158 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); 137925762158 q else if (type == RECURSE_WAY_NODE) 13802722 q way_members(context, input_set->ways, input_set->attic_ways, get_pos(), 13812722 q Ranges< Uint32_Index >::global(), {}, true) 13822722 q .swap(into.nodes, into.attic_nodes); 138325735139 q else if (type == RECURSE_WAY_COUNT) 13842520 q way_cnt_members(context, input_set->ways, input_set->attic_ways, lower, upper, 13852520 q Ranges< Uint32_Index >::global(), {}, true) 13862520 q .swap(into.nodes, into.attic_nodes); 138725710122 q else if (type == RECURSE_WAY_LINK) 13882015 q way_link_members(context, input_set->ways, input_set->attic_ways, lower, upper, 13892015 q Ranges< Uint32_Index >::global(), {}, true) 13902015 q .swap(into.nodes, into.attic_nodes); 139125690107 q else if (type == RECURSE_DOWN) 13922553931 q add_nw_member_objects(context, *input_set, into); 139315181 q else if (type == RECURSE_DOWN_REL) 13951817 q relations_loop(*this, rman, input_set->relations, input_set->attic_relations) 13961817 q .swap(into.relations, into.attic_relations); 13981817 q context, into.relations, into.attic_relations, Ranges< Uint31_Index >::global(), {}, true) 13991817 q .swap(into.ways, into.attic_ways); 14001817 q auto source_ways = Timeless< Uint31_Index, Way_Skeleton >{ input_set->ways, input_set->attic_ways }; 14031817 q Timeless< Uint31_Index, Way_Skeleton > result_ways; 14041817 q source_ways.set_union(result_ways.swap(into.ways, into.attic_ways).sort()); 14051817 q result_ways.swap(into.ways, into.attic_ways); 14071817 q Timeless< Uint32_Index, Node_Skeleton > rel_nodes = relation_node_members( 14081817 q context, into.relations, into.attic_relations, Ranges< Uint32_Index >::global(), {}, true); 14111817 q Timeless< Uint32_Index, Node_Skeleton > more_nodes 14121817 q = way_members(context, source_ways.current, source_ways.attic, 0, 14131817 q Ranges< Uint32_Index >::global(), {}, true); 14141817 q rel_nodes.set_union(more_nodes.sort()); 14161817 q keep_matching_skeletons(rel_nodes.current, rel_nodes.attic, rman.get_desired_timestamp()); 14171817 q rel_nodes.swap(into.nodes, into.attic_nodes); 141913366 q else if (type == RECURSE_NODE_WAY || type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WR) 14212419 q if (type == RECURSE_NODE_WAY || type == RECURSE_NODE_WR) 14221713 q collect_ways(context, input_set->nodes, input_set->attic_nodes, get_pos(), {}, true) 14231713 q .swap(into.ways, into.attic_ways); 14242419 q if (type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WR) 14251412 q collect_relations(*this, rman, input_set->nodes, input_set->attic_nodes, Relation_Entry::NODE, {}, true) 14261412 q .swap(into.relations, into.attic_relations); 142810948 q else if (type == RECURSE_WAY_RELATION) 1429108 q collect_relations(*this, rman, input_set->ways, input_set->attic_ways, Relation_Entry::WAY, {}, true) 1430108 q .swap(into.relations, into.attic_relations); 14319940 q else if (type == RECURSE_UP || type == RECURSE_UP_REL) 14339940 q auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input_set->ways, input_set->attic_ways}; 14359940 q auto node_ways = collect_ways(context, input_set->nodes, input_set->attic_nodes, 0, {}, true); 14369940 q rel_ways.set_union(node_ways.sort()); 14379940 q node_ways.swap(into.ways, into.attic_ways); 14399940 q auto rel_rels = Timeless< Uint31_Index, Relation_Skeleton >{ input_set->relations, input_set->attic_relations }; 14429940 q collect_relations(*this, rman, rel_ways.current, rel_ways.attic, Relation_Entry::WAY, {}, true).sort()); 14449940 q collect_relations(*this, rman, input_set->nodes, input_set->attic_nodes, Relation_Entry::NODE, {}, true) 14488024 q rel_rels.swap(into.relations, into.attic_relations); 14501918 q relations_up_loop(*this, rman, std::move(rel_rels)).swap(into.relations, into.attic_relations); 145325812187 q if (rman.get_desired_timestamp() != NOW) 14552560387 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.nodes, into.attic_nodes); 14562560387 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.ways, into.attic_ways); 14572560387 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.relations, into.attic_relations); 1465Recurse_Statement::~Recurse_Statement() 14671066222 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin(); 1473Query_Constraint* Recurse_Statement::get_query_constraint() 147516551 q constraints.push_back(new Recurse_Constraint(*this));