The following GSQL command reports the total number of person vertices. The person.csv data file had 7 lines after the header.
GSQL command
SELECT count() FROM person
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
SELECT count() FROM person-(friendship)->person
The results are illustrated below.
GSQL shell
GSQL > SELECT count() FROM person
[{
"count": 7,
"v_type": "person"
}]
GSQL > SELECT count() FROM person-(friendship)->person
[{
"count": 14,
"e_type": "friendship"
}]
GSQL >
Edge Count
Why are there 14 edges? For an undirected edge, GSQL actually creates two edges, one in each direction.
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
SELECT * FROM person WHERE primary_id=="Tom"
SELECT name FROM person WHERE state=="ca"
SELECT name, age FROM person WHERE age > 30
The result is in JSON format as shown below.
GSQL shell
GSQL > SELECT * FROM person WHERE primary_id=="Tom"
[{
"v_id": "Tom",
"attributes": {
"gender": "male",
"name": "Tom",
"state": "ca",
"age": 40
},
"v_type": "person"
}]
GSQL > SELECT name FROM person WHERE state=="ca"
[
{
"v_id": "Amily",
"attributes": {"name": "Amily"},
"v_type": "person"
},
{
"v_id": "Tom",
"attributes": {"name": "Tom"},
"v_type": "person"
}
]
GSQL > SELECT name, age FROM person WHERE age > 30
[
{
"v_id": "Tom",
"attributes": {
"name": "Tom",
"age": 40
},
"v_type": "person"
},
{
"v_id": "Dan",
"attributes": {
"name": "Dan",
"age": 34
},
"v_type": "person"
}
]
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
source_type -(edge_type)-> target_type
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
SELECT * FROM person-(friendship)->person WHERE from_id =="Tom"
SELECT * FROM person-(ANY)->ANY WHERE from_id =="Tom"
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:
The source vertex type must be specified.
The from_id condition must be specified.
There is no such restriction for user-defined queries.
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
[tigergraph@localhost ~]$ gadmin status graph -v
verbose is ON
=== graph ===
[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
[m1 ][GRAPH][INIT] True
[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
[SUMMARY][GRAPH] graph is ready