安装以及基本操作
安装
下载地址 安装:
1
2
3
tar xzf <your_tigergraph_package>.tar.gz
cd tigergraph*/
sudo ./install.sh
基本操作
数据准备:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
person.csv
name,gender,age,state
Tom,male,40,ca
Dan,male,34,ny
Jenny,female,25,tx
Kevin,male,28,az
Amily,female,22,ca
Nancy,female,20,ky
Jack,male,26,fl
friendship.csv
person1,person2,date
Tom,Dan,2017-06-03
Tom,Jenny,2015-01-01
Dan,Jenny,2016-08-03
Jenny,Amily,2015-06-08
Dan,Nancy,2016-01-03
Nancy,Jack,2017-03-02
Dan,Kevin,2015-12-30
在安装过程中创建的用户中进行登录:
1
2
3
4
5
例如账户test,密码test
输入gsql进入数据库shell界面
ls查看数据库中的库
drop all删除所有数据
Restarting TigerGraph services重启数据库服务
库的创建:
1
2
3
节点的创建:CREATE VERTEX person (PRIMARY_ID name STRING, name STRING, age INT, gender STRING, state STRING)
边的创建:CREATE UNDIRECTED EDGE friendship (FROM person, TO person, connect_day DATETIME)
图的创建:CREATE GRAPH social (person, friendship)
数据载入:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
GSQL > USE GRAPH social
Using graph 'social'
GSQL > BEGIN
GSQL > CREATE LOADING JOB load_social FOR GRAPH social {
GSQL > DEFINE FILENAME file1="/home/tigergraph/person.csv";
GSQL > DEFINE FILENAME file2="/home/tigergraph/friendship.csv";
GSQL >
GSQL > LOAD file1 TO VERTEX person VALUES ($"name", $"name", $"age", $"gender", $"state") USING header="true", separator=",";
GSQL > LOAD file2 TO EDGE friendship VALUES ($0, $1, $2) USING header="true", separator=",";
GSQL > }
GSQL > END
The job load_social is created.
run loading job load_social
数据查询:
1
2
3
4
5
6
查询person顶点的个数
SELECT count(*) FROM person
查询指定定顶点的详细信息
SELECT * FROM person WHERE primary_id=="Tom"
SELECT name FROM person WHERE state=="ca"
SELECT name, age FROM person WHERE age > 30
选择边:
1
2
3
4
5
6
7
8
9
语法:source_type -(edge_type)-> target_type
查找与tom链接有friendship关系的person节点
SELECT * FROM person-(friendship)->person WHERE from_id =="Tom"
查找与tom节点有边链接的节点
SELECT * FROM person-(ANY)->ANY WHERE from_id =="Tom"
注意:
1. 必须指定源顶点类型
2. 必须指定from_id条件