返回值的结构化 您所在的位置:网站首页 pagerank时间复杂度 返回值的结构化

返回值的结构化

2022-12-18 01:33| 来源: 网络整理| 查看: 265

DataItem

DataItem 是使用 UQLResponse 类的 get()、alias() 方法时返回的别名类。

DataItem 的方法:

方法 类型 说明 AsNodes() []*structs.Node, map[string]*structs.Schema, error 将 NODE 类型的 *DataItem 转换成 *structs.Node 列表、*structs.Schema 映射等 AsFirstNode() *structs.Node, error 取出 NODE 类型的 *DataItem 中的第一个 *structs.Node AsEdges() []*structs.Edge, map[string]*structs.Schema, error 将 EDGE 类型的 *DataItem 转换成 *structs.Edge 列表、*structs.Schema 映射等 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 AsArray() *structs.Array, error 将 ARRAY 类型的 *DataItem 转换成 *structs.Array AsAttr() *structs.Attr, error 将 ATTR 类型的 *DataItem 转换成 *structs.Attr 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 的某个自定义属性,属性名不存在时将则添加该键值对

示例:发送 UQL 语句查询一列点,获取第二个点的 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 的某个自定义属性,属性名不存在时将则添加该键值对

示例:发送 UQL 语句查询一列边,获取第二个边的起点的 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: 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

示例:发送 UQL 语句查询一列路径,获取第一个路径的点列

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)


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有