DataItem
使用UQLResponse的get()
、alias()
方法时将获得DataItem结构。
DataItem的方法:
方法 | 类型 | 说明 |
---|---|---|
AsNodes() | []*structs.Node, map[string]*structs.Schema, error | 将NODE类型的*DataItem转为[]*structs.Node等 |
AsFirstNode() | *structs.Node, error | 取出NODE类型的*DataItem中的第一个*structs.Node |
AsEdges() | []*structs.Edge, map[string]*structs.Schema, error | 将EDGE类型的*DataItem转为[]*structs.Edge等 |
AsFirstEdge() | *structs.Edge, error | 取出EDGE类型的*DataItem中的第一个*structs.Edge |
AsPaths() | []*structs.Path, error | 将PATH类型的*DataItem转为[]*structs.Path |
AsGraphs() | []*structs.Graph, error | 将默认别名_graph的*DataItem转为[]*structs.Graph |
AsSchemas() | []*structs.Schema, error | 将默认别名_nodeSchema、_edgeSchema的*DataItem转为[]*structs.Schema |
AsProperties() | []*structs.Property, error | 将默认别名_nodeProperty、_edgeProperty的*DataItem转为[]*structs.Property |
AsAlgos() | []*structs.Algo, error | 将默认别名_algoList的*DataItem转为[]*structs.Algo |
AsTable() | *structs.Table, error | 将TABLE类型的*DataItem转为*structs.Table |
AsAttr() | *structs.Attr, error | 将ATTR类型的*DataItem转为*structs.Attr |
也可以使用方法
asTable()
将默认别名_graph、_nodeSchema、_edgeSchema等的*DataItem转为*structs.Table。
Node
structs.Node的字段:
字段 | 类型 | 说明 |
---|---|---|
ID | types.ID | Node的ID |
UUID | types.UUID | Node的UUID |
Schema | string | Node的Schema |
Values | *Value | Node的自定义属性 |
Name | string | Node的别名 |
structs.Node 的方法:
方法 | 类型 | 说明 |
---|---|---|
GetID() | types.ID | 获取当前Node的ID |
GetUUID() | types.UUID | 获取当前Node的UUID |
GetSchema() | string | 获取当前Node的Schema |
GetValues() | *Value | 获取当前Node的Values(自定义属性) |
Get(key string) | interface{} | 获取当前Node的某个自定义属性 |
GetBytes(key string) | []byte, error | 获取当前Node的某个自定义属性的字节数组 |
Set(key string, value interface{}) | error | 设置当前Node的某个自定义属性,属性名不存在时将则添加该键值对 |
示例:发送嬴图GQL语句查询一列点,获取第二个点的ID,将第一个点的rating改为8
func TestMisc(t *testing.T) {
// 创建名为conn的连接,此部分代码省略
resp, _ := conn.UQL("find().nodes({@movie}) as nodes return nodes{*} limit 5", nil)
nodes, schemas, _ := resp.Alias("nodes").AsNodes()
firstNode, _ := resp.Alias("nodes").AsFirstNode()
printers.PrintNodes(nodes, schemas)
fmt.Println("ID of 2nd node is: ", nodes[1].GetID())
fmt.Println("rating of 1st node was: ", firstNode.Get("rating"))
firstNode.Set("rating", int32(8))
fmt.Println("rating of 1st node now is: ", firstNode.Get("rating"))
}
输出:
+------------------------+------+--------+--------+------+
| ID | UUID | Schema | rating | year |
+------------------------+------+--------+--------+------+
| ULTIPA80000000000003E9 | 1001 | movie | 9 | 1994 |
| ULTIPA80000000000003EA | 1002 | movie | 7 | 1993 |
| ULTIPA80000000000003EB | 1003 | movie | 6 | 1998 |
| ULTIPA80000000000003EC | 1004 | movie | 9 | 1994 |
| ULTIPA80000000000003ED | 1005 | movie | 9 | 1997 |
+------------------------+------+--------+--------+------+
ID of 2nd node is: ULTIPA80000000000003EA
rating of 1st node was: 9
rating of 1st node now is: 8
Edge
structs.Edge的字段:
字段 | 类型 | 说明 |
---|---|---|
From | types.ID | Edge起点的ID |
To | types.ID | Edge终点的ID |
FromUUID | types.UUID | Edge起点的UUID |
ToUUID | types.UUID | Edge终点的UUID |
UUID | types.UUID | Edge的UUID |
Schema | string | Edge的Schema |
Values | *Value | Edge的自定义属性 |
Name | string | Edge的别名 |
structs.Edge的方法:
方法 | 类型 | 说明 |
---|---|---|
GetFrom() | types.ID | 获取当前Edge起点的ID |
GetTo() | types.ID | 获取当前Edge终点的ID |
GetUUID() | types.UUID | 获取当前Edge的UUID |
GetSchema() | string | 获取当前Edge的Schema |
GetValues() | *Value | 获取当前Edge的Values(自定义属性) |
Get(key string) | interface{} | 获取当前Edge的某个自定义属性 |
GetBytes(key string) | []byte, error | 获取当前Edge的某个自定义属性的字节数组 |
Set(key string, value interface{}) | error | 设置当前Edge的某个自定义属性,属性名不存在时将则添加该键值对 |
示例:发送嬴图GQL语句查询一列边,获取第二个边的起点的ID,为第一个边添加属性value并设置为8
func TestMisc(t *testing.T) {
// 创建名为conn的连接,此部分代码省略
resp, _ := conn.UQL("find().edges({@default}) as edges return edges{*} limit 5", nil)
edges, schemas, _ := resp.Alias("edges").AsEdges()
firstEdge, _ := resp.Alias("edges").AsFirstEdge()
printers.PrintEdges(edges, schemas)
fmt.Println("ID of start node of 2nd edge is: ", edges[1].GetFrom())
fmt.Println("value of 1st edge was: ", firstEdge.Get("value"))
firstEdge.Set("value", int32(8))
fmt.Println("value of 1st edge now is: ", firstEdge.Get("value"))
}
输出:
+------+------------------------+------------------------+---------+
| UUID | FROM | TO | SCHEMA |
+------+------------------------+------------------------+---------+
| 21 | ULTIPA0000003 | ULTIPA0000004 | default |
| 24 | ULTIPA8000000000000001 | ULTIPA8000000000000002 | default |
| 29 | ULTIPA800000000000001A | ULTIPA800000000000001B | default |
+------+------------------------+------------------------+---------+
ID of start node of 2nd edge is: ULTIPA8000000000000001
value of 1st edge was: <nil>
value of 1st edge now is: 8
Path
structs.Path的字段:
字段 | 类型 | 说明 |
---|---|---|
Nodes | []*Node | Path中的*Node列表 |
Edges | []*Edge | Path中的*Edge列表 |
NodeSchemas | map[string]*Schema | Path中的所有点 *Schema的映射 |
EdgeSchemas | map[string]*Schema | Path中的所有边*Schema的映射 |
Name | string | Path的别名 |
structs.Path的方法:
方法 | 类型 | 说明 |
---|---|---|
GetLength() | int | 获取当前Path的长度,即Edge的数量 |
GetNodes() | []*Node | 获取当前Path的*Node列表 |
GetEdges() | []*Edge | 获取当前Path的*Edge列表 |
GetLastNode() | *Node | 获取当前Path的最后一个*Node |
示例:发送嬴图GQL语句查询一列路径,获取第一个路径的点列
func TestMisc(t *testing.T) {
// 创建名为conn的连接,此部分代码省略
resp, _ := conn.UQL("n().e()[2].n() as paths return paths{*} limit 3", nil)
paths, _ := resp.Alias("paths").AsPaths()
printers.PrintPaths(paths)
printers.PrintNodes(paths[0].GetNodes(), paths[0].NodeSchemas)
}
输出:
+---+---------------------------------------------------------+
| # | Path |
+---+---------------------------------------------------------+
| 0 | (CARD00001) <- [14] - (CARD00020) <- [25] - (CARD00019) |
| 1 | (CARD00001) <- [39] - (CARD00024) <- [22] - (CARD00045) |
| 2 | (CARD00001) <- [53] - (CARD00022) <- [13] - (CARD00042) |
+---+---------------------------------------------------------+
+-----------+------+---------+----------+-------+
| ID | UUID | Schema | balance | level |
+-----------+------+---------+----------+-------+
| CARD00001 | 1 | default | 4245.3 | 3 |
| CARD00020 | 20 | default | 2564.0 | 2 |
| CARD00019 | 19 | default | 244.8 | 2 |
+-----------+------+---------+----------+-------+
Graph
structs.Graph的字段:
字段 | 类型 | 说明 |
---|---|---|
ID | types.ID | Graph的ID |
Name | string | Graph的名称 |
Description | string | Graph的描述 |
TotalNodes | uint64 | Graph的点数量 |
TotalEdges | uint64 | Graph的边数量 |
Status | string | Graph的状态(MOUNTED、UNMOUNTED) |
示例:发送嬴图GQL语句查询图集列表
func TestMisc(t *testing.T) {
// 创建名为conn的连接,此部分代码省略
resp, _ := conn.UQL("show().graph()", nil)
graphs, _ := resp.Alias("_graph").AsGraphs()
printers.PrintGraph(graphs)
}
输出:
+----------------+-------------+------------+------------+-----------+
| Name | Description | Total Node | Total Edge | Status |
+----------------+-------------+------------+------------+-----------+
| DeliveryCenter | | 30 | 77 | MOUNTED |
| GithubSocial | | 37700 | 289003 | MOUNTED |
| HB_POC | | 0 | 0 | UNMOUNTED |
| Industry | | 0 | 0 | MOUNTED |
+----------------+-------------+------------+------------+-----------+
Schema
structs.Schema的字段:
字段 | 类型 | 说明 |
---|---|---|
Name | string | Schema的名称 |
Properties | []*Property | Schema的*Property列表 |
Desc | string | Schema的描述 |
Type | string | Schema的点/边类型 |
DBType | ultipa.DBType | Schema的点/边类型 |
Total | int | Schema的点/边数量 |
structs.Schema的方法:
方法 | 类型 | 说明 |
---|---|---|
GetProperty(name string) | *Property | 按名称获取当前Schema的某个*Property |
示例:发送嬴图GQL语句查询当前图集的点schema列表
func TestMisc(t *testing.T) {
// 创建名为conn的连接,此部分代码省略
resp, _ := conn.UQL("show().node_schema()", nil)
nodeSchemas, _ := resp.Alias("_nodeSchema").AsSchemas()
printers.PrintSchema(nodeSchemas)
}
输出:
Schema Name: default ( 3 )
Description: default schema
-
Schema Name: movie ( 92 )
Description:
+-----------+-------------+-----------+-------+--------+
| Name | Description | Type | LTE | Schema |
+-----------+-------------+-----------+-------+--------+
| note | | string | false | movie |
| frating | | float | false | movie |
| timestamp | | timestamp | false | movie |
| drating | | double | false | movie |
| genre | | string | false | movie |
| datetime | | datetime | false | movie |
| name | | string | false | movie |
| rating | | int32 | false | movie |
| year | | int32 | true | movie |
+-----------+-------------+-----------+-------+--------+
-
Schema Name: country ( 23 )
Description:
+------+-------------+--------+-------+---------+
| Name | Description | Type | LTE | Schema |
+------+-------------+--------+-------+---------+
| name | | string | false | country |
+------+-------------+--------+-------+---------+
-
Property
structs.Property的字段:
字段 | 类型 | 说明 |
---|---|---|
Name | string | Property的名称 |
Desc | string | Property的描述 |
Schema | string | Property的Schema |
Type | ultipa.PropertyType | Property的数据类型 |
Lte | bool | Property的LTE状态(true、false) |
示例:发送嬴图GQL语句查询当前图集的点属性列表
func TestMisc(t *testing.T) {
// 创建名为conn的连接,此部分代码省略
resp, _ := conn.UQL("show().node_property()", nil)
nodeProperties, _ := resp.Alias("_nodeProperty").AsProperties()
printers.PrintProperty(nodeProperties)
}
输出:
+-----------+-------------+-----------+-------+-----------+
| Name | Description | Type | LTE | Schema |
+-----------+-------------+-----------+-------+-----------+
| note | | string | false | movie |
| frating | | float | false | movie |
| timestamp | | timestamp | false | movie |
| drating | | double | false | movie |
| genre | | string | false | movie |
| datetime | | datetime | false | movie |
| name | | string | false | movie |
| rating | | int32 | false | movie |
| year | | int32 | true | movie |
| name | | string | false | country |
| name | | string | false | celebrity |
| name | | string | false | account |
| industry | | string | false | account |
| gender | | string | false | account |
| year | | int32 | true | account |
+-----------+-------------+-----------+-------+-----------+
Algo
structs.Algo的字段:
字段 | 类型 | 说明 |
---|---|---|
Name | string | Algo的名称 |
Desc | string | Algo的描述 |
Version | string | Algo的版本 |
Params | map[string]*AlgoParam | Algo的参数列表 |
structs.Algo的方法:
方法 | 类型 | 说明 |
---|---|---|
ParamsToString() | string | 将当前Algo的Params转换成字符串 |
示例:发送嬴图GQL语句查询已安装的算法列表
func TestMisc(t *testing.T) {
// 创建名为conn的连接,此部分代码省略
resp, _ := conn.UQL("show().algo()", nil)
algos, _ := resp.Alias("_algoList").AsAlgos()
printers.PrintAlgoList(algos)
}
输出:
+-------------------+-------------------------------------+---------+----------------------------------------------------------+
| Algo Name | Description | Version | Parameters |
+-------------------+-------------------------------------+---------+----------------------------------------------------------+
| triangle_counting | triangle counting | 1.0.2 | type : 1:count by edge 2:count by node |
| | | | limit : -1 for all triples |
| | | | result_type : 1:only number 2:triangles |
| | | | |
| sybil_rank | sybil rank | 1.0.1 | trust_seeds : array of nodes,required |
| | | | loop_num : size_t,required |
| | | | limit : optional,-1 for all results, >=0 partial results |
| | | | total_trust : float,required |
| | | | |
| subgraph | subgraph generated by certain nodes | 1.0.2 | ids : array of nodes,required |
| | | | limit : optional,-1 for all results, >=0 partial results |
| | | | |
+-------------------+-------------------------------------+---------+----------------------------------------------------------+
Table
structs.Table的字段:
字段 | 类型 | 说明 |
---|---|---|
Name | string | Table的别名 |
Headers | []*Property | Table的表头列表 |
Rows | []*Row | Table的所有行列表 |
structs.Table的方法:
方法 | 类型 | 说明 |
---|---|---|
GetHeaders() | []*Property | 获取当前Table的表头列表 |
GetRows() | []*Row | 获取当前Table的所有行列表 |
ToKV() | []*Values | 将当前Table转换为KV列表 |
示例:发送嬴图GQL语句查询一个表格,获取该表格表头及第二行数据
func TestMisc(t *testing.T) {
// 创建名为conn的连接,此部分代码省略
resp, _ := conn.UQL("find().nodes({@account}) limit 5 return table(nodes.gender, nodes.year) as myTable", nil)
table, _ := resp.Alias("myTable").AsTable()
printers.PrintTable(table)
printers.PrintProperty(table.GetHeaders())
fmt.Println(*table.GetRows()[0])
}
输出:
+--------------+------------+
| nodes.gender | nodes.year |
+--------------+------------+
| female | 1978 |
| female | 1989 |
| male | 1982 |
| female | 2007 |
| male | 1973 |
+--------------+------------+
+--------------+-------------+--------+-------+--------+
| Name | Description | Type | LTE | Schema |
+--------------+-------------+--------+-------+--------+
| nodes.gender | | string | false | |
| nodes.year | | int32 | false | |
+--------------+-------------+--------+-------+--------+
[female 1978]
Attr
structs.Attr的字段:
字段 | 类型 | 说明 |
---|---|---|
Name | string | Attr的别名 |
Rows | Row | Attr的列表 |
PropertyType | ultipa.PropertyType | Attr的类型 |
示例:发送嬴图GQL语句查询一列属性,获取第二个属性
func TestMisc(t *testing.T) {
// 创建名为 onn的连接,此部分代码省略
resp, _ := conn.UQL("find().nodes({@account}) as nodes return nodes.industry as myAttr limit 5", nil)
attribute, _ := resp.Alias("myAttr").AsAttr()
printers.PrintAttr(attribute)
fmt.Println("2nd attr is: ", attribute.Rows[1])
}
输出:
+---------------+
| myAttr |
+---------------+
| Manufacturing |
| Health |
| Other |
| Education |
| Publishing |
+---------------+
2nd attr is: Health