使用内置的SELECT进行查询
你现在有了一个有数据的图!您可以运行一些简单的内置查询来检查数据。

选择顶点

下面的GSQL命令报告person顶点的总数。person.csv数据文件标题行后有7行。
GSQL command
SELECT count() FROM person
类似地,下面的GSQL命令报告friendship边的总数。friendship.csv文件在标题行后也有7行。
GSQL command
SELECT count() FROM person-(friendship)->person
结果如下所示:
GSQL > SELECT count() FROM person
[{
"count": 7,
"v_type": "person"
}]
GSQL > SELECT count() FROM person-(friendship)->person
[{
"count": 14,
"e_type": "friendship"
}]
GSQL >
边数
为什么有14条边?对于无向边,GSQL实际上创建两条边,每个方向一条
如果您想查看关于特定顶点集的详细信息,可以使用“SELECT *”和WHERE子句来指定谓词条件。以下是一些可以尝试的语句:
GSQL command
SELECT * FROM person WHERE primary_id=="Tom"
SELECT name FROM person WHERE state=="ca"
SELECT name, age FROM person WHERE age > 30
结果是JSON格式,如下所示
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"
}
]

选择边

以同样的方式,我们可以看到关于边的细节。为了描述一个边,您可以在三个部分中指定顶点和边的类型,并添加一些标点符号来表示遍历方向:
GSQL syntax
source_type -(edge_type)-> target_type
注意,无论是无向边还是有向边,总是使用箭头->。这是因为我们描述的是查询在图中的遍历(搜索)方向,而不是边本身的方向。
我们可以在WHERE子句中使用from_id谓词,从由“from_id”标识的顶点选择所有friendship边。关键字ANY表示允许任何边缘类型或任何目标顶点类型。以下两个查询的结果相同.
GSQL command
SELECT * FROM person-(friendship)->person WHERE from_id =="Tom"
SELECT * FROM person-(ANY)->ANY WHERE from_id =="Tom"
对内置边选择查询的限制
为了防止查询可能返回过多的输出项,内置边查询有以下限制:
1. 必须指定源顶点类型
2. 必须指定from_id条件
用户定义查询没有这样的限制。
结果如下所示:
GSQL
GSQL > SELECT * FROM person-(friendship)->person WHERE from_id =="Tom"
[
{
"from_type": "person",
"to_type": "person",
"directed": false,
"from_id": "Tom",
"to_id": "Dan",
"attributes": {"connect_day": "2017-06-03 00:00:00"},
"e_type": "friendship"
},
{
"from_type": "person",
"to_type": "person",
"directed": false,
"from_id": "Tom",
"to_id": "Jenny",
"attributes": {"connect_day": "2015-01-01 00:00:00"},
"e_type": "friendship"
}
另一种检查图大小的方法是使用管理员工具gadmin的选项之一。从Linux shell中输入命令:
#Linux shell
gadmin status graph -v
#Linux shell
[[email protected] ~]$ 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
Copy link