GSQL®图形查询语言是一种用于探索和分析大规模数据的图形数据库语言。这种高阶的语言可以让用户轻松地在TigerGraph系统中执行强大的图遍历操作。通过将数据库管理员熟知的特性与极具表现力的新功能相结合,GSQL图形查询语言提供了简单的编写体验和强大执行能力。 GSQL查询包含一个或多个SELECT语句,每个SELECT语句或是对顶点和边的遍历,或是按照要求在顶点中选择出某些组成子集。通过多个SELECT语句的组合,用户可以将其需求逻辑映射在查询中,以解决真实环境中几乎所有的数据问题。
本文档重点介绍了GSQL图形查询语言的正式标准格式,并同时提供了大量各种查询方法的示例。所有的示例查询均运行在以下六个示例图形上,它们是:workNet,socialNet,friendNet,computerNet,minimalNet和investmentNet。他们的图形数据库纲目(graph schema)如下所示。创建和加载这些图形需要用到一个小规模的数据集(包含10到20个顶点),附录D中列出了这些示例的完整命令和数据文件。数据集并不大,所以每个示例查询的结果都很容易被理解。 压缩包文件gsql_ref_examples_2.0.tar.gz包含了所有的图形数据库Schema,数据文件和查询示例。
CREATE VERTEX person(PRIMARY_ID personId UINT, id STRING, gender STRING) WITH STATS="OUTDEGREE_BY_EDGETYPE"
CREATE UNDIRECTED EDGE friend(FROM person, TO person)
CREATE VERTEX post(PRIMARY_ID postId UINT, subject STRING, postTime DATETIME)
CREATE DIRECTED EDGE posted(FROM person, TO post)
CREATE DIRECTED EDGE liked(FROM person, TO post, actionTime DATETIME)
CREATE VERTEX person(PRIMARY_ID personId STRING, id STRING, locationId STRING, skillSet SET<INT>, skillList LIST<INT>, interestSet SET<STRING COMPRESS>, interestList LIST<STRING COMPRESS>)
CREATE VERTEX company(PRIMARY_ID clientId STRING, id STRING, country STRING)
CREATE UNDIRECTED EDGE worksFor(FROM person, TO company, startYear INT, startMonth INT, fullTime BOOL)
CREATE VERTEX person(PRIMARY_ID personId UINT, id STRING)
CREATE UNDIRECTED EDGE friend(FROM person, TO person)
CREATE UNDIRECTED EDGE coworker(FROM person, TO person)
CREATE VERTEX computer(PRIMARY_ID compID STRING, id STRING)
CREATE DIRECTED EDGE connected(FROM computer, TO computer, connectionSpeed INT)
CREATE VERTEX testV(PRIMARY_ID id STRING)
CREATE UNDIRECTED EDGE testE(FROM testV, TO testV)
图形数据库Schema: investmentNet
TYPEDEF TUPLE < age UINT (4), mothersName STRING(20) > SECRET_INFO
CREATE VERTEX person(PRIMARY_ID personId STRING, portfolio MAP<STRING, DOUBLE>, secretInfo SECRET_INFO)
CREATE VERTEX stockOrder(PRIMARY_ID orderId STRING, ticker STRING, orderSize UINT, price FLOAT)
CREATE UNDIRECTED EDGE makeOrder(FROM person, TO stockOrder, orderTime DATETIME)