Is any way to use more than one vertex set in a SELECT statement?

174 Views Asked by At

I was wondering if there is any way to use more than one vertex set in a SELECT statement. I would think it should be possible because... why not?

For example, say we have this basic query:

CREATE QUERY coolQuery(VERTEX<Foo> foo, String bar, String biz) FOR GRAPH cool_graph SYNTAX v2 {

  f = {foo};

  x = SELECT i
  FROM SomeVertex:i -(PathType1>)- f

  y = SELECT i
  FROM x:i -(<PathType2)- BarVertex:br
  WHERE br.id == bar;

  z = SELECT i
  FROM y:i -(PathType3>.PathType4>)- BizVertex:bz
  WHERE bz.id == biz;

  PRINT z;
}

Now, that's all fine and dandy, but what if I know the other vertices whose ids are bar and biz? Can I use more than one known vertex set in a SELECT statement? The goal here is to arrive to the final SomeVertex set as quickly as possible via using the indexed vertex id values.

This is what I'm thinking:

CREATE QUERY coolQuery2(VERTEX<FooVertex> foo, VERTEX<BarVertex> bar, Vertex<BizVertex> biz) FOR GRAPH cool_graph SYNTAX v2 {

  f = {foo};
  br = {bar};
  bz = {biz};

  x = SELECT i
  FROM SomeVertex:i -(PathType1>)- f

  y = SELECT i
  FROM x:i -(<PathType2)- br

  z = SELECT i
  FROM y:i -(PathType3>.PathType4>)- bz

  PRINT z;
}

I get syntax errors with this and I can't find anything in the docs that does this type of thing where more than one known vertex set is used in a SELECT statement.

1

There are 1 best solutions below

0
On

in your case, it is recommended to write the query this way:

Version 1:

CREATE QUERY coolQuery2(VERTEX<FooVertex> foo, VERTEX<BarVertex> bar, Vertex<BizVertex> biz) FOR GRAPH cool_graph SYNTAX v2 {

  OrAccum<BOOL> @hasFoo, @hasBar, @hasBiz;

  f = {foo, bar, biz};

  result = select t from f:s-((PathType1|PathType2|PathType3):e)-:t
               accum case when s == foo then t.@hasFoo += true end,
                          case when s == bar then t.@hasBar += true end,
                           case when s == biz then t.@hasBiz += true end
               having t.@hasFoo and t.@hasBar and t.@hasBiz;

  print result;
}

Version 2:

CREATE QUERY coolQuery2(VERTEX<FooVertex> foo, VERTEX<BarVertex> bar, Vertex<BizVertex> biz) FOR GRAPH cool_graph SYNTAX v2 {

  OrAccum<BOOL> @hasFoo, @hasBar, @hasBiz;

  f = {foo};
  br = {bar};
  bz = {biz};

  fooSet = select t from f-(PathType1)-:t;
  barSet = select t from br-(PathType1)-:t;
  bizSet = select t from bz-(PathType1)-:t;

  result = fooSet intersect barSet intersect bizSet;

  print result;
}

In this case version, 1 is more recommended since it has better concurrency and only does only one SELECT.