Looking at the screenshot below we see that a User can participate in one or more rounds, and a round can (will) have many Users, and both will link to many EvaluationEvents. A EvaluationEvents must link to both User and Round.
I want to query all the EvaluationEvents and ConceptItems for a single User and single Round. I don’t know how to use both input parameters in a single select (I think this would be preferred), so I made a failed attempt to create two SELECTs and use an INTERSECT. Below shows working code for the two selects and I remmed code used for the intersect.
- What’s better, use both param in a single SELECT
Or
- Two SELECTs and in INTERSECT
Which every you choose, can you kindly please show me how?
CREATE QUERY GetUserRndEvals(vertex<User> usr, vertex<Round> rnd) FOR GRAPH MyGraph syntax v2 {
ListAccum<edge>@@edgeEvents;
#ListAccum<vertex>@@vertEvents;
#ListAccum<vertex>@@intersectEvents;
startUser = {usr};
startRound = {rnd};
Items = Select tItm FROM startUser:s-(User2EvaluationEvent>:eUserEvent)-EvaluationEvent:tEvent-(EvaluationEvent2ConceptItem>:eEvItm)-ConceptItem:tItm
ACCUM @@edgeEvents += eEvItm; #, @@vertEvents+=tEvent;
#2nd SELECT for the intersect
Events = SELECT tEvent FROM startRound:s-(Round2EvaluationEvent>:eRndEvent)-EvaluationEvent:tEvent;
#@@intersectEvents = Events INTERSECT @@vertEvents;
Print Items;
Print @@edgeEvents;
#Print @@vertEvents;
}
Thank You!
There are a few ways of doing this. The most intuitive way is to first get the EvaluationEvent you want, then go on from there. There isn’t a way I can think of to do this in a single path, and we can’t match on an intermediate set (though there is a lot of thinking going on for this as I believe Neo can do this, and we aim to please) .
Anyway, here’s my first thinking. I haven’t tested it so apologies if it has any mistakes, hopefully it will still make sense.
Note the need for a reverse edge between Round2EvaluationEvent, given you have defined it as directed according to the diagram above.
startUser={usr};
myTE = select tEvent from startUser -(User2EvaluationEvent>)-EvaluationEvent:tEvent;
myTE = select tEvent from EvaluationEvent:tEvent-(rev_Round2EvaluationEvent>)-Round:r
WHERE r == rnd; // filter on parameter
// Now you've got the filtered EvaluationEvent
Items = Select tItm FROM myTE:tEvent-(EvaluationEvent2ConceptItem:eEvItm>)-ConceptItem:tItm
ACCUM @@edgeEvents += eEvItm; #, @@vertEvents+=tEvent;
Hi Richard,
Thank you. This will probably take a few more iterations since you don’t have access to the graph.
-
How did you know it was a directed edge? I changed it to a reverse edge and it still has the same appearance.
-
Was this an oversight? “myTE” is not used in the 2nd SELECT and is overwritten in the 2nd SELECT?
-
And this is the compile error shown in the screenshot above:
(10, 72) Error: no viable alternative at input ‘myTE:tEvent-(EvaluationEvent2ConceptItem:eEvItm>’
(10, 86) Error: mismatched input ‘:’ expecting {INTERSECT, MINUS, UNION, ‘%’, ‘&’, ‘+’, ‘-’, ‘*’, ‘/’, ‘.’, ‘;’, ‘>’, ‘|’, ‘<<’}
- And the is the 2nd of 2 compile errors (neither of which make sense to me):
(6, 21) Error: unsatisfiable FROM pattern, query result always empty
(6, 48) Warning: unsatisfiable pattern -(Round2EvaluationEvent>)-Round:r
(6, 48) Warning: unsatisfiable pattern -(Round2EvaluationEvent>)-Round:r
(6, 26) Warning: unsatisfiable pattern EvaluationEvent:tEvent-(Round2EvaluationEvent>)-Round:r
Do you have further recommendations?
Thanks again.
OK that makes more sense to me, which brings us to this screenshot:
(9, 21) Error: unsatisfiable FROM pattern, query result always empty
(9, 37) Warning: unsatisfiable pattern -(Round2EvaluationEvent>)-Round:r
(9, 37) Warning: unsatisfiable pattern -(Round2EvaluationEvent>)-Round:r
(9, 26) Warning: unsatisfiable pattern myTE:tEvent-(Round2EvaluationEvent>)-Round:r
Shouldn’t that be a reverse edge? I’m guessing (reverse_Round2EvaluationEvent>) maybe?
myTE:tEvent-(reverse_Round2EvaluationEvent>)-Round:r
You have been using some prefixes such as “reverse_”. Is that an actual prefix recognized by TG, or is it more like a comment to let me know what edge type it should be?
So there are a bunch of concepts here. Firstly, I recommend you go through the 101 training if you haven’t already: https://www.tigergraph.com/certification-gsql-101/
Directed edges can be defined in the schema to have both the forward and reverse edges. If you use graph studio then you can simply tick a checkbox to get the reverse edge. By convention, graph studio names the reverse edge by prefixing the edge name with “reverse_”.
If you define the schema explicitly (on the command line) then you can name the reverse edge anything you like.
When traversing the path, if you are going backwards along a directed edge then you explicitly need a reverse edge. If you don’t, then the code parser will usually spot the error as you have seen.
You gave the screenshot, which had the relevant clues:
Note here the reverse edge is explicitly named, and that’s the one you need in your code to get from EvaluationEvent back to Round. OK?
OK Thank you and I think we’re getting close. Hopefully this is the last error (everything looks good to me):
(14, 53) Error: no viable alternative at input ‘myTE:tEvent-(EvaluationEvent2ConceptItem:eEvItm>’
(14, 67) Error: mismatched input ‘:’ expecting {INTERSECT, MINUS, UNION, ‘%’, ‘&’, ‘+’, ‘-’, ‘*’, ‘/’, ‘.’, ‘;’, ‘>’, ‘|’, ‘<<’}
and this is the edge used in the last “From” clause:
No need for a reverse edge here right? as an EvaluationEven “has” ConceptItems.
and here’s the query text:
CREATE QUERY GetUserRndEvals3(vertex usr, vertex rnd) FOR GRAPH MyGraph syntax v2 {
startUser={usr};
myTE = Select tEvent From startUser -(User2EvaluationEvent>)-EvaluationEvent:tEvent;
myTE =
Select tEvent from myTE:tEvent-(reverse_Round2EvaluationEvent>)-Round:r
Where r == rnd; // filter on parameter
// Now you’ve got the filtered EvaluationEvent
Items =
Select tItm
From myTE:tEvent-(EvaluationEvent2ConceptItem:eEvItm>)-ConceptItem:tItm
Accum @@edgeEvents += eEvItm;
Print myTE;
Print Items;
Print @@edgeEvents;
}
Thank you.
I think you’ve just got the right caret in the wrong place, it needs to be before the colon:
(EvaluationEvent2ConceptItem>:eEvItm)
That was it. Thank you for staying with this and it’s now making sense to me.