(SEM-426) ACCUM clause is not endpoint-local

Can anyone shed some light on this error, so I can adjust my query accordingly?

CREATE QUERY myTraversal (VERTEX<Patient> pat) FOR GRAPH synthea SYNTAX v2 {
    TYPEDEF TUPLE <EDGE<patientEncounter> pe, EDGE<encounterReason> er> Relationships;
    TYPEDEF TUPLE <STRING patient_id, STRING patient_prefix, STRING patient_first_name,
        STRING patient_last_name, DATETIME patient_birthdate, STRING patient_gender,
        STRING patient_marital_status, STRING patient_address, STRING patient_city,
        STRING patient_state, STRING encounter_id, STRING encounter_class,
        STRING encounter_code, STRING encounter_description, FLOAT encounter_cost,
        DATETIME encounter_start_dt, DATETIME encounter_stop_dt, STRING diagnostic_code,
        STRING diagnostic_description> Information;

    MapAccum<Relationships, Information> @@traversal;

    patientSeed = {Patient.*};

    result = SELECT s FROM patientSeed:s-(patientEncounter>:pe)-Encounter:e-(encounterReason>:er)-Diagnosis:d
        WHERE s.patient_id == pat.patient_id
        ACCUM @@traversal += (Relationships(pe, er) -> Information(
            s.patient_id, s.prefix, s.first_name, s.last_name, s.birthdate,
            s.gender, s.marital_status, s.address, s.city, s.state,
            e.encounter_id, e.class, e.code, e.description, e.cost,
            e.start_dt, e.stop_dt, d.diagnosis_code, d.description));

    PRINT result;


Then I guess my next question is when will we see support for accumulators through an entire query.

Currently, v2 syntax query only supports the use of source vertex alias of the path, target vertex alias of the path, source vertex alias of the last hop in the path, and the edge alias of the last hop in the path in ACCUM clause, in the case that the last hop is a single edge.

As in the case of the query here, the usable aliases are:

s - source vertex alias of the path
e - source vertex alias of the last hop
er - edge alias of the last hop
d - target vertex alias of the path

Note that if the last hop of the query, i.e. Encounter:e-(encounterReason>:er)-Diagnosis:d takes more than one edge, for example if it uses star pattern, then e will also become unusable.

A way to adjust the query is to break up the pattern into two parts, where the Encounter vertex is the target of the first part and source of the second part. Then, you can pass the patientEncounter edge to the Encounter vertex in a accumulator in the first part and accumulate to @@traversal in the second part.

On the side note, one other suggestion is to initialize patientSeed with:

patientSeed ={ pat };

In this case you won’t need the WHERE condition in the following query block.


Thanks for the feedback on the query. Much appreciated. I am now splitting the traversal into separate queries. Your bit of advice about accumulating the previous accumulator will be helpful as I continue down this path.

Thanks again.