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

overpass_api/statements/recurse.cc

805 of 1171 instrumented lines run by the suite (68.7%) at 8edf11b0419c (this file on GitHub).

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

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#include <algorithm>
20#include <map>
21#include <set>
22#include <sstream>
23#include <string>
24#include <vector>
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"
32#include "recurse.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;
68768159 q std::string from = "_";
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)
8027666 q {
8127666 q role_found = true;
8227666 q if (tree_it.rhs()->token == "-")
8310024 q {
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;
8810024 q }
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));
910 else
920 error_output->add_parse_error("Simple role token expected, structured syntax tree found.", line_nr);
9327666 q tree_it = tree_it.lhs();
9427666 q }
96768159 q if (tree_it->token == "." && tree_it->rhs)
97684151 q {
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;
104768159 q attributes["from"] = from;
105768159 q attributes["into"] = into;
107768159 q if (type == "r")
10817240 q {
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);
12517240 q }
126596131 q else if (type == "w")
12714033 q {
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);
13214033 q }
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);
14731674 q else if (type == "br")
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);
15427665 q else if (type == "bw")
15510025 q {
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);
16010025 q }
16117642 q else if (type == "bn")
16217642 q {
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);
17117642 q }
1720 else
1730 return 0;
175768159 q if (role_found)
17627666 q {
17727666 q if (type == "r" || result_type == "relation")
17810425 q {
17910425 q attributes["role"] = roles.back();
18010425 q attributes["role-restricted"] = "yes";
18110425 q }
18217241 q else if (type == "w" || result_type == "way")
183328 q {
184328 q attributes["pos"] = roles[0];
185408 q for (uint i = 1; i < roles.size(); ++i)
18682 q attributes["pos"] += "," + roles[i];
187328 q }
18814034 q else if (type == "way_cnt" || type == "way_link")
18914034 q {
19014034 q if (role_found)
19114034 q {
19214034 q if (roles.empty())
19310024 q {
19410024 q attributes["lower"] = lower;
19510024 q attributes["upper"] = upper;
19610024 q }
1974010 q else
1994010 q attributes["lower"] = roles.back();
2004010 q attributes["upper"] = roles.back();
20214034 q }
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);
20514034 q }
2060 else if (error_output)
2070 error_output->add_parse_error("A recursion of type '" + type + "' cannot have restrictions.", line_nr);
20827666 q }
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)
2230 {
2240 from = tree_it.rhs()->token;
2250 tree_it = tree_it.lhs();
2260 }
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;
23341 q if (type == ">")
2340 attributes["type"] = "down";
23541 q else if (type == ">>")
2360 attributes["type"] = "down-rel";
23741 q else if (type == "<")
23841 q attributes["type"] = "up";
2390 else if (type == "<<")
2400 attributes["type"] = "up-rel";
2410 else
2420 return 0;
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,
256 uint32 source_type,
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);
2695431 q rman.health_check(stmt);
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)
275221331 q req.insert(*it);
2765431 q current_ids.swap(children_ids);
27923469 q Request_Context context(&stmt, rman);
28023469 q if (!invert_ids)
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);
28622863 q else if (ids.empty())
28722863 q collect_items_discrete(context, req,
28822863 q Get_Parent_Rels_Predicate(current_ids, source_type), result.current, result.attic);
2890 else
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);
29823469 q return result;
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,
307 uint32 source_type,
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);
3131211 q rman.health_check(stmt);
3141211 q std::set< Uint31_Index > req = extract_parent_indices(sources);
3151211 q rman.health_check(stmt);
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)
32811834 q req.insert(*it);
32944 q current_ids.swap(children_ids);
3321211 q Request_Context context(&stmt, rman);
3331211 q if (!invert_ids)
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);
3420 else
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);
3511211 q return result;
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);
3642917 q rman.health_check(stmt);
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);
3782917 q if (!invert_ids)
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);
3852715 q else if (ids.empty())
3862715 q collect_items_flat(context,
3872715 q Get_Parent_Rels_Predicate(current_ids, Relation_Entry::RELATION), result.current, result.attic);
3880 else
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);
3982917 q return result;
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)
4150 {
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);
4230 }
42511 q if (!invert_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);
43211 q else if (ids.empty())
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);
4360 else
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);
44611 q return result;
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 };
4571817 q working_set.sort();
4581817 q uint old_rel_count = 0;
4591817 q uint new_rel_count = count(working_set.current) + count(working_set.attic);
4603417 q while (old_rel_count < new_rel_count)
461169 q {
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);
468169 q }
4691817 q return working_set;
473Timeless< Uint31_Index, Relation_Skeleton > relations_up_loop(
474 const Statement& query, Resource_Manager& rman,
475 Timeless< Uint31_Index, Relation_Skeleton >&& working_set)
4771918 q working_set.sort();
4781918 q uint old_rel_count = 0;
4791918 q uint new_rel_count = count(working_set.current) + count(working_set.attic);
4803918 q while (old_rel_count < new_rel_count)
481208 q {
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);
487208 q }
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);
5003029 q for (auto i : req)
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));
5103029 q result.sort();
5113029 q return result;
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)
5190{
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);
5250 auto rel_ways =
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());
5330 return way_nodes;
5340}
537//-----------------------------------------------------------------------------
539class Recurse_Constraint : public Query_Constraint
541public:
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,
556 int type,
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() {}
563private:
564 Recurse_Statement* stmt;
565};
568Ranges< Uint32_Index > Recurse_Constraint::get_node_ranges(Resource_Manager& rman)
57086 q const Set* input = rman.get_set(stmt->get_input());
57186 q if (!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());
5882624 q if (!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());
6042727 q if (!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,
620 bool invert_ids)
62286 q const Set* input = rman.get_set(stmt->get_input());
62386 q if (!input)
62411 q return true;
62675 q Request_Context context(&query, rman);
62775 q if (stmt->get_role())
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)
64353 q way_members(
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)
6470 way_cnt_members(
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)
6520 way_link_members(
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)
6600 recurse_down_nodes(
6610 query, rman, ranges, ids, invert_ids,
6620 relations_loop(query, rman, input->relations, input->attic_relations))
6630 .swap(into.nodes, into.attic_nodes);
66575 q return true;
669bool Recurse_Constraint::get_data
670 (const Statement& query, Resource_Manager& rman, Set& into,
671 const Ranges< Uint31_Index >& ranges,
672 int type,
673 const std::vector< Uint32_Index >& ids,
674 bool invert_ids)
6765345 q const Set* input = rman.get_set(stmt->get_input());
6775345 q if (!input)
67832 q return true;
6805043 q Request_Context context(&query, rman);
6815043 q if (stmt->get_role())
68366 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role());
68466 q if (role_id == std::numeric_limits< uint32 >::max())
6850 return true;
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)
7010 collect_relations(
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);
7100 else
7110 return false;
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)
7270 {
7280 if (type != QUERY_WAY)
7290 return true;
7300 collect_ways(context, input->relations, input->attic_relations, ranges, ids, invert_ids)
7310 .swap(into.ways, into.attic_ways);
7320 }
7333632 q else if (stmt->get_type() == RECURSE_DOWN_REL)
7340 {
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);
7410 else
7420 {
7430 if (!ids.empty())
7440 {
7450 if (!invert_ids)
7460 rel_rels.filter_items(Id_Predicate< Relation_Skeleton >(ids));
7470 else
7480 rel_rels.filter_items(
7490 Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > >(
7500 Id_Predicate< Relation_Skeleton >(ids)));
7510 }
7520 keep_matching_skeletons(rel_rels.current, rel_rels.attic, rman.get_desired_timestamp());
7530 rel_rels.swap(into.relations, into.attic_relations);
7540 }
7550 }
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)
7690 {
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);
7730 else
7740 {
7750 auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input->ways, input->attic_ways };
7760 rel_ways.sort();
7770 rel_ways.set_union(collect_ways(context, input->nodes, input->attic_nodes, 0, {}, true).sort());
7790 auto result =
7800 collect_relations(query, rman, rel_ways.current, rel_ways.attic, Relation_Entry::WAY, ids, invert_ids);
7810 result.sort();
7820 result.set_union(
7830 collect_relations(query, rman, input->nodes, input->attic_nodes, Relation_Entry::NODE, ids, invert_ids)
7840 .sort());
7850 result.swap(into.relations, into.attic_relations);
7860 }
7870 }
78874 q else if (stmt->get_type() == RECURSE_UP_REL)
7890 {
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);
7930 else
7940 {
7950 auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input->ways, input->attic_ways };
7960 rel_ways.sort();
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 };
8000 rel_rels.sort();
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));
8080 if (!ids.empty())
8090 {
8100 if (!invert_ids)
8110 result.filter_items(Id_Predicate< Relation_Skeleton >(ids));
8120 else
8130 result.filter_items(
8140 Not_Predicate< Relation_Skeleton, Id_Predicate< Relation_Skeleton > >(
8150 Id_Predicate< Relation_Skeleton >(ids)));
8160 }
8170 result.swap(into.relations, into.attic_relations);
8180 }
8190 }
82074 q else
82174 q return false;
8234339 q return true;
827void Recurse_Constraint::filter(Resource_Manager& rman, Set& into)
8296251 q const Set* input = rman.get_set(stmt->get_input());
8306251 q if (!input)
83243 q into.clear();
83343 q return;
8365848 q if (stmt->get_type() == RECURSE_DOWN || stmt->get_type() == RECURSE_DOWN_REL)
8370 return;
8395848 q if (stmt->get_role())
84177 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role());
84277 q if (role_id == std::numeric_limits< uint32 >::max())
8430 return;
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);
85166 q else
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);
86055 q else
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)
8850 return;
88633 q else
88733 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations);
88977 q return;
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)
9000 {
9010 ids = way_cnt_nd_ids(input->ways, input->attic_ways, stmt->get_lower(), stmt->get_upper());
9020 rman.health_check(*stmt);
9030 }
9044640 q else if (stmt->get_type() == RECURSE_WAY_LINK)
9050 {
9060 ids = way_link_nd_ids(input->ways, input->attic_ways, stmt->get_lower(), stmt->get_upper());
9070 rman.health_check(*stmt);
9080 }
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);
9313428 q else
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)
9560 return;
9572924 q else
9582924 q into.relations.clear();
962void Recurse_Constraint::filter(const Statement& query, Resource_Manager& rman, Set& into)
9646251 q const Set* input = rman.get_set(stmt->get_input());
9656251 q if (!input)
96643 q return;
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)
9695848 q return;
9710 Request_Context context(&query, rman);
9720 if (stmt->get_type() == RECURSE_DOWN)
9730 {
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);
9940 }
9950 else if (stmt->get_type() == RECURSE_DOWN_REL)
9960 {
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);
10200 else
10210 {
10220 item_filter_map(into.relations, rel_rels.current);
10230 item_filter_map(into.attic_relations, rel_rels.attic);
10240 }
10250 }
10260 else if (stmt->get_type() == RECURSE_UP && !into.relations.empty())
10270 {
10280 auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input->ways, input->attic_ways };
10290 rel_ways.sort();
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);
10370 }
10380 else if (stmt->get_type() == RECURSE_UP_REL && !into.relations.empty())
10390 {
10400 auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input->ways, input->attic_ways };
10410 rel_ways.sort();
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 };
10450 rel_rels.sort();
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);
10570 }
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;
10681066222 q attributes["from"] = "_";
10691066222 q attributes["into"] = "_";
10701066222 q attributes["pos"] = "";
10711066222 q attributes["lower"] = "";
10721066222 q attributes["upper"] = "";
10731066222 q attributes["role"] = "";
10741066222 q attributes["role-restricted"] = "no";
10751066222 q attributes["type"] = "";
10771066222 q eval_attributes_array(get_name(), attributes, input_attributes);
10791066222 q input = attributes["from"];
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")
10876616 q type = RECURSE_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")
109914033 q type = RECURSE_WAY_NODE;
1100708174 q else if (attributes["type"] == "way-link")
11016015 q type = RECURSE_WAY_LINK;
1102648161 q else if (attributes["type"] == "way-count")
11038020 q type = RECURSE_WAY_COUNT;
1104568143 q else if (attributes["type"] == "down")
110510232 q type = RECURSE_DOWN;
1106466118 q else if (attributes["type"] == "down-rel")
11075117 q type = RECURSE_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")
11139223 q type = RECURSE_NODE_WAY;
111417352 q else if (attributes["type"] == "node-wr")
11154010 q type = RECURSE_NODE_WR;
111613342 q else if (attributes["type"] == "up")
11177926 q type = RECURSE_UP;
11185418 q else if (attributes["type"] == "up-rel")
11195418 q type = RECURSE_UP_REL;
11200 else
11210 {
11220 type = 0;
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());
11290 }
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)
11380 {
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());
11440 }
114510425 q else
114710425 q role = attributes["role"];
114810425 q restrict_to_role = true;
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\",");
1156328 q else
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]));
116382 q if (pos.back() == 0)
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.");
116882 q startpos = endpos + 1;
116982 q endpos = attributes["pos"].find(",", startpos);
1171328 q pos.push_back(atoll(&attributes["pos"][startpos]));
1172328 q if (pos.back() == 0)
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());
118314034 q if (lower_i <= 0)
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();
11876015 q else if (upper_i < lower_i)
11880 add_static_error("upper must be an integer greater or equal lower");
118914034 q lower = lower_i;
119014034 q upper = upper_i;
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)
11998439 q return "relation";
1200388162 q else if (type == RECURSE_RELATION_WAY || type == RECURSE_NODE_WAY)
12014019 q return "way";
1202348151 q else if (type == RECURSE_RELATION_NODE || type == RECURSE_WAY_NODE
1203348151 q || type == RECURSE_WAY_LINK || type == RECURSE_WAY_COUNT)
120414869 q return "node";
120520092 q else if (type == RECURSE_RELATION_NWR)
12060 return "nwr";
120720092 q else if (type == RECURSE_RELATION_NW)
12080 return "nw";
120920092 q else if (type == RECURSE_RELATION_WR || type == RECURSE_NODE_WR)
1210126 q return "wr";
121118887 q else if (type == RECURSE_RELATION_NR)
12120 return "nr";
121418887 q return "";
1218std::string Recurse_Statement::to_xml_representation(int type)
1220193160 q if (type == RECURSE_RELATION_RELATION)
12211919 q return "relation-relation";
1222174146 q else if (type == RECURSE_RELATION_BACKWARDS)
12231010 q return "relation-backwards";
1224164141 q else if (type == RECURSE_RELATION_WAY)
12251515 q return "relation-way";
1226149133 q else if (type == RECURSE_RELATION_NODE)
122799 q return "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)
12373533 q return "way-node";
123810599 q else if (type == RECURSE_WAY_LINK)
12391515 q return "way-link";
12409086 q else if (type == RECURSE_WAY_COUNT)
12412020 q return "way-count";
12427066 q else if (type == RECURSE_WAY_RELATION)
12432525 q return "way-relation";
12444543 q else if (type == RECURSE_NODE_RELATION)
12451111 q return "node-relation";
12463432 q else if (type == RECURSE_NODE_WR)
12471010 q return "node-wr";
12482424 q else if (type == RECURSE_NODE_WAY)
12492323 q return "node-way";
125011 q else if (type == RECURSE_DOWN)
12510 return "down";
125211 q else if (type == RECURSE_DOWN_REL)
12530 return "down-rel";
125411 q else if (type == RECURSE_UP)
125511 q return "up";
12560 else if (type == RECURSE_UP_REL)
12570 return "up-rel";
12590 return "void";
1263std::string Recurse_Statement::to_ql_representation(int type)
1265582222 q if (type == RECURSE_RELATION_RELATION)
12663819 q return "r";
1267544212 q else if (type == RECURSE_RELATION_BACKWARDS)
12682010 q return "br";
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)
12715223 q return "r";
1272472196 q else if (type == RECURSE_WAY_NODE)
12737033 q return "w";
1274402174 q else if (type == RECURSE_WAY_LINK)
12753015 q return "way_link";
1276372161 q else if (type == RECURSE_WAY_COUNT)
12774020 q return "way_cnt";
1278332143 q else if (type == RECURSE_WAY_RELATION)
12795025 q return "bw";
1280282126 q else if (type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WAY || type == RECURSE_NODE_WR)
12819243 q return "bn";
128219088 q else if (type == RECURSE_DOWN)
12836832 q return ">";
128412258 q else if (type == RECURSE_DOWN_REL)
12853417 q return ">>";
12868842 q else if (type == RECURSE_UP)
12875226 q return "<";
12883618 q else if (type == RECURSE_UP_REL)
12893618 q return "<<";
12910 return "";
1295void Recurse_Statement::execute(Resource_Manager& rman)
129625825190 q{
129725825190 q Set into;
129925825190 q const Set* input_set = rman.get_set(input);
130025825190 q if (!input_set)
13021310 q transfer_output(rman, into);
13031310 q return;
130625812187 q Request_Context context(this, rman);
130725812187 q if (restrict_to_role)
13092017 q uint32 role_id = determine_role_id(*rman.get_transaction(), role);
13102017 q if (role_id == std::numeric_limits< uint32 >::max())
13110 {
13120 transfer_output(rman, into);
13130 return;
13140 }
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)
132365 q relation_way_members(
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)
132832 q relation_node_members(
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)
133611 q collect_relations(
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)
134076 q collect_relations(
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)
13451411 q relation_relation_members(
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)
135265 q relation_way_members(
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)
135644 q relation_node_members(
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)
13620 {
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);
13780 }
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);
13971817 q relation_way_members(
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 };
14011817 q source_ways.sort();
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);
14091817 q rel_nodes.sort();
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};
14349940 q rel_ways.sort();
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 };
14409940 q rel_rels.sort();
14419940 q rel_rels.set_union(
14429940 q collect_relations(*this, rman, rel_ways.current, rel_ways.attic, Relation_Entry::WAY, {}, true).sort());
14439940 q rel_rels.set_union(
14449940 q collect_relations(*this, rman, input_set->nodes, input_set->attic_nodes, Relation_Entry::NODE, {}, true)
14459940 q .sort());
14479940 q if (type == RECURSE_UP)
14488024 q rel_rels.swap(into.relations, into.attic_relations);
14491918 q else
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)
14542560387 q {
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);
14582560387 q }
146025812187 q transfer_output(rman, into);
146125812187 q rman.health_check(*this);
146225812187 q}
1465Recurse_Statement::~Recurse_Statement()
14671066222 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin();
14681231222 q it != constraints.end(); ++it)
146916551 q delete *it;
1473Query_Constraint* Recurse_Statement::get_query_constraint()
147516551 q constraints.push_back(new Recurse_Constraint(*this));
147616551 q return constraints.back();