输入gsql命令
[tiger@ ~]$ gsql
目前图数据库是空的
GSQL-Dev > ls
---- Global vertices, edges, and all graphs
Vertex Types:
- VERTEX user(PRIMARY_ID id STRING, fans_num INT) WITH STATS="OUTDEGREE_BY_EDGETYPE", PRIMARY_ID_AS_ATTRIBUTE="false"
Edge Types:
Graphs:
- Graph MyGraph(user:v)
Jobs:
JSON API version: v2
Syntax version: v1
创建一个person用户节点类型:
GSQL-Dev > CREATE VERTEX person (PRIMARY_ID name STRING, name STRING, age INT, gender STRING, state STRING)
The vertex type person is created.
当然也可以用GraphStudio,更加方便,输入IP地址:14240,便可访问GraphStudio,创建。
可以看到界面只需要用Button就可以创建例如一个User的节点类型。
创建边类型:
The vertex type person is created.
GSQL-Dev > CREATE UNDIRECTED EDGE friendship (FROM person, TO person, connect_day DATETIME)
The edge type friendship is created.
This feature is not supported in the developer edition.
See doc.tigergraph.com for a comparison of the editions.
ls发现已经有图存在了,tigergraph不好的一点就是社区版只能支持一张图,但是如果这张图巨大,还是比较合适应用的。
所以只能先把这一切删除了
GSQL-Dev > drop all
Dropping all, about 1 minute ...
Abort all active loading jobs
Try to abort all loading jobs on graph MyGraph, it may take a while ...
[ABORT_SUCCESS] No active Loading Job to abort.
Shutdown restpp gse gpe ...
Graph store /home/tigergraph/tigergraph/gstore/0/ has been cleared!
Everything is dropped.
再重新创建:可以发现已经创建了一个叫social的图,包含点person和边friendship
GSQL-Dev > ls
---- Graph social
Vertex Types:
- VERTEX person(PRIMARY_ID name STRING, name STRING, age INT, gender STRING, state STRING) WITH STATS="OUTDEGREE_BY_EDGETYPE"
Edge Types:
- UNDIRECTED EDGE friendship(FROM person, TO person, connect_day DATETIME)
Graphs:
- Graph social(person:v, friendship:e)
Jobs:
Queries:
上传数据
GSQL-Dev > USE GRAPH social
Using graph 'social'
GSQL-Dev > BEGIN
GSQL-Dev > CREATE LOADING JOB load_social FOR GRAPH social {
GSQL-Dev > DEFINE FILENAME file1="/home/tigergraph/person.csv";
GSQL-Dev > DEFINE FILENAME file2="/home/tigergraph/friendship.csv";
GSQL-Dev >
GSQL-Dev > LOAD file1 TO VERTEX person VALUES ($"name", $"name", $"age", $"gender", $"state") USING header="true", separator=",";
GSQL-Dev > LOAD file2 TO EDGE friendship VALUES ($0, $1, $2) USING header="true", separator=",";
GSQL-Dev > }
GSQL-Dev > END
The job load_social is created.
运行Job
GSQL-Dev > RUN LOADING JOB load_social
[Tip: Use "CTRL + C" to stop displaying the loading status update, then use "SHOW LOADING STATUS jobid" to track the loading progress again]
[Tip: Manage loading jobs with "ABORT/RESUME LOADING JOB jobid"]
Starting the following job, i.e.
JobName: load_social, jobid: social.load_social.file.m1.1567499844139
Loading log: '/home/tigergraph/tigergraph/logs/restpp/restpp_loader_logs/social/social.load_social.file.m1.1567499844139.log'
Job "social.load_social.file.m1.1567499844139" loading status
[FINISHED] m1 ( Finished: 2 / Total: 2 )
[LOADED]
+---------------------------------------------------------------------------+
| FILENAME | LOADED LINES | AVG SPEED | DURATION|
|/home/tigergraph/friendship.csv | 8 | 7 l/s | 1.00 s|
| /home/tigergraph/person.csv | 8 | 6 l/s | 1.00 s|
+---------------------------------------------------------------------------+
从GraphStudio可以看到,可视化做得有点渣渣