DataItem
Using methods get()
and alias()
of Response will return struct DataItem.
DataItem has below methods:
Method | Type | Description |
---|---|---|
AsNodes() | []*structs.Node, map[string]*structs.Schema, error | convert *DataItem of NODE type to []*structs.Node, map[string]*structs.Schema, etc. |
AsFirstNode() | *structs.Node, error | acquire the first *structs.Node from *DataItem of NODE type |
AsEdges() | []*structs.Edge, map[string]*structs.Schema, error | convert *DataItem of EDGE type to []*structs.Edge, map[string]*structs.Schema, etc. |
AsFirstEdge() | *structs.Edge, error | acquire the first *structs.Edge from *DataItem of EDGE type |
AsPaths() | []*structs.Path, error | convert *DataItem of PATH type to []*structs.Path |
AsGraphs() | []*structs.Graph, error | convert *DataItem with alias _graph to []*structs.Graph |
AsSchemas() | []*structs.Schema, error | convert *DataItem with alias _nodeSchema, _edgeSchema to []*structs.Schema |
AsProperties() | []*structs.Property, error | convert *DataItem with alias _nodeProperty, _edgeProperty to []*structs.Property |
AsAlgos() | []*structs.Algo, error | convert *DataItem with alias _algoList to []*structs.Algo |
AsTable() | *structs.Table, error | convert *DataItem of TABLE type to *structs.Table |
AsArray() | *structs.Array, error | convert *DataItem of ARRAY type to *structs.Array |
AsAttr() | *structs.Attr, error | convert *DataItem of ATTR type to *structs.Attr |
It is also legal to convert *DataItem with alias _graph, _nodeSchema, _edgeSchema, etc., to *structs.Table using method
asTable()
.
Node
structs.Node has below fields:
Field | Type | Description |
---|---|---|
ID | types.ID | Node ID |
UUID | types.UUID | Node UUID |
Schema | string | Node Schema |
Values | *Value | Node customer properties |
Name | string | Node alias |
structs.Node has below methods:
Method | Type | Description |
---|---|---|
GetID() | types.ID | acquire ID of current Node |
GetUUID() | types.UUID | acquire UUID of current Node |
GetSchema() | string | acquire Schema of current Node |
GetValues() | *Value | acquire Values (custom properties) of current Node |
Get(key string) | interface{} | acquire a custom property of current Node |
GetBytes(key string) | []byte, error | acquire the []byte of a custom property of current Node |
Set(key string, value interface{}) | error | set a custom property of current Node, or add KV pair if 'key' is not an existing key |
Example: Send UQL query for a node list, print the ID of 2nd node, and set 'rating' of the 1st node to 8
func TestMisc(t *testing.T) {
// omit code of establishing server connection '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"))
}
Output:
+------------------------+------+--------+--------+------+
| 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 has below fields:
Field | Type | Description |
---|---|---|
From | types.ID | Edge start node ID |
To | types.ID | Edge end node ID |
FromUUID | types.UUID | Edge start node UUID |
ToUUID | types.UUID | Edge end node UUID |
UUID | types.UUID | Edge UUID |
Schema | string | Edge Schema |
Values | *Value | Edge customer properties |
Name | string | Edge alias |
structs.Edge has below methods:
Method | Type | Description |
---|---|---|
GetFrom() | types.ID | acquire ID of start node of current Edge |
GetTo() | types.ID | acquire ID of end node of current Edge |
GetUUID() | types.UUID | acquire UUID of current Edge |
GetSchema() | string | acquire Schema of current Edge |
GetValues() | *Value | acquire Values (custom properties) of current Edge |
Get(key string) | interface{} | acquire a custom property of current Edge |
GetBytes(key string) | []byte, error | acquire the []byte of a custom property of current Edge |
Set(key string, value interface{}) | error | set a custom property of current Edge, or add KV pair if 'key' is not an existing key |
Example: Send UQL query for an edge list, print the ID of the start node of the 2nd edge, and add 'value' for the 1st edge and set to 8
func TestMisc(t *testing.T) {
// omit code of establishing server connection '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"))
}
Output:
+------+------------------------+------------------------+---------+
| 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 has below fields:
Field | Type | Description |
---|---|---|
Nodes | []*Node | []*Node of Path |
Edges | []*Edge | []*Edge of Path |
NodeSchemas | map[string]*Schema | Map of all node *Schema of Path |
EdgeSchemas | map[string]*Schema | Map of all edge *Schema of Path |
Name | string | Path alias |
structs.Path has below methods:
Method | Type | Description |
---|---|---|
GetLength() | int | acquire length of current Path, namely the number of Edge |
GetNodes() | []*Node | acquire []*Node of current Path |
GetEdges() | []*Edge | acquire []*Edge of current Path |
GetLastNode() | *Node | acquire the last *Node of current Path |
Example: Send UQL query for a path list, print the node list of the 1st path
func TestMisc(t *testing.T) {
// omit code of establishing server connection '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)
}
Output:
+---+---------------------------------------------------------+
| # | 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 has below fields:
Field | Type | Description |
---|---|---|
ID | types.ID | Graph ID |
Name | string | Graph name |
Description | string | Graph description |
TotalNodes | uint64 | Graph total number of nodes |
TotalEdges | uint64 | Graph total number of edges |
Status | string | Graph status (MOUNTED or UNMOUNTED) |
Example: Send UQL query for a graph list, print the graph table
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
resp, _ := conn.UQL("show().graph()", nil)
graphs, _ := resp.Alias("_graph").AsGraphs()
printers.PrintGraph(graphs)
}
Output:
+----------------+-------------+------------+------------+-----------+
| 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 has below fields:
Field | Type | Description |
---|---|---|
Name | string | Schema name |
Properties | []*Property | []*Property of Schema |
Desc | string | Schema description |
Type | string | Schema type (Node or Edge) |
DBType | ultipa.DBType | Schema type (Node or Edge) |
Total | int | Schema total number of nodes/edges |
structs.Schema has below methods:
Method | Type | Description |
---|---|---|
GetProperty(name string) | *Property | acquire a *Property of current Schema by name |
Example: Send UQL query for the node schema list, print the schema table
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
resp, _ := conn.UQL("show().node_schema()", nil)
nodeSchemas, _ := resp.Alias("_nodeSchema").AsSchemas()
printers.PrintSchema(nodeSchemas)
}
Output:
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 has below fields:
Field | Type | Description |
---|---|---|
Name | string | Property name |
Desc | string | Property description |
Schema | string | Property Schema |
Type | ultipa.PropertyType | Property data type |
Lte | bool | Property LTE status (true or false) |
Example: Send UQL query for the node property list, print the property table
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
resp, _ := conn.UQL("show().node_property()", nil)
nodeProperties, _ := resp.Alias("_nodeProperty").AsProperties()
printers.PrintProperty(nodeProperties)
}
Output:
+-----------+-------------+-----------+-------+-----------+
| 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 has below fields:
Field | Type | Description |
---|---|---|
Name | string | Algo name |
Desc | string | Algo description |
Version | string | Algo version |
Params | map[string]*AlgoParam | Algo parameters |
structs.Algo has below methods:
Method | Type | Description |
---|---|---|
ParamsToString() | string | convert Params of current Algo to string |
Example: Send UQL query for the installed algorithm list, print the algorithm table
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
resp, _ := conn.UQL("show().algo()", nil)
algos, _ := resp.Alias("_algoList").AsAlgos()
printers.PrintAlgoList(algos)
}
Output:
+-------------------+-------------------------------------+---------+----------------------------------------------------------+
| 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 has below fields:
Field | Type | Description |
---|---|---|
Name | string | Table alias |
Headers | []*Property | Table headers |
Rows | []*Row | Table rows |
structs.Table has below methods:
Method | Type | Description |
---|---|---|
GetHeaders() | []*Property | acquire current Table headers |
GetRows() | []*Row | acquire current Table rows |
ToKV() | []*Values | convert current Table to KV list |
Example: Send UQL query for a table, print the headers and the 2nd row:
func TestMisc(t *testing.T) {
// omit code of establishing server connection '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])
}
Output:
+--------------+------------+
| 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]
Array
structs.Array has below fields:
Field | Type | Description |
---|---|---|
Name | string | Array alias |
Rows | []*Row | Array rows |
Example: Send UQL query for an array list, print the 3rd element of the 2nd array
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
resp, _ := conn.UQL("find().nodes({@account}) as nodes group by nodes.industry return collect(nodes.name) as myArray limit 3", nil)
array, _ := resp.Alias("myArray").AsArray()
printers.PrintArray(array)
fmt.Println("3rd element of 2nd array is: ", (*array.Rows[1])[2])
}
Output:
+-------------------------------------------------------------+
| myArray |
+-------------------------------------------------------------+
| ["jibber-jabber", "jo", "CR.", "laofung", "pepe"] |
| ["Meng", "HolyC", "pixiedust", "sadmov"] |
| ["Unbeliever", "Ivo", "Nannobrycon", "auric", "Blair_self"] |
+-------------------------------------------------------------+
3rd element of 2nd array is: pixiedust
Attr
structs.Attr has below fields:
Field | Type | Description |
---|---|---|
Name | string | Attr alias |
Rows | Row | Attr rows |
PropertyType | ultipa.PropertyType | Attr type |
Example: Send UQL query for an attribute list, print the 2nd attribute
func TestMisc(t *testing.T) {
// omit code of establishing server connection 'conn'
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])
}
Output:
+---------------+
| myAttr |
+---------------+
| Manufacturing |
| Health |
| Other |
| Education |
| Publishing |
+---------------+
2nd attr is: Health