SAMPLE in systax v2 queries

Hi Tigergraph team,

I see that sample clause is not supported in syntax v2 queries. I just want to sample the edge in the output to be able to visualized on graph studio, just around 10-50 edges. How can I do in syntax v2.

Below is my code:
CREATE QUERY mutihop(Vertex source_vertex_id) FOR GRAPH My_graph syntax v2 {
ListAccum @@edgelist;

Source = {source_vertex_id};

vertex_result = select t3 from Source:s1 - (Send_To>:e1) - :t1 - (Send_To>:e2) - :t2 - (Send_To>:e3) - :t3
//SAMPLE 5 EDGE WHEN t2.outdegree() >= 1
ACCUM @@edgelist +=e1, @@edgelist+=e2,@@edgelist+=e3
//LIMIT 5
;

PRINT @@edgelist;
}

SAMPLE works in SYNTAX V2 - i have used it

What error are you getting? Also consider putting in the Vertex names, not just the t2 alias

Hi markmegerian,

If I used SAMPLE clause, I got this error:

And here is my schema:

CREATE VERTEX Firm (PRIMARY_ID id STRING) WITH primary_id_as_attribute=“true”

CREATE DIRECTED EDGE Send_To(From Firm, To Firm, amount DOUBLE) WITH REVERSE_EDGE=“reverse_Send_To”

Any idea to fix this, thanks

I see, you may be using a different version than me

Can you just rewrite it using V1 syntax?

Hi mark,

If I rewrite using V1 syntax, I cannot use mutihop pattern since V1 does not support it. Can you have any ideas? Many thanks

Its not pretty but this would work for V1 syntax:


CREATE QUERY multihop(INT hops = 3, Vertex source_vertex_id) FOR GRAPH mygraph { 
  ListAccum<EDGE>  @@edgelist;
  
  source = {source_vertex_id};
  
  FOREACH j IN RANGE[1, hops] DO
  source = SELECT t FROM source:s -(Send_To:e)->  Firm:t
         SAMPLE 5 EDGE WHEN s.outdegree() >= 5
         ACCUM @@edgelist += e;
  END;
  PRINT @@edgelist;
}

Hi Markmegerian,

Thanks for your response. I also tried this before, however, when we sample the edges in the first loop, the target Firm may have no further Send_To edges, which leads to only one one-hop pattern in the result instead of 3-hopes pattern, as below:
image

Many thanks if you have any ideas.

Since your initial post implied that the exact number of edges is not important, how about this? You can adjust the limiter based on the fanout ratio

CREATE QUERY mutihop(Vertex source_vertex_id, INT limiter = 10) FOR GRAPH My_graph syntax v2 {
ListAccum<EDGE>  @@edgelist;

Source = {source_vertex_id};
vertex_result = select t3 from Source:s1 - (Send_To>:e1) - Firm:t1 - (Send_To>:e2) - Firm:t2 - (Send_To>:e3) - Firm:t3
LIMIT limiter;

edge_finder = select t3 from Source:s1 - (Send_To>:e1) - Firm:t1 - (Send_To>:e2) - Firm:t2 - (Send_To>:e3) - vertex_result
ACCUM @@edgelist +=e1, @@edgelist+=e2,@@edgelist+=e3;

PRINT @@edgelist;
}

Hi mark,

This does work for me. Thank you so much for such helpful suggestion. Anyway, I also have another solution for this with the help from @abdul as below:
CREATE QUERY mutihop(Vertex source_vertex_id) FOR GRAPH Mygraph{

TYPEDEF TUPLE<EDGE e1, EDGE e2, EDGE e3> edge_tup;
HeapAccum<edge_tup>(20, e1 ASC, e2 ASC, e3 ASC) @@edgelist;

Source = {source_vertex_id};

vertex_result = select t1
from Source:s1 - (Send_To>:e1) - Firm:t1 - (Send_To>:e2) - Firm:t2 - (Send_To>:e3) - Firm:t3
ACCUM @@edgelist +=edge_tup(e1, e2, e3)
;

PRINT @@edgelist;

}

Thats also an interesting solution - just curious, since you are printing a tuple at the end, what does your screen look like when you print this in Graph Studio ?

Here is the example output in Graph Studio: