Help with SQL query

26 views
Skip to first unread message

Erik T

unread,
Jun 19, 2017, 9:15:01 AM6/19/17
to OrientDB
I have a tree with 5 vertices

                                     Folder (a)
                                     /        \
                              (b) File      Folder (c)
                                                /       \
                                         (d) File     Folder (e)

I would like to retrieve the folders that contain a file. So I want to get back (a) and (c) from my query. The edges are lightweight edges and are labeled 'scopeEdge'. I placed a property on the files in my tree and labeled them 'file'. These queries don't work

select out from V where file is not null --> gives back temporary vertices

select from V where out('scopeEdge').file is not null --> gives back (a), (b), (c), (d), and (e)

I can get 1 query to work but its really complicated. It makes me think I'm doing something wrong. Is there something easier than this?

SELECT FROM (TRAVERSE in('scopedEdge') FROM (SELECT FROM #RID# WHERE file IS NOT NULL)) WHERE $depth > 0 --> gives back (a) and (c)


Luigi Dell'Aquila

unread,
Jun 19, 2017, 9:26:13 AM6/19/17
to orient-...@googlegroups.com
Hi Erik,

I'm afraid I don't completely understand your model:
- how are the edges directed? From parent to child or from child to parent?
- are File and Folder two different classes that extend V?
- what does the "file" property represent? Is it a string or what?


If I got it right, you have many alternatives to do this, one is as follows:

TRAVERSE in('scopedEdge') FROM (
  SELECT expand(in('scopeEdge')
) FROM V WHERE file IS NOT NULL

or

SELECT FROM V 
WHERE out("scopedEdge").size() > 0

or

MATCH
 {class:File, where:(file is not null)} <-scopedEdge- {} <-scopedEdge- {as:folder, while:(true)}
RETURN $elements

I hope it helps

Thanks

Luigi


--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-database+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luigi Dell'Aquila

unread,
Jun 19, 2017, 9:26:48 AM6/19/17
to orient-...@googlegroups.com
Sorry, the first query is

TRAVERSE in('scopedEdge') FROM (
  SELECT expand(in('scopeEdge'))
  FROM V WHERE file IS NOT NULL
)

Erik T

unread,
Jun 19, 2017, 9:33:00 AM6/19/17
to OrientDB
Hi Luigi,

The edges go from parent to child so the 'scopeEdge' comes out of (a) and goes in to (b). File and folder are not separate classes. 
They are both a plain vertex.
The file property is a boolean value. I was thinking the existence of the property could indicate it is a file.

I'll try your suggestions now.
Reply all
Reply to author
Forward
0 new messages