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

Deep Traversal doesnt seem to work in orientdb v3.0.4 #8490

Closed
surajhes opened this issue Aug 28, 2018 · 5 comments
Closed

Deep Traversal doesnt seem to work in orientdb v3.0.4 #8490

surajhes opened this issue Aug 28, 2018 · 5 comments

Comments

@surajhes
Copy link

OrientDB Version: 3.0.4

Java Version: 1.8.0_171

OS: windows 7 x64

Expected behavior

1->1.1
1->1.2
2->2.1
2->2.2
2->2.3

when traversing from 1.x or 2.x till depth < 2, i expect
1.1,1
1.2,1
2.1,2
2.2,2
2.3,2

Actual behavior

1.1,1
1.2
2.1,2
2.2,
2.3

Steps to reproduce

create a graph above and perform traverse from leaf nodes to depth < 2

@markodjurovic
Copy link
Contributor

markodjurovic commented Aug 30, 2018

Hi @surajhes
I've created graph with following commands:
create class tc extends V
create vertex tc set name = 1
create vertex tc set name = 1.1
create vertex tc set name = 1.2
create vertex tc set name = 2
create vertex tc set name = 2.1
create vertex tc set name = 2.2
create class te extends E
create edge te from #241:0 to #242:0
create edge te from #241:0 to #243:0
create edge te from #244:0 to #245:0
create edge te from #244:0 to #246:0

Vertices #241:0, #242:0, #243:0, #244:0, #245:0, #246:0 represents vertices with name 1, 1.1, 1.2, 2, 2.1, 2.2, 2.3 respectively.

And when I execute traversal with max depth 2, result is like following:

orientdb {db=demodb}> TRAVERSE out("te") FROM #241:0 MAXDEPTH 2

+----+------+------+---------------+----+--------+
|#   |@RID  |@CLASS|out_te         |name|in_te   |
+----+------+------+---------------+----+--------+
|0   |#241:0|tc    |[#249:0,#250:0]|1   |        |
|1   |#243:0|tc    |               |1.2 |[#250:0]|
|2   |#242:0|tc    |               |1.1 |[#249:0]|
+----+------+------+---------------+----+--------+

3 item(s) found. Traverse executed in 0.009 sec(s).

Is that what you have on your mind?

@smolinari
Copy link
Contributor

Following.

Scott

@surajhes
Copy link
Author

I would had expected like
Note: i am editing the table here posted above.
+----+------+------+---------------+----+--------+
|# |@Rid |@Class|out_te |name|in_te |
+----+------+------+---------------+----+--------+
|0 |#241:0|tc |[#249:0,#250:0]|1 | |
|1 |#243:0|tc | |1.2 |[#250:0]|
|0 |#241:0|tc |[#249:0,#250:0]|1
|2 |#242:0|tc | |1.1 |[#249:0]|
+----+------+------+---------------+----+--------+
something like that.

@smolinari
Copy link
Contributor

@markodjurovic

create a graph above and perform traverse from leaf nodes to depth < 2

Can the query be made from the leaf node, as suggested? Not sure that makes a difference or is possible, but maybe that would get the expected result?

Scott

@markodjurovic
Copy link
Contributor

markodjurovic commented Aug 31, 2018

@smolinari
It is possible to traverse from leafs (just in reverse direction):

orientdb {db=demodb}> traverse in("te") from (select rids from (select @rid as rids, out("te") as outEdge from tc unwind outEdge) where outEdge is null) maxdepth 2

+----+------+------+--------+----+---------------+
|#   |@RID  |@CLASS|in_te   |name|out_te         |
+----+------+------+--------+----+---------------+
|0   |#246:0|tc    |[#252:0]|2.2 |               |
|1   |#244:0|tc    |        |2   |[#251:0,#252:0]|
|2   |#245:0|tc    |[#251:0]|2.1 |               |
|3   |#243:0|tc    |[#250:0]|1.2 |               |
|4   |#241:0|tc    |        |1   |[#249:0,#250:0]|
|5   |#242:0|tc    |[#249:0]|1.1 |               |
+----+------+------+--------+----+---------------+

6 item(s) found. Traverse executed in 0.099 sec(s).

where


select rids from (select @rid as rids, out("te") as outEdge from tc unwind outEdge) where outEdge is null

