FOREACH not allowing setBagExpr

Hi,
I have a syntax error with this query in that foosFiltered is not being allowed in the FOREACH as a setBagExpr. The error is:

“A container type is required, while ‘foosFiltered’ is Vertex Set”

From the formal specification “The (set) operators are straightforward, when two operands are both sets, the result expression is a set.”

And
“forEachControl := (name | “(” name [, name]+ “)”) IN setBagExpr”

So, seeing as foosFiltered is a set of vertices, and seeing as FOREACH can take a setBagExpr, how is the syntax error occuring?

CREATE OR REPLACE QUERY searchSystem(VERTEX<bar> sys, INT sasquach, STRING term, SET<STRING> cat, INT lim) FOR GRAPH ty SYNTAX v2 {
    INT at = 0;
  SetAccum<vertex> @@foosFound;
    SetAccum<vertex> @@toFilter;
    Start={sys};
  
    fooRes = SELECT s FROM
    Start-(LIST_ON_BAR:lob)-list_:l-(FOO_IN_LIST:fil)-foo:s
    WHERE (s.foo_title_sortkey LIKE term) AND
          s.category IN cat
      ACCUM @@foosFound +=s;
 
  sozRet = SELECT filterFoos FROM 
    Start-(BAR_SASQUACH_ON_BAR)-bar_sasquach:sz-(FOO_ON_SASQUACH:soz)-foo:filterFoos
    WHERE sz.sasquach == sasquach AND
      (soz.removed == true OR soz.hidden == true)
      ACCUM @@toFilter += filterFoos;
 
    foosFiltered = @@foosFound MINUS @@toFilter;
  
    FOREACH fooRet IN foosFiltered DO
      PRINT fooRet;
      at = at + 1;
      IF at > lim THEN
        BREAK;
      END;
  END;
}
1 Like

Hi Rene,

There are two different concepts, vertex set variable and vertex set accumulator.

vertex set variable is something like

vSetVar = SELECT t FROM…

or vSetVar = @@vSetAccum

It stores the result of the SELECT statement, and it can be started from within a SELECT statement. This one can not be integrated by FOREACH.

vertex set accumulator is defined like: SetAccum @@vSetAccum;

It is an accumulator container type that can be iterated.

So for your query you can write it like:

SetAccum @@foosFiltered;

@@foosFiltered = @@foosFound MINUS @@toFilter;

FOREACH fooRet IN @@foosFiltered DO…

Thanks.