Trouble creating a query in GraphStudio

Hello everyone, I am trying to find the most common degree types for all users. The Education vertex is connected to the User vertex and degree is an attribute of Education. Any help would be greatly appreciated. This is the query:

CREATE QUERY Degree_types() FOR GRAPH Alumni {

SumAccum @degreeNum;
SetAccum<VERTEX> @degreeType;

start = {User.*};

Result = SELECT tgt
FROM start:s-(studied_at:e)->Education.degree:tgt
ACCUM
tgt.@degreeNum += 1,
tgt.@degreeType += tgt.degree
ORDER BY
tgt.@degreeNum DESC
LIMIT 5;

PRINT Result;
}

Hi @digitalpaddyo

to me Education.degree looks very wrong as vertex name.
You cannot traverse to attribute.
FROM start:s-(studied_at:e)->Education:tgt would be correct.

Bruno

Thank you Bruno, I fixed that but now I am getting the error:
“Incompatible operand types SetAccum<vertex> and string for the operator +=”
for tgt.@degreeType += tgt.degree

I am trying to find the most common degree types and the sum of occurrences for each degree type.
degree is an attribute of Education.

Does each User get their own Education vertex? Or is there just one Education vertex for each degree type, and multiple Users are connected to that same vertex? Since you haven’t clarified the schema, its hard to answer your question. But here are some suggestions. If there is only one Education vertex for each degree type which you are attempting find, then its pretty simple

CREATE QUERY Degree_types() FOR GRAPH Alumni {

SumAccum<INT> @degreeCount;

start = {User.*};
Result = SELECT tgt  FROM start:s-(studied_at:e)->Education:tgt
ACCUM tgt.@degreeCount += 1
ORDER BY
tgt.@degreeCount DESC
LIMIT 5;

PRINT Result;
}

There is no need to accumulate the degree type, since that is already an attribute of Education.

Now for the alternative: if the arrangement is that there can be multiple Education vertices with the same degree attribute, then you are probably better off using a global MapAccum like this:

CREATE QUERY Degree_types() FOR GRAPH Alumni {

MapAccum<STRING, INT> @@degreeCount;

start = {User.*};
Result = SELECT tgt FROM start:s-(studied_at:e)->Education:tgt
ACCUM  @@degreeCount += ( tgt.degree -> 1);

PRINT @@degreeCount;
}

Hello Mark, thank you very much. Sorry for not being more clear. Every User vertex is connected to an Education vertex. The primary id for Education is school and there is a degree attribute. Some users could have the same degree type, “Masters of computer science” for example. I would like to find the most common degree types and the number of occurrences.

okay, then use the second example. you can also consider using the SQL- like GROUP BY functionality that has been recently introduced by TigerGraph.

Like this

CREATE QUERY Degree_types()  FOR GRAPH Alumni SYNTAX v2 {
  
 SELECT tgt.degree, COUNT(*) as degreeCount INTO T 
   FROM User:s-(studied_at:e)->Education:tgt
  GROUP BY tgt.degree
  ORDER BY  degreeCount DESC
  LIMIT  5;

PRINT T;
}
2 Likes

That is great thanks but now for the GROUP BY function I am getting a “Mixed use of v1 and v2 syntax is not supported in pattern match query” for the User:s after the FROM.

Ah Right - change to: FROM User:s-(studied_at>:e)-Education:tgt

1 Like

It seems to be working but I am only getting this output:

[
{
“T”: [
{
“degree”: “”,
“degreeCount”: 59606
}
]
}
]

Then you don’t seem to have a valid string value in the degree attribute of the Education vertex.

1 Like

Ok I will try to fix that. Thank you very much for your time Mark!

2 Likes