-
Notifications
You must be signed in to change notification settings - Fork 870
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
[SQL/Match Question] Get node count between + edge data in a single query - "optimize" ? #8915
Comments
Hi @matanshukry You can try the following:
I didn't test it, so there is a chance that it has typos, but I hope you got the idea Thanks Luigi |
sorry, here's the right query
Thanks Luigi |
@luigidellaquila Awesome! I really liked the way you did it, great! One question though: why do we need the SELECT and the GROUP BY? the match it self seems to return the same data (with very little edit of a field in the RETURN)
|
Yes, it should work (just add a GROUP BY). Thanks LUigi |
@luigidellaquila - that's the thing I don't understand - why do we need to add a GROUP BY? the match I wrote is meant to be used alone, without a select at all. There should only be one friend anyway, due to how the match was written.. no? Also, I noticed after we find the target person, |
The GROUP BY is needed just because you have an aggregation function ( About the Thanks Luigi |
@luigidellaquila How come it works without the GROUP BY then? I ran the Match only and it returned the correct result, without the select/group by.. Regarding status=2: the value 2 is coming as a parameter actually. Is there anyway to avoid using it 3 times? (in each where) |
Hi @matanshukry The execution planner is smart enough to add the GROUP BY automatically in some cases, but I always suggest to set it explicitly to make the query more clear. You can pass named parameters to the query as
Thanks Luigi |
@luigidellaquila Awesome, that solves all my problems and questions and then some! Thanks :) |
@luigidellaquila Spoke a bit too soon; |
Hi @matanshukry You can add an
Thanks Luigi |
well, actually you can write it as follows, that is much better:
(see the Thanks Luigi |
@luigidellaquila The
p.s. Either way it works, so I'm closing it. |
@luigidellaquila I'm now looking for something a bit different, but still the same subject. I'll just reopen this then. Let me know if you prefer and I'll open a new issue. This is my current query:
The general query requirements are:
But/points from previous query:
Method 2I thought about doing this using 2 sub-queries, but not sure how to 'expand' them outside (expand doesn't work):
The query will return something like this:
|
@luigidellaquila / others - Athoughts? is that simply not implemented yet? I'm willing to help if needed/possible.. |
Hi @matanshukry I'd like to do a couple of tests with the queries, any chance to have a sample DB? Thanks Luigi |
@luigidellaquila Actually no; I just don't have one. I'm creating a few records at a time and playing with them. I made this up for you though, hopefully it will help:
I'm really waiting for this issue,, so please keep me informed, either here or though email. |
Hi @matanshukry I think I found the reason for the UnsupportedOperationException, I fixed it and I'm running the tests. With the fix, the following works fine:
But it only returns results that have mutual friends. Unfortunately, you cannot use
I'll keep you updated as soon as the fix is on the snapshot Thanks Luigi |
Ok, I pushed the fix, please let me know if you need further help Thanks Luigi |
@luigidellaquila Awesome, that does work as I've wanted! I have another question regarding the issue, also regarding performance:
|
@luigidellaquila Also, I'm having some troubles tweaking the query a little;
$a: 'friend' and 'mutualFriends' (if mutualFriends = 0, friend is null) How do I merge them though, so I'll get it all in a single line? |
OrientDB Version: 3.0.20
Java Version: 1.8.0_191
OS: Windows 10
Assuming I have this model:
I need to create a query that will find all
Person
that will match 'John' (Lucene full text), and will return (a) the friend data between them and person 'Bar', and (b) The amount of friends that person and 'Bar' has in common.The current query I have is:
Which technically is working, but:
(1) It looks like a really bad query, performance-wise. I have to repeat few things in each sub-query (such as SEARCH_CLASS). Anyway to avoid that?
(2) The result contains 2 columns, 'friend' and 'count', but in each of them I have an array, and in the count I even have a nested json with 'cnt'. Is there a way to avoid all that, so that in the first column/cell I will simply have the json data of 'friend', and in the second I will simply have an integer - the count?
The text was updated successfully, but these errors were encountered: