Is there a way to convert LIST to a SET within an accumulator statement?
In this GSQL query I am constructing triples (technically quads), and need to pull a property from the edge to compute the last entry.
A code example:
CREATE QUERY getTriples() FOR GRAPH SomeGraph SYNTAX v2 {
TYPEDEF TUPLE <VERTEX src, EDGE edg, VERTEX dest, STRING year> TUPLE_RECORD;
SetAccum<TUPLE_RECORD> @@triples;
p = ANY;
res = SELECT tgt FROM p:s - (:e1) - :tgt WHERE s!=tgt
ACCUM @@triples += TUPLE_RECORD(s, e1, tgt, subGetYearProp(e1.listOfStringProperty));
PRINT @@triples;
}
The edge property listOfStringProperty
is a List<String>
in the graph schema. For example ["2010", "2012", "1974"]
. Now I want to compute something over this property, for example the min value. However, (sub)queries do not take LIST as arguments, only SET or BAG. For example:
CREATE QUERY subGetYearProp(SET<STRING> years) RETURNS (MinAccum<STRING) {
MinAccum<STRING> @@minYear;
FOREACH yr in years DO
@@minYear += yr
END;
RETURN @@minYear;
}
Within getTriples()
the subquery subGetYearProp
will not compile because it expects a SET
but is given a LIST
. Is there a performant way to cast e1.listOfStringProperty
to a SET within the ACCUM
where the triples are constructed?
I have a solution with a global accumulator to build a map of SetAccums for those properties, but that requires a second loop over all edges to then construct the triple set.