Need help getting started with a real simple query

I’m new to TG, reviewed the GSQL docs and some demos, but am still having trouble. Can you please help me get started with this?

Using your sample data friendship.csv and person csv I created a very simple schema with just a person vertex and a friend edge where the edge links person1 (source) to person2 (target).

After loading the data I went to “Explorer Graph” and used the default settings. I saw 5 vertices but no edges which makes me think I did something wrong when mapping the data.

Can you confirm it I should see edges in this graph?

Next – I want to write a very simple query which could be as simple a show all persons, or show persons who are a friends of Dan. I took some existing sample queries from your website and modified them for this schema, but everything I tried had incorrect syntax.

Much thanks in advance.

The “Explore Graph” page is working correctly. You are exploring vertices, not edges (“Pick vertices by vertex types”). After choosing a few sample vertices, you can double click a certain vertex to reveal all outgoing/incoming edge connections.

The following query is taken from the GSQL101 section of our documentation : https://docs.tigergraph.com/intro/gsql-101/parameterized-gsql-query

CREATE QUERY hello(VERTEX<person> p) FOR GRAPH social {

Start = {p};

Result = SELECT tgt

FROM Start:s-(friend:e) ->person:tgt;

PRINT Result;

}

Could you possibly send over the query you wrote?

Thanks for your questions,

Kevin

Hi George,

You did nothing wrong in the data mapping. The “Search vertices” tab in Explore Graph page is for picking / searching vertices only. You can:

  1. Double click a vertex to see its directly connected edges and vertices

  2. Switch to other tabs (Expand vertices, find paths, find connections) on Explore Graph page.

Please refer to our GraphStudio documentation for more information:

https://docs.tigergraph.com/ui/graphstudio/explore-graph

Best,
Renchu

Thank you. Your quick response is a big help. Getting started is the hardest part.

In the example:

USE GRAPH social

CREATE QUERY hello(VERTEX<person> p) FOR GRAPH social{

Start = {p};

Result = SELECT tgt

FROM Start:s-(friendship:e) ->person:tgt;

PRINT Result;

Why do we need the variable “Start” when we have the parameter “p” being passed in. Shouldn’t we be able to reference p similar to what we would do in TSQL?

The query ran find, however, I didn’t see edges in the query results. shouldn’t those be present?

Thank you.

Start is a vertex set that contains p. The SELECT statement needs to start from a vertex set, and p is a single vertex so we’ll just need to set that as the starting vertex set.

The “Start:s-(friendship:e)” is part of the traversal instance. The whole traversal instance is this: Result = SELECT tgt FROM Start:s-(friendship:e) ->person:tgt;

What this is saying is:

  1. Let’s start from vertex set “Start”, which we will give an alias name of s.

  2. Traverse the edge named “friendship”, which we will give alias name of e.

  3. Travel only to vertices that are of type “person”, which are give an alias of name tgt.

  4. Save the target vertices that are reached by the SELECT statement.

The query is only saving the vertices, not the path(s) traversed to find these vertices.

If you want to find the edges, you’ll need to use an accumulator : https://docs.tigergraph.com/dev/gsql-ref/querying/accumulators#setaccum

You can use a SetAccum and store the edge alias by using the ACCUM clause during the traversal : ACCUM @@nameOfEdgeSet += e;

All GSQL language documentation can be found here: https://docs.tigergraph.com/dev/gsql-ref

Thanks,

Kevin

Thanks Kevin. I did not see the syntax using “ACCUM @@nameOfEdgeSet += e;” in https://docs.tigergraph.com/dev/gsql-ref/querying/accumulators#setaccum .

Can you please show me how to use it in our example?

CREATE QUERY hello(vertex<person> p) FOR GRAPH social {

//SetAccum<STRING> @@nameOfEdgeSet;
//@@intSetAccum += 5;

Start = {p};
Result = SELECT tgt

FROM Start:s-(friend:e) ->person:tgt;

//ACCUM @@nameOfEdgeSet += e;

PRINT Result;
}

Sure. The example I gave above is adding an edge alias to the edge set.

create query hello(vertex<person> p) for graph social {

  SetAccum<edge> @@edgeSet;

  Start = {p};
  Result = select t from Start:s - (friend:e) - person:t
                accum @@edgeSet += e;

  print @@edgeSet; (if you want the vertex attributes to be printed as well, you'll need to print the vertex set "Result".
}

Thanks,
Kevin

OK. This executes but I don’t see edges in the graph. only vertices.

CREATE QUERY hello(vertex<person> p) FOR GRAPH social {
   

  SetAccum<edge> @@edgeSet;
   
  Start = {p};
  Result = SELECT tgt
           FROM Start:s-(friend:e) ->person:tgt;
   
    //ACCUM @@nameOfEdgeSet += e;
   
  PRINT Result;
    print @@edgeSet; //(if you want the vertex attributes to be printed as well, you'll need to print the vertex set "Result".
}

Maybe the query is OK but something is wrong with the data or i’m using the wrong input parameter (Vertex id = Dan).

Why are you commenting out the ACCUM line?

If you copy paste the query I provided in my previous reply it should work fine.

Yes that worked thank you. I thought I had to include both"
PRINT Result;
print @@edgeSet;

to see both.

Sorry for all the dumb questions, but I’m really struggling getting up to speed as this is all foreign. I was looking for a guide that could explain simple syntax which the assumption is made that users know such as “@@” and many more. Is there such a reference or guide? I’m sure I will have plenty more of these type of questions for a little while so thank you for your fast replies and patience. My experience is all on the MS stack, but helps any to tolerate this, we’re in the process of making a decision to use TB rather than Cosmos.

Great!

As long as you print the edges between vertices, the vertices will also print but only with the vertex ID. If you wanted the vertex attributes, you would need to print the vertex set as well.

The documentation page has all this information, which may be a bit much to read : https://docs.tigergraph.com/dev/gsql-ref

To get a jump-start into writing queries, we have a series of training videos on Youtube: https://www.youtube.com/playlist?list=PLq4l3NnrSRp6vaCWmookIZJefDkAPvaxS

Don’t hesitate to ask any other questions you have!

Thanks,

Kevin