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

Selecting all vertices connected by and edge to another specific list of vertices #5608

Closed
shyamchandranmec opened this issue Jan 19, 2016 · 14 comments
Assignees
Labels

Comments

@shyamchandranmec
Copy link

select expand( in('BELONGS_TO') ) from
(select expand(out('follows')) from User where @Rid = #13:0 )

This query returns posts from all pages followed by a user
User ->(follows)->Page
Post->(belongs_to)Page

each post falls-into a category as well

I need to filter the same output based on multiple categories.
something like this

select expand( in('BELONGS_TO') AND OUT("FALLS_INTO") in ["#32:0","#32:1] ) from
(select expand(out('follows')) from User where @Rid = #13:0 )

@shyamchandranmec shyamchandranmec changed the title Selecting all vertices connected by and edge to another specific list of vertex Selecting all vertices connected by and edge to another specific list of vertices Jan 19, 2016
@luigidellaquila
Copy link
Member

Hi @shyamchandranmec

just to understand, is the OUT_FALLS_INTO an attribute of the Page?

Thanks

Luigi

@shyamchandranmec
Copy link
Author

@luigidellaquila nope.. "FALLS_INTO" is an edge pointing out from the Post to the Category class. 32:0 and 32:1 are the id's of 2 Category vertices

@shyamchandranmec
Copy link
Author

@luigidellaquila I have edited the comment and changed it to out("falls_into")

@luigidellaquila luigidellaquila self-assigned this Jan 21, 2016
@luigidellaquila
Copy link
Member

Hi @shyamchandranmec

I think the right query should be something like:


select expand(out('BELONGS_TO')) 
from (
    select expand(out('follows')) from User where @rid = #13:0 
) WHERE
OUT("FALLS_INTO") in [#32:0, #32:1] 

Thanks

Luigi

@shyamchandranmec
Copy link
Author

@luigidellaquila

Thanks ... I will try it out

@shyamchandranmec
Copy link
Author

@luigidellaquila
I tried this. This is giving zero results... Then I tried it with 'NOT IN' [#32:0] instead of 'IN', then it was displaying the item which had an 'OUT' relationship to #32:0..

Any idea why its acting weird..

@luigidellaquila
Copy link
Member

Hi @shyamchandranmec

I don't know, just consider that I changed in('BELONGS_TO') into out('BELONGS_TO') because it makes sense based on your domain...

If you can share a simple dataset I'll try it and I'll try to give you some more info

Thanks

Luigi

@shyamchandranmec
Copy link
Author

@luigidellaquila I changed the out('BELONGS_TO') to in('BELONGS_TO')..

How should I give the dataset? Should I give you the db dump?

@luigidellaquila
Copy link
Member

Hi @shyamchandranmec

yes, a db dump would be perfect

Thanks

Luigi

@shyamchandranmec
Copy link
Author

Hi @luigidellaquila
I have attached the file.

@luigidellaquila
Copy link
Member

Hi @shyamchandranmec

I think the query you are looking for is the following:

select from (
    select expand(out('follows').in('BELONGS_TO')) from User where @rid = #13:0 
) WHERE OUT("FALLS_INTO") in [#24:1, #32:1] 

(probably you have different cluster IDs, because of the import/export)

Thanks

Luigi

@shyamchandranmec
Copy link
Author

Hi @luigidellaquila

This works. Thanks... I confused the edge id and the vertex id shown in the orientdb studio. I was using wrong ids in the queries which I tried. Now it works but I have a one more question.. Its returning 3 rows with same data... There are duplicate rows in the result.. Any idea why?

@luigidellaquila
Copy link
Member

Hi @shyamchandranmec

probably you have multiple paths between the user and the post. You can change your query this way to avoid duplicates:

select from (
    select expand(out('follows').in('BELONGS_TO').asSet()) from User where @rid = #13:0 
) WHERE OUT("FALLS_INTO") in [#24:1, #32:1]

I'm closing this issue, please reopen in case you have any other problems.

Thanks

Luigi

@shyamchandranmec
Copy link
Author

@luigidellaquila

Thanks for the help

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

No branches or pull requests

2 participants