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

overpass_api/statements/recurse.cc

809 of 1171 instrumented lines run by the suite (69.1%) 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)
65724150 q Token_Node_Ptr tree_it = input_tree;
66724150 q uint line_nr = tree_it->line_col.first;
68724150 q std::string from = "_";
69724150 q std::vector< std::string > roles;
70724150 q std::string lower, upper;
71724150 q bool role_found = false;
73732150 q while (tree_it->token == "," && tree_it->rhs && tree_it->lhs)
7582 q roles.push_back(tree_it.rhs()->token);
7682 q tree_it = tree_it.lhs();
79724150 q if (tree_it->token == ":" && tree_it->rhs)
8030871 q {
8130871 q role_found = true;
8230871 q if (tree_it.rhs()->token == "-")
8313231 q {
8413231 q if (tree_it.rhs()->lhs)
8513231 q lower = tree_it.rhs().lhs()->token;
8613231 q if (tree_it.rhs()->rhs)
87246 q upper = tree_it.rhs().rhs()->token;
8813231 q }
8917641 q else if (!tree_it.rhs()->lhs && !tree_it.rhs()->rhs)
9017641 q roles.push_back(decode_json(tree_it.rhs()->token, error_output));
910 else
920 error_output->add_parse_error("Simple role token expected, structured syntax tree found.", line_nr);
9330871 q tree_it = tree_it.lhs();
9430871 q }
96724150 q if (tree_it->token == "." && tree_it->rhs)
97684146 q {
98684146 q from = tree_it.rhs()->token;
99684146 q tree_it = tree_it.lhs();
102724150 q std::string type = tree_it->token;
103724150 q std::map< std::string, std::string > attributes;
104724150 q attributes["from"] = from;
105724150 q attributes["into"] = into;
107724150 q if (type == "r")
10816038 q {
10916038 q if (result_type == "node")
1104010 q attributes["type"] = "relation-node";
11112029 q else if (result_type == "way")
1126416 q attributes["type"] = "relation-way";
1135614 q else if (result_type == "relation")
1145614 q attributes["type"] = "relation-relation";
1150 else if (result_type == "nwr")
1160 attributes["type"] = "relation-nwr";
1170 else if (result_type == "nw")
1180 attributes["type"] = "relation-nw";
1190 else if (result_type == "wr")
1200 attributes["type"] = "relation-wr";
1210 else if (result_type == "nr")
1220 attributes["type"] = "relation-nr";
1230 else if (error_output)
1240 error_output->add_parse_error("A recursion of type 'r' produces nodes, ways, or relations.", line_nr);
12516038 q }
126564124 q else if (type == "w")
1289223 q if (result_type == "node")
1299223 q attributes["type"] = "way-node";
1300 else if (error_output)
1310 error_output->add_parse_error("A recursion of type 'w' produces nodes.", line_nr);
133472110 q else if (type == "way_link")
1357218 q if (result_type == "node")
1367218 q attributes["type"] = "way-link";
1370 else if (error_output)
1380 error_output->add_parse_error("A recursion of type 'way_link' produces nodes.", line_nr);
14040095 q else if (type == "way_cnt")
14112029 q {
14212029 q if (result_type == "node")
14312029 q attributes["type"] = "way-count";
1440 else if (error_output)
1450 error_output->add_parse_error("A recursion of type 'way_cnt' produces nodes.", line_nr);
14612029 q }
14728069 q else if (type == "br")
1494812 q if (result_type == "relation")
1504812 q attributes["type"] = "relation-backwards";
1510 else if (error_output)
1520 error_output->add_parse_error("A recursion of type 'br' produces relations.", line_nr);
15423257 q else if (type == "bw")
1566416 q if (result_type == "relation")
1576416 q attributes["type"] = "way-relation";
1580 else if (error_output)
1590 error_output->add_parse_error("A recursion of type 'bw' produces relations.", line_nr);
16116842 q else if (type == "bn")
16216842 q {
16316842 q if (result_type == "way")
1647619 q attributes["type"] = "node-way";
1659223 q else if (result_type == "relation")
1665213 q attributes["type"] = "node-relation";
1674010 q else if (result_type == "wr")
1684010 q attributes["type"] = "node-wr";
1690 else if (error_output)
1700 error_output->add_parse_error("A recursion of type 'bn' produces ways or relations.", line_nr);
17116842 q }
1720 else
1730 return 0;
175724150 q if (role_found)
17630871 q {
17730871 q if (type == "r" || result_type == "relation")
1799222 q attributes["role"] = roles.back();
1809222 q attributes["role-restricted"] = "yes";
18221651 q else if (type == "w" || result_type == "way")
183246 q {
184246 q attributes["pos"] = roles[0];
185326 q for (uint i = 1; i < roles.size(); ++i)
18682 q attributes["pos"] += "," + roles[i];
187246 q }
18819246 q else if (type == "way_cnt" || type == "way_link")
18919246 q {
19019246 q if (role_found)
19119246 q {
19219246 q if (roles.empty())
19313231 q {
19413231 q attributes["lower"] = lower;
19513231 q attributes["upper"] = upper;
19613231 q }
1976015 q else
1996015 q attributes["lower"] = roles.back();
2006015 q attributes["upper"] = roles.back();
20219246 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);
20519246 q }
2060 else if (error_output)
2070 error_output->add_parse_error("A recursion of type '" + type + "' cannot have restrictions.", line_nr);
20830871 q }
209724150 q return new Recurse_Statement(line_nr, attributes, global_settings);
213Statement* Recurse_Statement::Criterion_Maker_2::create_criterion(const Token_Node_Ptr& input_tree,
214 const std::string& result_type, const std::string& into,
215 Statement::Factory& stmt_factory, Parsed_Query& global_settings, Error_Output* error_output)
21741 q Token_Node_Ptr tree_it = input_tree;
21841 q uint line_nr = tree_it->line_col.first;
22041 q std::string from = "_";
22241 q if (tree_it->token == "." && tree_it->rhs)
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 == ">")
23441 q attributes["type"] = "down";
2350 else if (type == ">>")
2360 attributes["type"] = "down-rel";
2370 else if (type == "<")
2380 attributes["type"] = "up";
2390 else if (type == "<<")
2400 attributes["type"] = "up-rel";
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)
25922173 q Timeless< Uint31_Index, Relation_Skeleton > result;
26122173 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources);
26222173 q std::set< Uint31_Index > req = extract_parent_indices(sources);
26322173 q rman.health_check(stmt);
26522173 q if (rman.get_desired_timestamp() != NOW)
2676334 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources);
2686334 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_sources);
2696334 q rman.health_check(stmt);
2716334 q std::vector< Uint64 > children_ids;
2726334 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(),
2736334 q std::back_inserter(children_ids));
274409934 q for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it)
275403634 q req.insert(*it);
2766334 q current_ids.swap(children_ids);
27922173 q Request_Context context(&stmt, rman);
28022173 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);
28621568 q else if (ids.empty())
28721568 q collect_items_discrete(context, req,
28821568 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);
29822173 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)
31076 q Timeless< Uint31_Index, Relation_Skeleton > result;
31276 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources);
31376 q rman.health_check(stmt);
31476 q std::set< Uint31_Index > req = extract_parent_indices(sources);
31576 q rman.health_check(stmt);
31776 q if (rman.get_desired_timestamp() != NOW)
31933 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources);
32033 q rman.health_check(stmt);
32133 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_sources);
32233 q rman.health_check(stmt);
32433 q std::vector< Uint64 > children_ids;
32533 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(),
32633 q std::back_inserter(children_ids));
3271473 q for (std::set< Uint31_Index >::const_iterator it = attic_req.begin(); it != attic_req.end(); ++it)
3281443 q req.insert(*it);
32933 q current_ids.swap(children_ids);
33276 q Request_Context context(&stmt, rman);
33376 q if (!invert_ids)
33411 q collect_items_discrete(context, req,
33511 q And_Predicate< Relation_Skeleton,
33611 q Id_Predicate< Relation_Skeleton >, Get_Parent_Rels_Role_Predicate >
33711 q (Id_Predicate< Relation_Skeleton >(ids),
33811 q Get_Parent_Rels_Role_Predicate(current_ids, source_type, role_id)), result.current, result.attic);
33965 q else if (ids.empty())
34065 q collect_items_discrete(context, req,
34165 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);
35176 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)
3616530 q Timeless< Uint31_Index, Relation_Skeleton > result;
3636530 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources);
3646530 q rman.health_check(stmt);
3666530 q if (rman.get_desired_timestamp() != NOW)
3681812 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources);
3691812 q rman.health_check(stmt);
3711812 q std::vector< Uint64 > children_ids;
3721812 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(),
3731812 q std::back_inserter(children_ids));
3741812 q current_ids.swap(children_ids);
3776530 q Request_Context context(&stmt, rman);
3786530 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);
3856328 q else if (ids.empty())
3866328 q collect_items_flat(context,
3876328 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);
3986530 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)
40822 q Timeless< Uint31_Index, Relation_Skeleton > result;
41022 q std::vector< Relation_Entry::Ref_Type > current_ids = extract_ids(sources);
41122 q rman.health_check(stmt);
41322 q Request_Context context(&stmt, rman);
41422 q if (rman.get_desired_timestamp() != NOW)
41611 q std::vector< Relation_Entry::Ref_Type > attic_ids = extract_ids(attic_sources);
41711 q rman.health_check(stmt);
41911 q std::vector< Uint64 > children_ids;
42011 q std::set_union(current_ids.begin(), current_ids.end(), attic_ids.begin(), attic_ids.end(),
42111 q std::back_inserter(children_ids));
42211 q current_ids.swap(children_ids);
42522 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);
43222 q else if (ids.empty())
43322 q collect_items_flat(context,
43422 q Get_Parent_Rels_Role_Predicate(current_ids, Relation_Entry::RELATION, role_id),
43522 q result.current, result.attic);
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);
44622 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)
4551816 q Request_Context context(&query, rman);
4561816 q auto working_set = Timeless< Uint31_Index, Relation_Skeleton >{ source, attic_source };
4571816 q working_set.sort();
4581816 q uint old_rel_count = 0;
4591816 q uint new_rel_count = count(working_set.current) + count(working_set.attic);
4603516 q while (old_rel_count < new_rel_count)
4621712 q old_rel_count = new_rel_count;
4631712 q auto new_results = relation_relation_members(
4641712 q context, working_set.current, working_set.attic, Ranges< Uint31_Index >::global(), {}, true);
4651712 q working_set.set_union(new_results.sort());
4661712 q keep_matching_skeletons(working_set.current, working_set.attic, context.get_desired_timestamp());
4671712 q new_rel_count = count(working_set.current) + count(working_set.attic);
4691816 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)
4773226 q working_set.sort();
4783226 q uint old_rel_count = 0;
4793226 q uint new_rel_count = count(working_set.current) + count(working_set.attic);
4808626 q while (old_rel_count < new_rel_count)
4825420 q old_rel_count = new_rel_count;
4835420 q auto new_results = collect_relations(query, rman, working_set.current, working_set.attic, {}, true);
4845420 q working_set.set_union(new_results.sort());
4855420 q keep_matching_skeletons(working_set.current, working_set.attic, rman.get_desired_timestamp());
4865420 q new_rel_count = count(working_set.current) + count(working_set.attic);
4883226 q return std::move(working_set);
492template< typename Index, typename Object >
493Ranges< Uint31_Index > extract_parent_indices(
494 const std::map< Index, std::vector< Object > >& cur_elems,
495 const std::map< Index, std::vector< Attic< Object > > >& attic_elems)
4972927 q Ranges< Uint31_Index > result;
4992927 q std::set< Uint31_Index > req = extract_parent_indices(cur_elems);
5002927 q for (auto i : req)
5011922027 q result.push_back(i, inc(i));
5032927 q if (!attic_elems.empty())
50566 q std::set< Uint31_Index > attic_req = extract_parent_indices(attic_elems);
50666 q for (auto i : attic_req)
5074906 q result.push_back(i, inc(i));
5102927 q result.sort();
5112927 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:
54217455 q Recurse_Constraint(Recurse_Statement& stmt_) : stmt(&stmt_) {}
544 Ranges< Uint32_Index > get_node_ranges(Resource_Manager& rman) override;
545 Ranges< Uint31_Index > get_way_ranges(Resource_Manager& rman) override;
546 Ranges< Uint31_Index > get_relation_ranges(Resource_Manager& rman) override;
5486655 q Query_Filter_Strategy delivers_data(Resource_Manager& rman) override { return prefer_ranges; }
550 virtual bool get_data(const Statement& query, Resource_Manager& rman, Set& into,
551 const Ranges< Uint32_Index >& ranges,
552 const std::vector< Node::Id_Type >& ids,
553 bool invert_ids) override;
554 virtual bool get_data(const Statement& query, Resource_Manager& rman, Set& into,
555 const Ranges< Uint31_Index >& ranges,
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)
57098 q const Set* input = rman.get_set(stmt->get_input());
57198 q if (!input)
57222 q return Ranges< Uint32_Index >();
57476 q if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR
57576 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR)
57622 q return relation_node_member_indices(input->relations, input->attic_relations);
57754 q else if (stmt->get_type() == RECURSE_WAY_NODE || stmt->get_type() == RECURSE_WAY_LINK
57854 q || stmt->get_type() == RECURSE_WAY_COUNT)
57954 q return way_nd_indices(input->ways, input->attic_ways);
5810 return Ranges< Uint32_Index >::global();
585Ranges< Uint31_Index > Recurse_Constraint::get_way_ranges(Resource_Manager& rman)
5872421 q const Set* input = rman.get_set(stmt->get_input());
5882421 q if (!input)
58921 q return Ranges< Uint31_Index >();
5912220 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR
5922220 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_WR)
59354 q return relation_way_member_indices(input->relations, input->attic_relations);
5941716 q else if (stmt->get_type() == RECURSE_NODE_WAY)
5951312 q return extract_parent_indices(input->nodes, input->attic_nodes);
59744 q return Ranges< Uint31_Index >::global();
601Ranges< Uint31_Index > Recurse_Constraint::get_relation_ranges(Resource_Manager& rman)
6033029 q const Set* input = rman.get_set(stmt->get_input());
6043029 q if (!input)
6050 return Ranges< Uint31_Index >();
6073029 q if (stmt->get_type() == RECURSE_NODE_RELATION)
60866 q return extract_parent_indices(input->nodes, input->attic_nodes);
6092423 q else if (stmt->get_type() == RECURSE_WAY_RELATION)
610109 q return extract_parent_indices(input->ways, input->attic_ways);
6121414 q return Ranges< Uint31_Index >::global();
616bool Recurse_Constraint::get_data
617 (const Statement& query, Resource_Manager& rman, Set& into,
618 const Ranges< Uint32_Index >& ranges,
619 const std::vector< Node::Id_Type >& ids,
620 bool invert_ids)
62298 q const Set* input = rman.get_set(stmt->get_input());
62398 q if (!input)
62422 q return true;
62676 q Request_Context context(&query, rman);
62776 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);
63765 q else if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR
63865 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR)
63911 q relation_node_members(
64011 q context, input->relations, input->attic_relations, ranges, ids, invert_ids)
64111 q .swap(into.nodes, into.attic_nodes);
64254 q else if (stmt->get_type() == RECURSE_WAY_NODE)
64354 q way_members(
64454 q context, input->ways, input->attic_ways, stmt->get_pos(), ranges, ids, invert_ids)
64554 q .swap(into.nodes, into.attic_nodes);
6460 else if (stmt->get_type() == RECURSE_WAY_COUNT)
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);
66576 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)
6765445 q const Set* input = rman.get_set(stmt->get_input());
6775445 q if (!input)
67821 q return true;
6805244 q Request_Context context(&query, rman);
6815244 q if (stmt->get_role())
68375 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role());
68475 q if (role_id == std::numeric_limits< uint32 >::max())
6850 return true;
68775 q if (stmt->get_type() == RECURSE_RELATION_WAY
68875 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_WAY)
68975 q || (stmt->get_type() == RECURSE_RELATION_NW && type == QUERY_WAY)
69075 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_WAY))
69121 q collect_ways(context, input->relations, input->attic_relations, ranges, ids, invert_ids, &role_id)
69221 q .swap(into.ways, into.attic_ways);
69354 q else if (stmt->get_type() == RECURSE_RELATION_RELATION
69454 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_RELATION)
69554 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_RELATION)
69654 q || (stmt->get_type() == RECURSE_RELATION_NR && type == QUERY_RELATION))
6970 relation_relation_members(
6980 context, input->relations, input->attic_relations, ranges, ids, invert_ids, &role_id)
6990 .swap(into.relations, into.attic_relations);
70054 q else if (stmt->get_type() == RECURSE_NODE_RELATION)
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);
70454 q else if (stmt->get_type() == RECURSE_WAY_RELATION)
70554 q collect_relations(query, rman, input->ways, input->attic_ways, Relation_Entry::WAY, ids, invert_ids, role_id)
70654 q .swap(into.relations, into.attic_relations);
7070 else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS)
7080 collect_relations(query, rman, input->relations, input->attic_relations, ids, invert_ids, role_id)
7090 .swap(into.relations, into.attic_relations);
7100 else
7110 return false;
7134539 q else if (stmt->get_type() == RECURSE_RELATION_WAY
7144539 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_WAY)
7154539 q || (stmt->get_type() == RECURSE_RELATION_NW && type == QUERY_WAY)
7164539 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_WAY))
71733 q collect_ways(context, input->relations, input->attic_relations, ranges, ids, invert_ids)
71833 q .swap(into.ways, into.attic_ways);
7194236 q else if (stmt->get_type() == RECURSE_RELATION_RELATION
7204236 q || (stmt->get_type() == RECURSE_RELATION_NWR && type == QUERY_RELATION)
7214236 q || (stmt->get_type() == RECURSE_RELATION_NR && type == QUERY_RELATION)
7224236 q || (stmt->get_type() == RECURSE_RELATION_WR && type == QUERY_RELATION))
72355 q relation_relation_members(
72455 q context, input->relations, input->attic_relations, ranges, ids, invert_ids, 0)
72555 q .swap(into.relations, into.attic_relations);
7263732 q else if (stmt->get_type() == RECURSE_DOWN)
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 }
7333732 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 }
7563732 q else if (stmt->get_type() == RECURSE_NODE_WAY)
7571312 q collect_ways(context, input->nodes, input->attic_nodes, stmt->get_pos(), ids, invert_ids)
7581312 q .swap(into.ways, into.attic_ways);
7592420 q else if (stmt->get_type() == RECURSE_NODE_RELATION)
76066 q collect_relations(query, rman, input->nodes, input->attic_nodes, Relation_Entry::NODE, ids, invert_ids)
76166 q .swap(into.relations, into.attic_relations);
7621814 q else if (stmt->get_type() == RECURSE_WAY_RELATION)
76355 q collect_relations(query, rman, input->ways, input->attic_ways, Relation_Entry::WAY, ids, invert_ids)
76455 q .swap(into.relations, into.attic_relations);
765139 q else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS)
76655 q collect_relations(query, rman, input->relations, input->attic_relations, ids, invert_ids)
76755 q .swap(into.relations, into.attic_relations);
76884 q else if (stmt->get_type() == RECURSE_UP)
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 }
78884 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 }
82084 q else
82184 q return false;
8234440 q return true;
827void Recurse_Constraint::filter(Resource_Manager& rman, Set& into)
8296655 q const Set* input = rman.get_set(stmt->get_input());
8306655 q if (!input)
83243 q into.clear();
83343 q return;
8366253 q if (stmt->get_type() == RECURSE_DOWN || stmt->get_type() == RECURSE_DOWN_REL)
8370 return;
8396253 q if (stmt->get_role())
84197 q uint32 role_id = determine_role_id(*rman.get_transaction(), *stmt->get_role());
84297 q if (role_id == std::numeric_limits< uint32 >::max())
8430 return;
84597 q if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR
84697 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR)
84722 q Timeless< Uint32_Index, Node_Skeleton >{}.swap(into.nodes, into.attic_nodes)
84822 q .filter_items(Id_Predicate< Node_Skeleton >(
84922 q relation_node_member_ids(input->relations, input->attic_relations, &role_id)))
85022 q .swap(into.nodes, into.attic_nodes);
85175 q else
85275 q Timeless< Uint32_Index, Node_Skeleton >{}.swap(into.nodes, into.attic_nodes);
85497 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR
85597 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_WR)
85621 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways)
85721 q .filter_items(Id_Predicate< Way_Skeleton >(
85821 q relation_way_member_ids(input->relations, input->attic_relations, &role_id)))
85921 q .swap(into.ways, into.attic_ways);
86076 q else
86176 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways);
86397 q if (stmt->get_type() == RECURSE_RELATION_RELATION || stmt->get_type() == RECURSE_RELATION_NWR
86497 q || stmt->get_type() == RECURSE_RELATION_WR || stmt->get_type() == RECURSE_RELATION_NR)
8650 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations)
8660 .filter_items(Id_Predicate< Relation_Skeleton >(
8670 relation_relation_member_ids(input->relations, input->attic_relations, &role_id)))
8680 .swap(into.relations, into.attic_relations);
86997 q else if (stmt->get_type() == RECURSE_NODE_RELATION)
8700 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations)
8710 .filter_items(Get_Parent_Rels_Role_Predicate(
8720 extract_ids(input->nodes, input->attic_nodes), Relation_Entry::NODE, role_id))
8730 .swap(into.relations, into.attic_relations);
87497 q else if (stmt->get_type() == RECURSE_WAY_RELATION)
87554 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations)
87654 q .filter_items(Get_Parent_Rels_Role_Predicate(
87754 q extract_ids(input->ways, input->attic_ways), Relation_Entry::WAY, role_id))
87854 q .swap(into.relations, into.attic_relations);
87943 q else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS)
8800 Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations)
8810 .filter_items(Get_Parent_Rels_Role_Predicate(
8820 extract_ids(input->relations), Relation_Entry::RELATION, role_id))
8830 .swap(into.relations, into.attic_relations);
88443 q else if (stmt->get_type() == RECURSE_UP || stmt->get_type() == RECURSE_UP_REL)
8850 return;
88643 q else
88743 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations);
88997 q return;
8935346 q std::vector< Node::Id_Type > ids;
8945346 q if (stmt->get_type() == RECURSE_WAY_NODE)
89654 q ids = way_nd_ids(input->ways, input->attic_ways, stmt->get_pos());
89754 q rman.health_check(*stmt);
8994843 q else if (stmt->get_type() == RECURSE_WAY_COUNT)
9000 {
9010 ids = way_cnt_nd_ids(input->ways, input->attic_ways, stmt->get_lower(), stmt->get_upper());
9020 rman.health_check(*stmt);
9030 }
9044843 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 }
9094843 q else if (stmt->get_type() == RECURSE_RELATION_NODE || stmt->get_type() == RECURSE_RELATION_NWR
9104843 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_NR)
91211 q ids = relation_node_member_ids(input->relations, input->attic_relations);
91311 q rman.health_check(*stmt);
9165346 q filter_items(Id_Predicate< Node_Skeleton >(ids), into.nodes);
9175346 q filter_items(Id_Predicate< Node_Skeleton >(ids), into.attic_nodes);
9205346 q if (stmt->get_type() == RECURSE_RELATION_WAY || stmt->get_type() == RECURSE_RELATION_NWR
9215346 q || stmt->get_type() == RECURSE_RELATION_NW || stmt->get_type() == RECURSE_RELATION_WR)
92233 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways)
92333 q .filter_items(Id_Predicate< Way_Skeleton >(
92433 q relation_way_member_ids(input->relations, input->attic_relations)))
92533 q .swap(into.ways, into.attic_ways);
9265043 q else if (stmt->get_type() == RECURSE_NODE_WAY || stmt->get_type() == RECURSE_UP
9275043 q || stmt->get_type() == RECURSE_UP_REL)
9281312 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways)
9291312 q .filter_items(Get_Parent_Ways_Predicate(extract_ids(input->nodes, input->attic_nodes), stmt->get_pos()))
9301312 q .swap(into.ways, into.attic_ways);
9313732 q else
9323732 q Timeless< Uint31_Index, Way_Skeleton >{}.swap(into.ways, into.attic_ways);
9345346 q if (stmt->get_type() == RECURSE_RELATION_RELATION || stmt->get_type() == RECURSE_RELATION_NWR
9355346 q || stmt->get_type() == RECURSE_RELATION_WR || stmt->get_type() == RECURSE_RELATION_NR)
93686 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations)
93786 q .filter_items(Id_Predicate< Relation_Skeleton >(
93886 q relation_relation_member_ids(input->relations, input->attic_relations)))
93986 q .swap(into.relations, into.attic_relations);
9404542 q else if (stmt->get_type() == RECURSE_NODE_RELATION)
94177 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations)
94277 q .filter_items(Get_Parent_Rels_Predicate(
94377 q extract_ids(input->nodes, input->attic_nodes), Relation_Entry::NODE))
94477 q .swap(into.relations, into.attic_relations);
9453835 q else if (stmt->get_type() == RECURSE_WAY_RELATION)
94676 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations)
94776 q .filter_items(Get_Parent_Rels_Predicate(
94876 q extract_ids(input->ways, input->attic_ways), Relation_Entry::WAY))
94976 q .swap(into.relations, into.attic_relations);
9503129 q else if (stmt->get_type() == RECURSE_RELATION_BACKWARDS)
95155 q Timeless< Uint31_Index, Relation_Skeleton >{}.swap(into.relations, into.attic_relations)
95255 q .filter_items(Get_Parent_Rels_Predicate(
95355 q extract_ids(input->relations, input->attic_relations), Relation_Entry::RELATION))
95455 q .swap(into.relations, into.attic_relations);
9552624 q else if (stmt->get_type() == RECURSE_UP || stmt->get_type() == RECURSE_UP_REL)
9560 return;
9572624 q else
9582624 q into.relations.clear();
962void Recurse_Constraint::filter(const Statement& query, Resource_Manager& rman, Set& into)
9646655 q const Set* input = rman.get_set(stmt->get_input());
9656655 q if (!input)
96643 q return;
9676253 q if (stmt->get_type() != RECURSE_DOWN && stmt->get_type() != RECURSE_DOWN_REL
9686253 q && stmt->get_type() != RECURSE_UP && stmt->get_type() != RECURSE_UP_REL)
9696253 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)
10641007205 q : Output_Statement(line_number_), restrict_to_role(false), lower(1), upper(0)
10661007205 q std::map< std::string, std::string > attributes;
10681007205 q attributes["from"] = "_";
10691007205 q attributes["into"] = "_";
10701007205 q attributes["pos"] = "";
10711007205 q attributes["lower"] = "";
10721007205 q attributes["upper"] = "";
10731007205 q attributes["role"] = "";
10741007205 q attributes["role-restricted"] = "no";
10751007205 q attributes["type"] = "";
10771007205 q eval_attributes_array(get_name(), attributes, input_attributes);
10791007205 q input = attributes["from"];
10801007205 q set_output(attributes["into"]);
10821007205 q if (attributes["type"] == "relation-relation")
10835614 q type = RECURSE_RELATION_RELATION;
1084951200 q else if (attributes["type"] == "relation-backwards")
10854812 q type = RECURSE_RELATION_BACKWARDS;
1086903194 q else if (attributes["type"] == "relation-way")
10877017 q type = RECURSE_RELATION_WAY;
1088833183 q else if (attributes["type"] == "relation-node")
10894010 q type = RECURSE_RELATION_NODE;
1090793176 q else if (attributes["type"] == "relation-nwr")
10910 type = RECURSE_RELATION_NWR;
1092793176 q else if (attributes["type"] == "relation-nw")
10930 type = RECURSE_RELATION_NW;
1094793176 q else if (attributes["type"] == "relation-wr")
10950 type = RECURSE_RELATION_WR;
1096793176 q else if (attributes["type"] == "relation-nr")
10970 type = RECURSE_RELATION_NR;
1098793176 q else if (attributes["type"] == "way-node")
10999223 q type = RECURSE_WAY_NODE;
1100701164 q else if (attributes["type"] == "way-link")
11017218 q type = RECURSE_WAY_LINK;
1102629153 q else if (attributes["type"] == "way-count")
110312029 q type = RECURSE_WAY_COUNT;
1104509129 q else if (attributes["type"] == "down")
11056421 q type = RECURSE_DOWN;
1106445115 q else if (attributes["type"] == "down-rel")
11074816 q type = RECURSE_DOWN_REL;
1108397104 q else if (attributes["type"] == "way-relation")
11096416 q type = RECURSE_WAY_RELATION;
111033391 q else if (attributes["type"] == "node-relation")
11115213 q type = RECURSE_NODE_RELATION;
111228180 q else if (attributes["type"] == "node-way")
11138220 q type = RECURSE_NODE_WAY;
111419961 q else if (attributes["type"] == "node-wr")
11154010 q type = RECURSE_NODE_WR;
111615951 q else if (attributes["type"] == "up")
11178127 q type = RECURSE_UP;
11187826 q else if (attributes["type"] == "up-rel")
11197826 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 }
11311007205 q if (!attributes["role"].empty() || attributes["role-restricted"] == "yes")
11339222 q if (type != RECURSE_RELATION_RELATION && type != RECURSE_RELATION_BACKWARDS
11349222 q && type != RECURSE_RELATION_WAY && type != RECURSE_RELATION_NODE
11359222 q && type != RECURSE_RELATION_NWR && type != RECURSE_RELATION_NW && type != RECURSE_RELATION_WR
11369222 q && type != RECURSE_RELATION_NR
11379222 q && type != RECURSE_NODE_RELATION && type != RECURSE_WAY_RELATION)
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 }
11459222 q else
11479222 q role = attributes["role"];
11489222 q restrict_to_role = true;
11521007205 q if (!attributes["pos"].empty())
1154246 q if (type != RECURSE_WAY_NODE && type != RECURSE_NODE_WAY)
11550 add_static_error("A role can only be specified for values \"way-node\" or \"node-way\",");
1156246 q else
1158246 q std::string::size_type startpos = 0;
1159246 q std::string::size_type endpos = attributes["pos"].find(",");
1160326 q while (endpos != std::string::npos)
116282 q pos.push_back(atoll(&attributes["pos"][startpos]));
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);
1171246 q pos.push_back(atoll(&attributes["pos"][startpos]));
1172246 q if (pos.back() == 0)
11730 add_static_error("Invalid pos '" + attributes["pos"].substr(startpos) + "' in positions list.");
1176246 q std::sort(pos.begin(), pos.end());
11791007205 q if (!attributes["lower"].empty() || !attributes["upper"].empty())
118119246 q int64_t lower_i = atoll(attributes["lower"].c_str());
118219246 q int64_t upper_i = atoll(attributes["upper"].c_str());
118319246 q if (lower_i <= 0)
11840 add_static_error("lower must be an integer greater or equal 1");
118519246 q if (attributes["upper"].empty())
118610826 q upper_i = std::numeric_limits< unsigned int >::max();
11878421 q else if (upper_i < lower_i)
11880 add_static_error("upper must be an integer greater or equal lower");
118919246 q lower = lower_i;
119019246 q upper = upper_i;
1195std::string Recurse_Statement::to_target_type(int type)
1197434165 q if (type == RECURSE_RELATION_RELATION || type == RECURSE_RELATION_BACKWARDS
1198434165 q || type == RECURSE_WAY_RELATION || type == RECURSE_NODE_RELATION)
11995427 q return "relation";
1200380150 q else if (type == RECURSE_RELATION_WAY || type == RECURSE_NODE_WAY)
12014420 q return "way";
1202336137 q else if (type == RECURSE_RELATION_NODE || type == RECURSE_WAY_NODE
1203336137 q || type == RECURSE_WAY_LINK || type == RECURSE_WAY_COUNT)
120414668 q return "node";
120519087 q else if (type == RECURSE_RELATION_NWR)
12060 return "nwr";
120719087 q else if (type == RECURSE_RELATION_NW)
12080 return "nw";
120919087 q else if (type == RECURSE_RELATION_WR || type == RECURSE_NODE_WR)
1210126 q return "wr";
121117882 q else if (type == RECURSE_RELATION_NR)
12120 return "nr";
121417882 q return "";
1218std::string Recurse_Statement::to_xml_representation(int type)
1220182151 q if (type == RECURSE_RELATION_RELATION)
12211414 q return "relation-relation";
1222168143 q else if (type == RECURSE_RELATION_BACKWARDS)
12231212 q return "relation-backwards";
1224156135 q else if (type == RECURSE_RELATION_WAY)
12251616 q return "relation-way";
1226140124 q else if (type == RECURSE_RELATION_NODE)
12271010 q return "relation-node";
1228130115 q else if (type == RECURSE_RELATION_NWR)
12290 return "relation-nwr";
1230130115 q else if (type == RECURSE_RELATION_NW)
12310 return "relation-nw";
1232130115 q else if (type == RECURSE_RELATION_WR)
12330 return "relation-wr";
1234130115 q else if (type == RECURSE_RELATION_NR)
12350 return "relation-nr";
1236130115 q else if (type == RECURSE_WAY_NODE)
12372323 q return "way-node";
1238107100 q else if (type == RECURSE_WAY_LINK)
12391818 q return "way-link";
12408985 q else if (type == RECURSE_WAY_COUNT)
12413029 q return "way-count";
12425958 q else if (type == RECURSE_WAY_RELATION)
12431616 q return "way-relation";
12444343 q else if (type == RECURSE_NODE_RELATION)
12451313 q return "node-relation";
12463030 q else if (type == RECURSE_NODE_WR)
12471010 q return "node-wr";
12482020 q else if (type == RECURSE_NODE_WAY)
12491919 q return "node-way";
125011 q else if (type == RECURSE_DOWN)
125111 q return "down";
12520 else if (type == RECURSE_DOWN_REL)
12530 return "down-rel";
12540 else if (type == RECURSE_UP)
12550 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)
1265550205 q if (type == RECURSE_RELATION_RELATION)
12662814 q return "r";
1267522200 q else if (type == RECURSE_RELATION_BACKWARDS)
12682412 q return "br";
1269498194 q else if (type == RECURSE_RELATION_WAY || type == RECURSE_RELATION_NODE || type == RECURSE_RELATION_NWR
1270498194 q || type == RECURSE_RELATION_WR || type == RECURSE_RELATION_NW || type == RECURSE_RELATION_NR)
12715626 q return "r";
1272442176 q else if (type == RECURSE_WAY_NODE)
12734623 q return "w";
1274396164 q else if (type == RECURSE_WAY_LINK)
12753618 q return "way_link";
1276360153 q else if (type == RECURSE_WAY_COUNT)
12776029 q return "way_cnt";
1278300129 q else if (type == RECURSE_WAY_RELATION)
12793216 q return "bw";
1280268117 q else if (type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WAY || type == RECURSE_NODE_WR)
12818843 q return "bn";
128218083 q else if (type == RECURSE_DOWN)
12834221 q return ">";
128413866 q else if (type == RECURSE_DOWN_REL)
12853216 q return ">>";
128610651 q else if (type == RECURSE_UP)
12875427 q return "<";
12885226 q else if (type == RECURSE_UP_REL)
12895226 q return "<<";
12910 return "";
1295void Recurse_Statement::execute(Resource_Manager& rman)
12972636163 q Set into;
12992636163 q const Set* input_set = rman.get_set(input);
13002636163 q if (!input_set)
130265 q transfer_output(rman, into);
130365 q return;
13062630162 q Request_Context context(this, rman);
13072630162 q if (restrict_to_role)
13091414 q uint32 role_id = determine_role_id(*rman.get_transaction(), role);
13101414 q if (role_id == std::numeric_limits< uint32 >::max())
13110 {
13120 transfer_output(rman, into);
13130 return;
13140 }
13161414 q if (type == RECURSE_RELATION_RELATION || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_WR
13171414 q || type == RECURSE_RELATION_NR)
131833 q relation_relation_members(
131933 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true, &role_id)
132033 q .swap(into.relations, into.attic_relations);
13211414 q if (type == RECURSE_RELATION_WAY || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW
13221414 q || type == RECURSE_RELATION_WR)
132344 q relation_way_members(
132444 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true, &role_id)
132544 q .swap(into.ways, into.attic_ways);
13261414 q if (type == RECURSE_RELATION_NODE || type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW
13271414 q || type == RECURSE_RELATION_NR)
132833 q relation_node_members(
132933 q context, input_set->relations, input_set->attic_relations,
133033 q Ranges< Uint32_Index >::global(), {}, true, &role_id)
133133 q .swap(into.nodes, into.attic_nodes);
13321111 q else if (type == RECURSE_RELATION_BACKWARDS)
133322 q collect_relations(*this, rman, input_set->relations, input_set->attic_relations, {}, true, role_id)
133422 q .swap(into.relations, into.attic_relations);
133599 q else if (type == RECURSE_NODE_RELATION)
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);
133988 q else if (type == RECURSE_WAY_RELATION)
134011 q collect_relations(
134111 q *this, rman, input_set->ways, input_set->attic_ways, Relation_Entry::WAY, {}, true, role_id)
134211 q .swap(into.relations, into.attic_relations);
13442616152 q else if (type == RECURSE_RELATION_RELATION)
134555 q relation_relation_members(
134655 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true)
134755 q .swap(into.relations, into.attic_relations);
13482611149 q else if (type == RECURSE_RELATION_BACKWARDS)
134965 q collect_relations(*this, rman, input_set->relations, input_set->attic_relations, {}, true)
135065 q .swap(into.relations, into.attic_relations);
13512605146 q else if (type == RECURSE_RELATION_WAY)
1352118 q relation_way_members(
1353118 q context, input_set->relations, input_set->attic_relations, Ranges< Uint31_Index >::global(), {}, true)
1354118 q .swap(into.ways, into.attic_ways);
13552594140 q else if (type == RECURSE_RELATION_NODE)
135643 q relation_node_members(
135743 q context, input_set->relations, input_set->attic_relations,
135843 q Ranges< Uint32_Index >::global(), {}, true)
135943 q .swap(into.nodes, into.attic_nodes);
13602590139 q else if (type == RECURSE_RELATION_NWR || type == RECURSE_RELATION_NW || type == RECURSE_RELATION_WR
13612590139 q || type == RECURSE_RELATION_NR)
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 }
13792590139 q else if (type == RECURSE_WAY_NODE)
13801513 q way_members(context, input_set->ways, input_set->attic_ways, get_pos(),
13811513 q Ranges< Uint32_Index >::global(), {}, true)
13821513 q .swap(into.nodes, into.attic_nodes);
13832575130 q else if (type == RECURSE_WAY_COUNT)
13843928 q way_cnt_members(context, input_set->ways, input_set->attic_ways, lower, upper,
13853928 q Ranges< Uint32_Index >::global(), {}, true)
13863928 q .swap(into.nodes, into.attic_nodes);
13872536108 q else if (type == RECURSE_WAY_LINK)
13882118 q way_link_members(context, input_set->ways, input_set->attic_ways, lower, upper,
13892118 q Ranges< Uint32_Index >::global(), {}, true)
13902118 q .swap(into.nodes, into.attic_nodes);
1391251596 q else if (type == RECURSE_DOWN)
1392237319 q add_nw_member_objects(context, *input_set, into);
139314284 q else if (type == RECURSE_DOWN_REL)
13951816 q relations_loop(*this, rman, input_set->relations, input_set->attic_relations)
13961816 q .swap(into.relations, into.attic_relations);
13971816 q relation_way_members(
13981816 q context, into.relations, into.attic_relations, Ranges< Uint31_Index >::global(), {}, true)
13991816 q .swap(into.ways, into.attic_ways);
14001816 q auto source_ways = Timeless< Uint31_Index, Way_Skeleton >{ input_set->ways, input_set->attic_ways };
14011816 q source_ways.sort();
14031816 q Timeless< Uint31_Index, Way_Skeleton > result_ways;
14041816 q source_ways.set_union(result_ways.swap(into.ways, into.attic_ways).sort());
14051816 q result_ways.swap(into.ways, into.attic_ways);
14071816 q Timeless< Uint32_Index, Node_Skeleton > rel_nodes = relation_node_members(
14081816 q context, into.relations, into.attic_relations, Ranges< Uint32_Index >::global(), {}, true);
14091816 q rel_nodes.sort();
14111816 q Timeless< Uint32_Index, Node_Skeleton > more_nodes
14121816 q = way_members(context, source_ways.current, source_ways.attic, 0,
14131816 q Ranges< Uint32_Index >::global(), {}, true);
14141816 q rel_nodes.set_union(more_nodes.sort());
14161816 q keep_matching_skeletons(rel_nodes.current, rel_nodes.attic, rman.get_desired_timestamp());
14171816 q rel_nodes.swap(into.nodes, into.attic_nodes);
141912470 q else if (type == RECURSE_NODE_WAY || type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WR)
14212218 q if (type == RECURSE_NODE_WAY || type == RECURSE_NODE_WR)
14221613 q collect_ways(context, input_set->nodes, input_set->attic_nodes, get_pos(), {}, true)
14231613 q .swap(into.ways, into.attic_ways);
14242218 q if (type == RECURSE_NODE_RELATION || type == RECURSE_NODE_WR)
14251311 q collect_relations(*this, rman, input_set->nodes, input_set->attic_nodes, Relation_Entry::NODE, {}, true)
14261311 q .swap(into.relations, into.attic_relations);
142810255 q else if (type == RECURSE_WAY_RELATION)
142975 q collect_relations(*this, rman, input_set->ways, input_set->attic_ways, Relation_Entry::WAY, {}, true)
143075 q .swap(into.relations, into.attic_relations);
14319550 q else if (type == RECURSE_UP || type == RECURSE_UP_REL)
14339550 q auto rel_ways = Timeless< Uint31_Index, Way_Skeleton >{ input_set->ways, input_set->attic_ways};
14349550 q rel_ways.sort();
14359550 q auto node_ways = collect_ways(context, input_set->nodes, input_set->attic_nodes, 0, {}, true);
14369550 q rel_ways.set_union(node_ways.sort());
14379550 q node_ways.swap(into.ways, into.attic_ways);
14399550 q auto rel_rels = Timeless< Uint31_Index, Relation_Skeleton >{ input_set->relations, input_set->attic_relations };
14409550 q rel_rels.sort();
14419550 q rel_rels.set_union(
14429550 q collect_relations(*this, rman, rel_ways.current, rel_ways.attic, Relation_Entry::WAY, {}, true).sort());
14439550 q rel_rels.set_union(
14449550 q collect_relations(*this, rman, input_set->nodes, input_set->attic_nodes, Relation_Entry::NODE, {}, true)
14459550 q .sort());
14479550 q if (type == RECURSE_UP)
14486326 q rel_rels.swap(into.relations, into.attic_relations);
14493226 q else
14503226 q relations_up_loop(*this, rman, std::move(rel_rels)).swap(into.relations, into.attic_relations);
14532630162 q if (rman.get_desired_timestamp() != NOW)
1454179273 q {
1455179273 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.nodes, into.attic_nodes);
1456179273 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.ways, into.attic_ways);
1457179273 q filter_attic_elements(rman, rman.get_desired_timestamp(), into.relations, into.attic_relations);
1458179273 q }
14602630162 q transfer_output(rman, into);
14612630162 q rman.health_check(*this);
1465Recurse_Statement::~Recurse_Statement()
14671007205 q for (std::vector< Query_Constraint* >::const_iterator it = constraints.begin();
14681181205 q it != constraints.end(); ++it)
146917455 q delete *it;
1473Query_Constraint* Recurse_Statement::get_query_constraint()
147517455 q constraints.push_back(new Recurse_Constraint(*this));
147617455 q return constraints.back();