finds leaf nodes.

But with MATCH you can go further:


orientdb {db=demodb}> match {class: tc, as: rec}.inE("te"){while: ($depth < 2), as: kk}.outV(){as: vv} return $matches

+----+------+------+------+
|#   |rec   |kk    |vv    |
+----+------+------+------+
|0   |#242:0|#249:0|#241:0|
|1   |#243:0|#250:0|#241:0|
|2   |#245:0|#251:0|#244:0|
|3   |#246:0|#252:0|#244:0|
+----+------+------+------+

4 item(s) found. Query executed in 0.003 sec(s).

or


orientdb {db=demodb}> match {class: tc, as: rec}.inE("te"){while: ($depth < 2), as: kk}.outV(){as: vv} return $elements

+----+------+------+--------+----+------+------+---------------+
|#   |@RID  |@CLASS|in_te   |name|out   |in    |out_te         |
+----+------+------+--------+----+------+------+---------------+
|0   |#242:0|tc    |[#249:0]|1.1 |      |      |               |
|1   |#249:0|te    |        |    |#241:0|#242:0|               |
|2   |#241:0|tc    |        |1   |      |      |[#249:0,#250:0]|
|3   |#243:0|tc    |[#250:0]|1.2 |      |      |               |
|4   |#250:0|te    |        |    |#241:0|#243:0|               |
|5   |#241:0|tc    |        |1   |      |      |[#249:0,#250:0]|
|6   |#245:0|tc    |[#251:0]|2.1 |      |      |               |
|7   |#251:0|te    |        |    |#244:0|#245:0|               |
|8   |#244:0|tc    |        |2   |      |      |[#251:0,#252:0]|
|9   |#246:0|tc    |[#252:0]|2.2 |      |      |               |
|10  |#252:0|te    |        |    |#244:0|#246:0|               |
|11  |#244:0|tc    |        |2   |      |      |[#251:0,#252:0]|
+----+------+------+--------+----+------+------+---------------+

12 item(s) found. Query executed in 0.005 sec(s).

These queries requires more sophisticated logic to detect if some node is leaf, so final query may looks like:

match {class: tc, as: rec, where: (@rid in (select rids from (select @rid as rids, out("te") as outEdge from tc unwind outEdge) where outEdge is null))}.inE("te"){while: ($depth < 2), as: kk}.outV(){as: vv} return $matches

and if you don't need info about edges connecting nodes:

orientdb {db=demodb}> match {class: tc, as: rec, where: (@rid in (select rids from (select @rid as rids, out("te") as outEdge from tc unwind outEdge) where outEdge is null))}.inE("te"){while: ($depth < 2)}.outV(){as: vv} return $matches

+----+------+------+
|#   |rec   |vv    |
+----+------+------+
|0   |#242:0|#241:0|
|1   |#243:0|#241:0|
|2   |#245:0|#244:0|
|3   |#246:0|#244:0|
+----+------+------+

4 item(s) found. Query executed in 0.008 sec(s).

or unrolled

orientdb {db=demodb}> match {class: tc, as: rec, where: (@rid in (select rids from (select @rid as rids, out("te") as outEdge from tc unwind outEdge) where outEdge is null))}.inE("te"){while: ($depth < 2)}.outV(){as: vv} return $elements

+----+------+------+--------+----+---------------+
|#   |@RID  |@CLASS|in_te   |name|out_te         |
+----+------+------+--------+----+---------------+
|0   |#242:0|tc    |[#249:0]|1.1 |               |
|1   |#241:0|tc    |        |1   |[#249:0,#250:0]|
|2   |#243:0|tc    |[#250:0]|1.2 |               |
|3   |#241:0|tc    |        |1   |[#249:0,#250:0]|
|4   |#245:0|tc    |[#251:0]|2.1 |               |
|5   |#244:0|tc    |        |2   |[#251:0,#252:0]|
|6   |#246:0|tc    |[#252:0]|2.2 |               |
|7   |#244:0|tc    |        |2   |[#251:0,#252:0]|
+----+------+------+--------+----+---------------+

8 item(s) found. Query executed in 0.008 sec(s).

More details on match can be found here

https://orientdb.com/docs/3.0.x/sql/SQL-Match.html

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

No branches or pull requests

3 participants