Using Multiple Vertex Sets In SELECT Statement

50 views
Skip to first unread message

Brett Renshaw

unread,
Jan 17, 2020, 4:55:56 PM1/17/20
to gsql-users
Hi, 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 an 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.

Xinyu Chang

unread,
Jan 17, 2020, 5:38:59 PM1/17/20
to Brett Renshaw, gsql-users
Hi Brett,

Thanks for your great question.

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.

Xinyu Chang
Solution Team Leader
TigerGraph, Inc.


--
Welcome to GSQL-user group.
- our mission is bringing the power of graph databases to everyone www.opengsql.org
- technical resource can be found here https://docs.tigergraph.com/
---
You received this message because you are subscribed to the Google Groups "gsql-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gsql-users+...@opengsql.org.
To view this discussion on the web visit https://groups.google.com/a/opengsql.org/d/msgid/gsql-users/4b4d8acb-6f79-48f9-b7f2-130521c1c837%40opengsql.org.

Brett Renshaw

unread,
Jan 17, 2020, 6:35:38 PM1/17/20
to Xinyu Chang, gsql-users
Thank you!
I believe that is exactly what I was looking for!
I was pretty sure there was a way to do,
thank you for showing me that way.  :)

Sent from my iPhone

On Jan 17, 2020, at 4:38 PM, Xinyu Chang <xi...@tigergraph.com> wrote:



Brett Renshaw

unread,
Feb 12, 2020, 3:27:43 PM2/12/20
to gsql-users, xi...@tigergraph.com

graph.png

I believe I have one that is more complicated now, and I am not sure how to go about it.
Say that I have the above graph schema. (all edges also have reverse edges).

In the query, parameters for VERTEX<v1>, VERTEX<v2>, VERTEX<v3>, and VERTEX<v6> would be provided.
The result of the query should return the set of v4 vertices.
(if in fact the vertex params for v1, v2, v3, and v6 actually have connecting edges).
The vertex v5 is ignored, v4 should have some path connecting any e4 and e5 to v6.

How can I go about this type of query using the vertex ids as the params?

Xinyu Chang

unread,
Feb 12, 2020, 4:32:39 PM2/12/20
to Brett Renshaw, gsql-users
So in this case, v3 should be connected by both input v1 and v2? 

And the v4 in the result should be connected to qualified v3?

And v6 should be connected to v4 via any v5?

Thanks.


Xinyu Chang
Solution Team Leader
TigerGraph, Inc.

Brett Renshaw

unread,
Feb 12, 2020, 5:56:55 PM2/12/20
to gsql-users, bigfo...@gmail.com
That is correct.

I can put the query together with multiple SELECT statements
(but only using v3 param as VERTEX<v3> type whereas other params are STRING),
but I'd really like to know how to chain this all together using one SELECT (if possible)

Brett Renshaw

unread,
Feb 19, 2020, 2:08:15 PM2/19/20
to gsql-users, bigfo...@gmail.com
Any idea on this one?

Xinyu Chang

unread,
Feb 19, 2020, 8:49:02 PM2/19/20
to Brett Renshaw, gsql-users
Hi Brett,

Sorry for the late reply. For that query we have to write them in syntax v1, which is to use multiple select.

I don't think we can chain all of them in one statement for now.

Thanks.


Xinyu Chang
Director of Customer Solutions
TigerGraph, Inc.


On Wed, Feb 19, 2020 at 11:08 AM Brett Renshaw <bigfo...@gmail.com> wrote:
Any idea on this one?

--
Welcome to GSQL-user group.
- our mission is bringing the power of graph databases to everyone www.opengsql.org
- technical resource can be found here https://docs.tigergraph.com/
---
You received this message because you are subscribed to the Google Groups "gsql-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gsql-users+...@opengsql.org.

Brett Renshaw

unread,
Feb 20, 2020, 12:09:34 AM2/20/20
to Xinyu Chang, gsql-users
Thank you for the info, that is helpful.
I think with neo4j Cypher queries this type of specifying middle vertices in a chain can be done.

Do you know if this chaining will be a feature in a future TigerGraph release?

Xinyu Chang

unread,
Feb 20, 2020, 3:08:20 PM2/20/20
to Brett Renshaw, gsql-users
Yes, I just confirmed this with the language team. we will support this very soon.

Thanks.


Xinyu Chang
Director of Customer Solutions
TigerGraph, Inc.

Brett Renshaw

unread,
Feb 20, 2020, 6:34:05 PM2/20/20
to gsql-users, bigfo...@gmail.com
Awesome, that is great to know, thanks!

I Appreciate the helpful info as always.  :)
Reply all
Reply to author
Forward
0 new messages