Run Built-in Queries
You now have a graph with data! You can run some simple built-in queries to inspect the data.

Select Vertices

The following GSQL command reports the total number of person vertices. The person.csv data file had 7 lines after the header.
GSQL command
1
SELECT count(*) FROM person
Copied!
Similarly, the following GSQL command reports the total number of friendship edges. The friendship.csv file also had 7 lines after the header.
GSQL command
1
SELECT count(*) FROM person-(friendship)->person
Copied!
The results are illustrated below.
GSQL shell
1
GSQL > SELECT count(*) FROM person
2
[{
3
"count": 7,
4
"v_type": "person"
5
}]
6
GSQL > SELECT count(*) FROM person-(friendship)->person
7
[{
8
"count": 7,
9
"e_type": "friendship"
10
}]
11
GSQL >
Copied!
Counting Undirected Edges
As of TG 2.4, undirected edges are counted once per edge. Previously, they were counted once per endpoint. E.g., the example above now returns 7 instead of 14.
If you want to see the details about a particular set of vertices, you can use "SELECT *" and the WHERE clause to specify a predicate condition. Here are some statements to try:
GSQL command
1
SELECT * FROM person WHERE primary_id=="Tom"
2
SELECT name FROM person WHERE state=="ca"
3
SELECT name, age FROM person WHERE age > 30
Copied!
The result is in JSON format as shown below.
GSQL shell
1
GSQL > SELECT * FROM person WHERE primary_id=="Tom"
2
[{
3
"v_id": "Tom",
4
"attributes": {
5
"gender": "male",
6
"name": "Tom",
7
"state": "ca",
8
"age": 40
9
},
10
"v_type": "person"
11
}]
12
GSQL > SELECT name FROM person WHERE state=="ca"
13
[
14
{
15
"v_id": "Amily",
16
"attributes": {"name": "Amily"},
17
"v_type": "person"
18
},
19
{
20
"v_id": "Tom",
21
"attributes": {"name": "Tom"},
22
"v_type": "person"
23
}
24
]
25
GSQL > SELECT name, age FROM person WHERE age > 30
26
[
27
{
28
"v_id": "Tom",
29
"attributes": {
30
"name": "Tom",
31
"age": 40
32
},
33
"v_type": "person"
34
},
35
{
36
"v_id": "Dan",
37
"attributes": {
38
"name": "Dan",
39
"age": 34
40
},
41
"v_type": "person"
42
}
43
]
Copied!

Select Edges

In similar fashion, we can see details about edges. To describe an edge, you name the types of vertices and edges in the three parts, with some added punctuation to represent the traversal direction:
GSQL syntax
1
source_type -(edge_type)-> target_type
Copied!
Note that the arrow -> is always used, whether it's an undirected or directed edge. That is because we are describing the direction of the query's traversal (search) through the graph, not the direction of the edge itself.
We can use the from_id predicate in the WHERE clause to select all friendship edges starting from the vertex identified by the "from_id". The keyword ANY to indicate that any edge type or any target vertex type is allowed. The following two queries have the same result
GSQL command
1
SELECT * FROM person-(friendship)->person WHERE from_id =="Tom"
2
SELECT * FROM person-(ANY)->ANY WHERE from_id =="Tom"
Copied!
Restrictions on built-in edge select queries
To prevent queries which might return an excessive number of output items, built-in edge queries have the following restrictions:
  1. 1.
    The source vertex type must be specified.
  2. 2.
    The from_id condition must be specified.
There is no such restriction for user-defined queries.
The result is shown below.
GSQL
1
GSQL > SELECT * FROM person-(friendship)->person WHERE from_id =="Tom"
2
[
3
{
4
"from_type": "person",
5
"to_type": "person",
6
"directed": false,
7
"from_id": "Tom",
8
"to_id": "Dan",
9
"attributes": {"connect_day": "2017-06-03 00:00:00"},
10
"e_type": "friendship"
11
},
12
{
13
"from_type": "person",
14
"to_type": "person",
15
"directed": false,
16
"from_id": "Tom",
17
"to_id": "Jenny",
18
"attributes": {"connect_day": "2015-01-01 00:00:00"},
19
"e_type": "friendship"
20
}
21
]
Copied!
Another way to check the graph's size is using one of the options of the administrator tool, gadmin. From a Linux shell, enter the command
gadmin status graph -v
Linux shell
1
[[email protected] ~]$ gadmin status graph -v
2
verbose is ON
3
=== graph ===
4
[m1 ][GRAPH][MSG ] Graph was loaded (/usr/local/tigergraph/gstore/0/part/): partition size is 4.00KiB, SchemaVersion: 0, VertexCount: 7, NumOfSkippedVertices: 0, NumOfDeletedVertices: 0, EdgeCount: 14
5
[m1 ][GRAPH][INIT] True
6
[INFO ][GRAPH][MSG ] Above vertex and edge counts are for internal use which show approximate topology size of the local graph partition. Use DML to get the correct graph topology information
7
[SUMMARY][GRAPH] graph is ready
Copied!
Last modified 1yr ago
Export as PDF
Copy link