Getting edge attribute for each hop in multihop using *1...x syntax

Hi, I am using syntax v2, and I’m trying to get the edge attribute after x number of hops (friendship.addeddate). I couldn’t assign alias to friendship to do like e.addeddate. I tried v.edgeAttribute(“friendship”, “addeddate”) but got syntax error with edgeType not valid. I didn’t find an example in the GSQL documentation on how to use edgeAttribute.

Also I would like to pass in a dynamic variable for the multihop so instead of 5 in the example, it will be x but the syntax wouldn’t take a variable.

CREATE QUERY QueryExample() FOR GRAPH mygraph syntax v2{ 
  BagAccum<DATETIME> @date;

  PERSON = {person.*};
  Result = SELECT s FROM PERSON:s - (friendship>*1..5) - :t
                      ACCUM s.@date+= friendship.addeddate;

  PRINT Result;

Thank you!

1 Like

Hi ttnguen,

For the edgeAttribute issue, does the type of attribute that you’re trying to add to the edge already exist in the schema? If the attribute doesn’t exist in your schema then you’re going to throw an invalid edgeType error.

If this is a value that you only need for the duration query, you can use a vertex attached accumulator. If this is a value that you wish to remain in your graph, then you will first need to add the edge attribute to the schema before setting it. You can load in your data without this value as it will default if there’s no value, then just populate the value a query run time.

For the second half of your question, it doesn’t seem like it’s possible to dynamically set the multihop count to a variable. I did a bit of testing on my end and could not find a method to make the hop count accept a variable. I’ll ask around the team and see if there’s something I’m missing, because this does seem like a useful feature.

1 Like

I used the Graph Studio to create the schema:
The “friendship” is my edge and it has the attribute “addeddate”.