POST-ACCUM on Two Hop in v2 Syntax

Hello, I am getting an error with a POST-ACCUM that I am attempting when doing a two-hop query in the v2 syntax. Here is the code snippet:

Start = SELECT s
                                FROM Start:s-(:e)-:m-(:e2)- Patient:t
                                POST-ACCUM 
                                        IF t.@d_tx ==0 THEN
                                                t.@score = (1/p) *1
                                        ELSE IF t.@d_tx == 1 THEN
                                                t.@score = t.score
                                        ELSE
                                                t.@score = (1/q) * 1
                                        END;

I am currently getting a “unsupported: POST-ACCUM clause is not local” error when trying to install. Is this the desired behavior/is there a way to get around this in one SELECT statement? Thanks!

1 Like

Hi Parker!

A few items that would help us diagnose this:

  • Did you intend to have both @score and score , or is that a typo?
  • Can you include the details on p and q?
1 Like

Hey Mark!

The score and @score are correct. p and q are parameters that help determine probabilities of DFS or BFS type walking procedure. I do have a working work around currently, but it is sort of clunky and slow. I can post more details tomorrow morning.

1 Like

This is what I have now, and it works but is slow.

                        Start = SELECT s FROM Start:s-(:e)-:m-(:e2)-sourceType:t;
                        Tgt = SELECT t FROM Start:s-(:e)-:m-(:e2)-sourceType:t;
                        Tgt = SELECT t
                                FROM Tgt:t
                                POST-ACCUM 
                                        IF t.@d_tx ==0 THEN
                                                t.@score = (1/p) *1
                                        ELSE IF t.@d_tx == 1 THEN
                                                t.@score = t.score
                                        ELSE
                                                t.@score = (1/q) * 1
                                        END;

Ideally, I would like to 1) update Start variable as currently specified and 2) Do the POST-ACCUM in that same SELECT statement, but GSQL gives me the unsupported error above.

Thanks!

1 Like

Can you list the modifications you made to speed up the query?

Yeah, so the main thing was splitting the two-hop query into two single-hop queries.

Mid = SELECT m FROM Start:s-(:e)-:m;
Tgt = SELECT t FROM Mid:m-(:e2)-sourceType:t

Hello,
The first query you wrote is complaining because in post accum you can only modify the vertex you have selected. if you also want the Start vertex without traversing the same pattern again, you can do it in two steps
OrAcuum @flag;
Tgt = SELECT t
FROM Start:s-(:e)-:m-(:e2)- Patient:t
ACCUM s.@flag += true
POST-ACCUM
IF t.@d_tx ==0 THEN
t.@score = (1/p) *1
ELSE IF t.@d_tx == 1 THEN
t.@score = t.score
ELSE
t.@score = (1/q) * 1
END;
Start = select s from Start:s where s.@flag == true;

1 Like