{"action":"created","issue":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/8480","repository_url":"https://api.github.com/repos/orientechnologies/orientdb","labels_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/8480/labels{/name}","comments_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/8480/comments","events_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/8480/events","html_url":"https://github.com/orientechnologies/orientdb/issues/8480","id":353446241,"node_id":"MDU6SXNzdWUzNTM0NDYyNDE=","number":8480,"title":"Accessing node siblings (rightmost/leftmost cousin node) in trees stored in orientdb.","user":{"login":"karlitos","id":3693437,"node_id":"MDQ6VXNlcjM2OTM0Mzc=","avatar_url":"https://avatars0.githubusercontent.com/u/3693437?v=4","gravatar_id":"","url":"https://api.github.com/users/karlitos","html_url":"https://github.com/karlitos","followers_url":"https://api.github.com/users/karlitos/followers","following_url":"https://api.github.com/users/karlitos/following{/other_user}","gists_url":"https://api.github.com/users/karlitos/gists{/gist_id}","starred_url":"https://api.github.com/users/karlitos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karlitos/subscriptions","organizations_url":"https://api.github.com/users/karlitos/orgs","repos_url":"https://api.github.com/users/karlitos/repos","events_url":"https://api.github.com/users/karlitos/events{/privacy}","received_events_url":"https://api.github.com/users/karlitos/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-23T15:55:01Z","updated_at":"2018-08-24T06:35:49Z","closed_at":null,"author_association":"NONE","body":"### OrientDB Version: v3.0.6 \r\n### OS: MacOS\r\n\r\nHello,\r\n\r\nI search for an possibility to store and more importantly, manage trees - Directed, acyclic, graphs - and __orientdb__ seems to be very promising solution. It is Important to me to have an (instant) access to nodes __next__ siblings.\r\n\r\ne.g.\r\n\r\n```\r\n    A\r\n  /   \\\r\n B     C\r\n/  \\  / \\\r\nD  E F  G\r\n```\r\nI would like to efficiently access F directly from E. The access among the direct siblings (D, E / F, G) can be done via 'ordered edges' .\r\n\r\nI was thinking about two solutions:\r\n\r\n1. _custom edges_ connecting two siblings, positioned next to each other which dies not have an direct common ancestor (E -cousin- G). But considering scenarios, where whole sub-trees could be repositioned just by changing the an edge between two nodes ... the complexity of re-establishing those \"cousin links\" would be probably huge.\r\n\r\n2. efficient computing. Was already discussed [here](rightmost/leftmost cousin node in a d3 tree). Basically: efficient computing is possible, as long as the nodes depth (distance from root) is known.\r\n\r\nIs there a way in which every node automatically tracks its' distance to the \"root\" ? What will be the most effective way of doing this ? Running _shortestPath_ between the Root and a given node and considering only outgoing edges _has_parent_\r\n"},"comment":{"url":"https://api.github.com/repos/orientechnologies/orientdb/issues/comments/415665782","html_url":"https://github.com/orientechnologies/orientdb/issues/8480#issuecomment-415665782","issue_url":"https://api.github.com/repos/orientechnologies/orientdb/issues/8480","id":415665782,"node_id":"MDEyOklzc3VlQ29tbWVudDQxNTY2NTc4Mg==","user":{"login":"luigidellaquila","id":459289,"node_id":"MDQ6VXNlcjQ1OTI4OQ==","avatar_url":"https://avatars0.githubusercontent.com/u/459289?v=4","gravatar_id":"","url":"https://api.github.com/users/luigidellaquila","html_url":"https://github.com/luigidellaquila","followers_url":"https://api.github.com/users/luigidellaquila/followers","following_url":"https://api.github.com/users/luigidellaquila/following{/other_user}","gists_url":"https://api.github.com/users/luigidellaquila/gists{/gist_id}","starred_url":"https://api.github.com/users/luigidellaquila/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/luigidellaquila/subscriptions","organizations_url":"https://api.github.com/users/luigidellaquila/orgs","repos_url":"https://api.github.com/users/luigidellaquila/repos","events_url":"https://api.github.com/users/luigidellaquila/events{/privacy}","received_events_url":"https://api.github.com/users/luigidellaquila/received_events","type":"User","site_admin":false},"created_at":"2018-08-24T06:35:49Z","updated_at":"2018-08-24T06:35:49Z","author_association":"MEMBER","body":"Hi @karlitos \r\n\r\nin the hypothesis that the edges are connected bottom-up, eg. `D --> B --> A`, you can calculate the depth as follows:\r\n\r\n```\r\nSELECT max($depth) as theNodeDepth FROM (\r\n  TRAVERSE out(\"EdgeClassName\") FROM (\r\n    SELECT FROM VertexClass WHERE name = 'D'\r\n  )\r\n)\r\n```\r\n\r\nThen you can use that value to find siblings:\r\n\r\n```\r\nSELECT FROM (\r\n  TRAVERSE in(\"EdgeClassName\") FROM <the root>\r\n) \r\nLET $theSiblingsDepth = (<the query for the max depth>)\r\nWHERE $depth = $theSiblingsDepth[0].theNodeDepth\r\n```\r\n\r\nI didn't try the query, so there is a slight chance that it has some small syntax errors, but in principle it should work fine\r\n\r\nThanks\r\n\r\nLuigi"}}
{"actor":{"display_login":"luigidellaquila"}}