Limit Clause with Edges

Hello,

I am running the below query, I want to return 5 vertexes with edges but it returning all vertex and edges.
CREATE QUERY Limit_test(/* Parameters here */) FOR GRAPH Company {

  /* Write query logic here */

SetAccum<edge> @@visRes ;
int k = 5;
 Start = {ANY};
  Parents = SELECT a FROM Start:s -(Holdings:e)-> Company_:a where a.Location != "a" ACCUM @@visRes += e Order By a.Name Desc Limit k ; 
  L = SELECT b FROM Parents:b -(Holdings:e)- :b where count(@@visRes) < 5 ACCUM @@visRes += e;
PRINT Parents ;
  PRINT @@visRes;
PRINT "Test Limit"; 
}

Thanks in Advance!

The reason you are experiencing this behavior is that the LIMIT clause only acts on the output vertex set the you get from the SELECT statement. It does not modify/limit the frequency of other clauses like ACCUM or POST-ACCUM.

In other words, the SELECT statement is first processed normally (ignoring the LIMIT clause). Then, the output of the SELECT statement is what actually gets limited after all the querying is finished.

Your output set Parents should (correctly) only have 5 items.

The SetAccum @@visRes will not be limited by this statement. I recommend accumulating these edges in another SELECT statement after you have limited your first SELECT statement output set to 5 Companies.

You could also manually impose a size limit of 5 on this accumulator by conditionally adding elements to it only in cases where @@visRes.size() < 5.

1 Like