A Graph Query question

244 views
Skip to first unread message

Brett Coffin

unread,
May 22, 2015, 10:17:19 PM5/22/15
to orient-...@googlegroups.com

I am building a chat room engine and I have a graph like so:

User---Started--->Room----Discuss--->Item<---Own---User

I would like to get all the Items and the roomId associated to the Item for a particular User.

select 
    *, in('Discuss').in('Started')[name ='julie'] as roomId
    from item

so this is going threw the right 'Room' and finds the one started by 'Julie' but it returns Julie's Id, how do I get with this query the Id of that room ? It's like i need to do a 'one back' and get @rid...

I am new to graphs so any pointers would be appreciated.

Brett Coffin

unread,
May 24, 2015, 7:17:22 PM5/24/15
to orient-...@googlegroups.com
Is this possible with OrientDB ?

Wes Arnquist

unread,
May 25, 2015, 5:00:14 AM5/25/15
to orient-...@googlegroups.com
Hi there, I'm also new and don't know if this will work, and I can't test it from where I am right now, but maybe you can try adding this after the ]
.out('Started')
Have you tried something like this? I'm sure there is a way to do what you're trying to do.

alessand...@gmail.com

unread,
May 25, 2015, 10:32:41 AM5/25/15
to orient-...@googlegroups.com
Hi Brett,
try this SQLquery select name,in('Discuss').roomId from (select expand(out('Started').out('Discuss')) from User where name = 'julie')

Bye, Alessandro

Luca Garulli

unread,
May 25, 2015, 1:36:57 PM5/25/15
to orient-...@googlegroups.com
Hi guys,
We helped on building a high-volume chat application by modeling the metadata about who started/discuss, but then using the document API with no index to have super fast access to last X messages. In facts, OrientDB stores new records in append only, and the @rid is auto generated as incrementing. So if you just create the message in the chat with

ODocument msg = new ODocument("Message");
msg.field( "date", new Date() );
msg.field( "text", iText );
...
msg.save();

Then you can retrieve last 50 messages with:

select from Message order by @rid desc skip 0 limit 50

To load the 2nd (last) page:

select from Message order by @rid desc skip 50 limit 50

This is super fast and O(1) even with million of messages.


Best Regards,

Luca Garulli
CEO at Orient Technologies LTD
the Company behind OrientDB


--

---
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-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luca Garulli

unread,
May 25, 2015, 1:58:49 PM5/25/15
to orient-...@googlegroups.com

Best Regards,

Luca Garulli
CEO at Orient Technologies LTD
the Company behind OrientDB


Brett Coffin

unread,
May 26, 2015, 5:13:13 AM5/26/15
to orient-...@googlegroups.com
@Wes Arnquist Thanks for the feed back, 

select
   
*, in('Discuss').in('Started')[name ='julie'].out('Started') as roomId
from item

I did try this, but it's giving me all the Room's @rid... it's not taking into consideration the prior-filter. 

Brett Coffin

unread,
May 26, 2015, 5:46:16 AM5/26/15
to orient-...@googlegroups.com
@alessand...@gmail.com Thanks for the feedback

select *, in('Discuss').@rid as roomId from (select expand(out('Started').out('Discuss')) from User where name = 'julie')

I tried it but it's not working out for me, first it's returning only the Items where Julie has started a room and it's not giving me the id of the room its giving back all the roomId for that item, but I really like the use of the expand in this context and I definitely learned something from this example, thanks.

Brett Coffin

unread,
May 26, 2015, 5:54:59 AM5/26/15
to orient-...@googlegroups.com
@l.garulli Thanks for the feedback

I will revise the model on you recommendations.
My problem with this query is not solved, I need all the Items and the roomId in which the current user started it, can I do a unionall of 2 separate queries to solve this ? 

Brett Coffin

unread,
May 26, 2015, 6:05:49 AM5/26/15
to orient-...@googlegroups.com
This is not working but will we have this kind of query working in the future ?
select *, in('Discuss')[in('Started')[name='julie']].@rid as roomId from Item

I remember reading something about supporting the full query syntax in the filter fields but I can't find it anymore...

Ziink A

