Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce osm_nodes annotations for 64-bit OSM Node Ids #6341

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

SiarheiFedartsou
Copy link
Member

@SiarheiFedartsou SiarheiFedartsou commented Aug 27, 2022

Issue

potentially closes #5970 and #5716

The question here is how to preserve backward compatibility, that's why I want to discuss this before doing final "polishing".

What I am doing at the moment I add additional field osm_nodes which in some cases may be returned along with old nodes field which is kind of ugly and wasteful(but we cannot just remove this old nodes without breaking backward compatibility). Another option would be to add parameter(e.g. use_64bit_node_ids=true) and start returning node ids as strings in this case.

Also worth noting that JSON itself seems to support 64-bit numbers and we could just fix our JSON serialization to not convert numbers to double before serialization, but JS itself safely supports only integers up to 53-bit(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/MAX_SAFE_INTEGER) and

Tasklist

Requirements / Relations

Link any requirements here. Other pull requests this PR is based on?

util::json::Array osm_nodes;
osm_nodes.values.emplace_back(std::to_string(node_values.first));
osm_nodes.values.emplace_back(std::to_string(node_values.second));
waypoint.values["osm_nodes"] = std::move(osm_nodes);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the nearest API we unconditionally add this new osm_nodes array, i.e. always have kind of duplication.

nodes.values.reserve(leg_geometry.node_ids.size());
for (const auto node_id : leg_geometry.node_ids)
{
nodes.values.push_back(
static_cast<std::uint64_t>(facade.GetOSMNodeIDOfNode(node_id)));
const auto osm_node_id =
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case of annotations we add this osm_nodes if it was explicitly requested(annotations=osm_nodes,...) or in case of annotations=true

@@ -10,6 +10,8 @@ table Annotation {
duration: [uint];
datasources: [uint];
nodes: [uint];
osm_nodes: [ulong];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flatbuffers implementation is not ready yet, but general idea will be the same

@SiarheiFedartsou
Copy link
Member Author

@mjjbell would be great if you will take a look and share your opinion

@SiarheiFedartsou
Copy link
Member Author

SiarheiFedartsou commented Aug 27, 2022

On another hand as per this site the largest node id at the moment is only >2^33, i.e. we seems to be okay with 2^53 limitation of JS(that's the probably main reason why we would need to migrate to string from number). I.e. we can probably only make fix in flatbuffers.

But on another hand I personally know the cases when companies enrich OSM data with their own data and in order to avoid conflicts they start their IDs "from the end"(i.e. 2^64 - 1 goes first).

@SiarheiFedartsou
Copy link
Member Author

Another option I see is to explicitly enable/disable this via CLI parameter/config(and have it disabled by default).

@SiarheiFedartsou
Copy link
Member Author

OSM Node IDs are 34-bit internally

using PackedOSMIDs = util::detail::PackedVector<OSMNodeID, 34, Ownership>;

Related issue #5644

@mjjbell
Copy link
Member

mjjbell commented Aug 28, 2022

Let me summarise to see if I understand.

  • OSM Node IDs are currently < 2^34

  • JSON Numbers have precision up to 2^53, so our JSON API will be fine for a while / forever.

  • Our Flatbuffers API is using uint for nodes and is therefore already overflowing. A breaking change is required to fix.

  • Some people hack OSM IDs that are larger than JSON number precision can support. They would like to be able to return node IDs as strings.

Is this right?

@SiarheiFedartsou
Copy link
Member Author

SiarheiFedartsou commented Aug 28, 2022

Let me summarise to see if I understand.

  • OSM Node IDs are currently < 2^34
  • JSON Numbers have precision up to 2^53, so our JSON API will be fine for a while / forever.
  • Our Flatbuffers API is using uint for nodes and is therefore already overflowing. A breaking change is required to fix.
  • Some people hack OSM IDs that are larger than JSON number precision can support. They would like to be able to return node IDs as strings.

Is this right?

Exactly. At the same time for some reason initially I was thinking that OSM ids are already > 2^53, now it turned out that the problem is not so serious - after all those people can start from 2^53 - 1, but not from 2^64-1. But when it comes to Flatbuffers I think we need to fix that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

flatbuffers nodes subsection of annotations have inappropriate format
2 participants