Overlap between two sets out of one map.

19 views
Skip to first unread message

Felix P.

unread,
Mar 10, 2020, 7:19:18 AM3/10/20
to gsql-users
Hello,

I am trying to get the overlap between two sets out of the same map:

MapAccum<vertex<myType>, SetAccum<String>> @@map;

overlap = (@@map.get(key1) INTERSECT @@map.get(key2)).size();

But as a syntax error I get the following:
" Left set "@@map.get(key1)" returns vertex type [], but the richt set " @@map.get(key2)" returns vertex type [] "

In my understanding both ".get(key)" calls should return a set of strings.

Is there an other way one could calculate this easily?
And please tell me if I am using the INTERSECT clause wrongly.

Thanks
Felix

Rik

unread,
Mar 10, 2020, 9:25:18 AM3/10/20
to gsql-users
So the problem here may be that GSQL type inference is sometimes a little shallow. I'll raise a ticket anyway in case it is a bug.

This code works by expanding your expression, otherwise you are exactly correct:

        MapAccum<vertex, SetAccum<String>> @@map;

VERTEX  key1, key2;
SetAccum<String> @@left, @@right, @@result;
int overlap;
@@left = @@map.get(key1);
@@right = @@map.get(key2);
@@result = @@left INTERSECT @@right;
        overlap = @@result.size();
print overlap;

Felix P.

unread,
Mar 10, 2020, 11:30:59 AM3/10/20
to gsql-users
Thanks for the reply, I will test your solution and mark this thread as completet if it works if not I will post more specifics to the use case i try to achieve with this query.

Felix P.

unread,
Mar 12, 2020, 7:45:53 AM3/12/20
to gsql-users
Hello again,

your solution worked. Thanks you.

On Tuesday, 10 March 2020 14:25:18 UTC+1, Rik wrote:

Rik

unread,
Mar 12, 2020, 8:04:38 AM3/12/20
to gsql-users
Good news! Good luck, and of course we are here to help, so if anything else comes up, let us know.

Regards

Richard Henderson 
Lead EMEA SE
Reply all
Reply to author
Forward
0 new messages