unread,
May 26, 2015, 11:09:59 AM5/26/15
to orient-...@googlegroups.com
Based on a comment from Alessandro within the last few days, there's some issue with filter part of the query (highlighted below) which should eventually get fixed. That's what might be causing this query to fail.


select 
    
*, in('Discuss').in('Started')[name ='julie'].out('Started') as roomId
from item


Brett Coffin

unread,
May 27, 2015, 6:31:31 PM5/27/15
to orient-...@googlegroups.com
Thanks @Ziink A,

I have added an issue: 4225, as I would like to know for certain that this is the expected behaviour.
Does anyone know where is the issue/link where they discuss the full syntax in the filter fields ?
In the mean time doesn't anyone has a work around for my query ?

Thanks for your time, and happy Odb dev ! 

neRok

unread,
May 27, 2015, 7:36:54 PM5/27/15
to orient-...@googlegroups.com
It looks like the expected behavior to me. From Item vertex, you have gone to Room vertex, and then to User vertex and filtered for only the users whos name is Julie. So it is returning User vertex for Julie.

You probably want something like the following (not tested for correct syntax, just my thoughts);
select 
    
*, in('Discuss')[in_Started.in.name ='julie'] as roomId
from item
So this gets all the Room vertex, and then filters them.

Brett Coffin

unread,
May 28, 2015, 3:26:35 AM5/28/15
to orient-...@googlegroups.com
Thanks, neRok

It would be great if that worked... 
select
   
in('Discuss').in_Started.out.name as roomId
from item
return : [["julie"]]

but 
select
   
in('Discuss')[in_Started.out.name[0][0] = 'julie'] as roomId
from item

select
   
in('Discuss')[in_Started.out.name = 'julie'] as roomId
from item
And every combination that I could think of did not return anything...


alessand...@gmail.com

unread,
May 28, 2015, 3:50:52 AM5/28/15
to orient-...@googlegroups.com

Hi Brett,
I created this graph.

and when I run the query I get these results.

I hope it can hepl you.

Bye, Alessandro



Il giorno sabato 23 maggio 2015 04:17:19 UTC+2, Brett Coffin ha scritto:

Brett Coffin

unread,
May 28, 2015, 6:49:54 AM5/28/15
to orient-...@googlegroups.com



Thanks for your help alessand...@gmail.com but I am still struggling for the solution... The issues with your proposal is:

1. I get the roomIds for Item 13:54 of marc and julie.

2. I would like to get all the Items not only the ones that have a room starter by julie

Context:

This is the Initial loading data of a product selling site, I need to load all the items and I would like to have the roomId for the item where the user logged-in has 'started' a room.  

here is a link to a StackOverflow for the same issue... query-on-orientdb-graph



alessand...@gmail.com

unread,
May 28, 2015, 10:08:32 AM5/28/15
to orient-...@googlegroups.com

Hi Brett,

if I understand the problem, try this query

select name , in('Discuss').in('Started').out('Started')[roomId]  from Item


Bye, Alessandro




Il giorno sabato 23 maggio 2015 04:17:19 UTC+2, Brett Coffin ha scritto:

neRok

unread,
May 28, 2015, 10:42:53 PM5/28/15
to orient-...@googlegroups.com
I have posted the answer to your StackOverflow question.

neRok

unread,
May 28, 2015, 11:09:53 PM5/28/15
to orient-...@googlegroups.com
Me again. I've been thinking about it some more, and whilst the query I provided works, the performance is probably going to be terrible. Presuming rooms only belong to items, you will effectively be asking the database to load every Item, then every Room, and then a large portion of Users (as it needs to check their name) every time you do this 1 query. That is a lot.

If this is a web app, the best way might be to do 1 query for items, 1 query for the rooms started by the user, then use javascript to add the rooms to each item.

Brett Coffin

unread,
May 29, 2015, 1:35:09 AM5/29/15
to orient-...@googlegroups.com
Yes its a web app angular 1.4 ES6 NodeJs Orientdb. Thank for the advice, I am using the user @rid for ref the name was for the example.
I would rather change my graph as I am in the process of modeling it, Maybe add the Starter ID to the Discuss link ? what do you think ? 
Reply all
Reply to author
Forward
0 new messages