UltipaDocs
Try Playground
  • Introduction
  • RESTful API
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
    • Installation
    • Connection
      • Request Configuration
      • Querying Methods
      • UQL Execution
      • Graphset Management
      • Schema and Property Management
      • Data Insertion and Deletion
      • Query Acceleration
      • Algorithm Management
      • Downloads and Exports
      • Process and Task Management
      • Access Management
      • Others
    • Result Processing
    • Types Mapping
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Go

Types Mapping Ultipa and Go

Mapping Methods

The Get() or Alias() method of the Response class returns a DataItem, which embeds the query result. You should use the As<Type>() method of DataItem to cast the result to the appropriate driver type.

Go
myQuery, _ := conn.Uql("find().nodes() as n return n{*} limit 5", requestConfig)
nodeList, schemaList, _ := myQuery.Alias("n").AsNodes()
printers.PrintNodes(nodeList, schemaList)

The result n coming from the database contains five nodes, each of the NODE type. The AsNodes() method converts them as a list of Node objects.

Type mapping methods available on DataItem:

UQL TypeUQL AliasMethodDriver Type
Description
NODEAnyAsNodes()[]NodeMaps NODE-type DataItem to a list of Node objects.
NODEAnyAsFirstNode()NodeMaps the first node in a NODE-type DataItem to a Node object.
EDGEAnyAsEdges()[]EdgeMaps EDGE-type DataItem to a list of Edge objects.
EDGEAnyAsFirstEdge()EdgeMaps the first edge in an EDGE-type DataItem to an Edge object.
PATHAnyAsPaths()Path[]Maps PATH-type DataItem to a list of Path objects.
GRAPHAnyAsGraph()GraphMaps GRAPH-type DataItem to a Graph object.
TABLE_graphAsGraphSets()[]GraphSetMaps DataItem with the alias _graph to a list of GraphSet objects.
TABLE_nodeSchema, _edgeSchemaAsSchemas()[]SchemaMaps DataItem with the alias _nodeSchema or _edgeSchema to a list of Schema objects.
TABLE_nodeProperty, _edgePropertyAsProperties()[]PropertyMaps DataItem with the alias _nodeProperty or _edgeProperty to a list of Property objects.
TABLE_algoListAsAlgos()[]AlgoMaps DataItem with the alias _algoList to a list of Algo objects.
TABLE_extaListAsExtas()[]ExtaMaps DataItem with the alias _extaList to a list of Exta objects.
TABLE_nodeIndex, _edgeIndexAsIndexes()[]IndexMaps DataItem with the alias _nodeIndex or _edgeIndex to a list of Index objects.
TABLE_nodeFulltext, _edgeFulltextAsFullTexts()[]IndexMaps DataItem with the alias _nodeFulltext or _edgeFulltext to a list of Index objects.
TABLE_privilegeAsPriviliege()[]PriviliegeMaps DataItem with the alias _privilege to a Priviliege object.
TABLE_policyAsPolicies()[]PolicyMaps DataItem with the alias _policy to a list of Policy objects.
TABLE_userAsUsers()[]UserMaps DataItem with the alias _user to a list of User objects.
TABLE_statisticAsStats()StatMaps DataItem with the alias _statistic to a Stat object.
TABLE_topAsTops()[]TopMaps DataItem with the alias _top to a list of Process objects.
TABLE_taskAsTasks()[]TaskMaps DataItem with the alias _task to a list of Task objects.
TABLEAnyAsTable()TableMaps TABLE-type DataItem to a Table object.
ATTRAnyAsAttr()AttrMaps ATTR-type DataItem to an Attr object.

Driver Types

NOTE

Objects of all driver types support getter methods to retrieve the value of a field and setter methods to set the value of a field, even if they are not explicitly listed below.

Node

A Node object has the following fields:

FieldType
Description
NamestringAlias name
IDstringNode ID
UUIDuint64Node UUID
SchemastringNode Schema
ValuesobjectNode custom properties

Methods on a Node object:

Method
Return
Description
get("<propertyName>")ObjectGet value of the given custom property of the node.
set("<propertyName>", <propertyValue>Set value for the given custom property of the node; or add a key-value pair to the Values of the node if the given <propertyName> does not exist.
Go
myQuery, _ := conn.Uql("find().nodes() as n return n{*} limit 5", requestConfig)
nodeList, _, _ := myQuery.Alias("n").AsNodes()

println("ID of the 1st node:", nodeList[0].GetID())
println("Name of the 1st node:", nodeList[0].GetSchema())
Output
ID of the 1st node: ULTIPA8000000000000001
Name of the 1st node: account

Edge

An Edge object has the following fields:

FieldType
Description
NamestringAlias name
FromstringStart node ID of the edge
TostringEnd node ID of the edge
FromUUIDuint64Start node UUID of the edge
ToUUIDuint64End node UUID of the edge
UUIDuint64Edge UUID
SchemastringEdge Schema
valuesobjectEdge custom properties

Methods on an Edge object:

Method
Return
Description
get("<propertyName>")ObjectGet value of the given custom property of the edge.
set("<propertyName>", <propertyValue>Set value for the given custom property of the edge; or add a key-value pair to the values of the edge if the given <propertyName> does not exist.
Go
myQuery, _ := conn.Uql("find().edges() as e return e{*} limit 5", requestConfig)
edgeList, _ := myQuery.Alias("e").AsFirstEdge()

println("Values of the 1st edge:", utils.JSONString(edgeList.GetValues()))
Output
Values of the 1st edge: {"Data":{"datetime":{"Datetime":1847052190913396736,"Year":2019,"Month":1,"Day":6,"Hour":2,"Minute":57,"Second":57,"Macrosec":0,"Time":"2019-01-06T02:57:57Z"},"targetPost":703,"timestamp":{"Datetime":1847052190913396736,"Year":2019,"Month":1,"Day":6,"Hour":2,"Minute":57,"Second":57,"Macrosec":0,"Time":"2019-01-06T02:57:57+08:00"}}}

Path

A Path object has the following fields:

Field
Type
Description
NamestringAlias name
Nodes[]NodeNode list of the path
Edges[]EdgeEdge list of the path
NodeSchemasobjectInfomation of node schema
EdgeSchemasobjectInfomation of edge schema
Go
myQuery, _ := conn.Uql("n().e()[:2].n() as paths return paths{*} limit 5", requestConfig)
pathList, _ := myQuery.Alias("paths").AsPaths()

println("Length of the 1st path:", pathList[0].GetLength())
println("Edge list of the 1st path:", "\n", utils.JSONString(pathList[0].GetEdges()))
println("Information of the 2nd node in the 1st path:", "\n", utils.JSONString(pathList[0].GetNodes()[1]))
Output
Length of the 1st path: 2
Edge list of the 1st path: 
 [{"Name":"paths","From":"u_10032","To":"u_105","FromUUID":27,"ToUUID":1,"UUID":2784,"Schema":"follow","Values":{"Data":{}}},{"Name":"paths","From":"u_10071","To":"u_10032","FromUUID":33,"ToUUID":27,"UUID":2876,"Schema":"follow","Values":{"Data":{}}}]
Information of the 2nd node in the 1st path: 
 {"Name":"paths","ID":"u_10032","UUID":27,"Schema":"account","Values":{"Data":{"birthYear":1988,"fRate":null,"gender":"male","industry":"Transportation","name":"floatingnote","new":null,"new1":null,"new2":null,"records":null,"tags":null}}}

Graph

A Graph object has the following fields:

Field
Type
Description
NamestringAlias name
Nodes[]NodeNode list of the path
Edges[]EdgeEdge list of the path
NodeSchemasobjectMap of all node schemas of the path
EdgeSchemasobjectMap of all edge schemas of the path
Go
myQuery, _ := conn.Uql("n(as n1).re(as e).n(as n2).limit(3) with toGraph(collect(n1), collect(n2), collect(e)) as graph return graph", requestConfig)
resp, _ := myQuery.Alias("graph").AsGraph()

println("Node IDs:")
for _, item := range resp.Nodes {
  println(item.ID)
}
println("Edge UUIDs:")
for _, item := range resp.Edges {
  println(item.UUID)
}
Output
Node IDs:
ad304833
u604131
ad534784
ad6880
Edge UUIDs:
363347
774098
527786
3

GraphSet

A GraphSet object has the following fields:

Field
Type
Description
IDstringGraphset ID
NamestringGraphset name
DescriptionstringGraphset description
TotalNodesstringTotal number of nodes in the graphset
TotalEdgesstringTotal number of edges in the graphset
StatusstringGraphset status (MOUNTED, MOUNTING, or UNMOUNTED)
Go
myQuery, _ := conn.Uql("show().graph()", nil)
resp, _ := myQuery.Alias("_graph").AsGraphSets()

for _, item := range resp {
  if item.Status == "UNMOUNTED" {
    println(item.Name)
  }
}
Output
DFS_EG
cyber
cyber2

Schema

A Schema object has the following fields:

Field
Type
Description
NamestringSchema name
Properties[]PropertyProperty list of the schema
DescstringSchema description
TypestringType of the schema (node or edge)
DBTypeDBTypeType of the schema (node or edge)
TotalintTotal number of nodes/edges of the schema
Go
myQuery, _ := conn.Uql("show().node_schema()", requestConfig)
resp, _ := myQuery.Alias("_nodeSchema").AsSchemas()

for _, item := range resp {
  println(item.Name, "has", item.Total, "nodes")
}
Output
default has 0 nodes
user has 1092511 nodes
ad has 846811 nodes

Property

A Property object has the following fields:

Field
Type
Description
NamestringProperty name
DescstringProperty description
LteboolProperty LTE status
SchemastringAssociated schema of the property
TypePropertyTypeProperty data type
SubTypes[]PropertyTypeList of property data type
ExtrastringExtra information of properties
Go
myQuery, _ := conn.Uql("show().node_property(@user)", requestConfig)
resp, _ := myQuery.Alias("_nodeProperty").AsProperties()

for _, item := range resp {
  if item.Lte {
    println("LTE-ed property name:", item.Name)
  }
}
Output
LTE-ed property name: occupation

Algo

An Algo object has the following fields:

Field
Type
Description
NamestringAlgorithm name
DescstringAlgorithm description
VersionstringAlgorithm version
ParamsobjectParameters of the algorithm
Go
myQuery, _ := conn.Uql("show().algo()", requestConfig)
resp, _ := myQuery.Alias("_algoList").AsAlgos()

println(utils.JSONString(resp[0]))
Output
{"Name":"bipartite","Desc":"bipartite check","Version":"1.0.1","Params":{}}

Exta

NOTE

An exta is a custom algorithm developed by users.

An Exta object has the following fields:

Field
Type
Description
NamestringExta name
AuthorstringExta author
VersionstringExta version
DetailstringContent of the YML configuration file of the Exta
Go
myQuery, _ := conn.Uql("show().exta()")
resp, _ := myQuery.Alias("_extaList").AsExtas()

println("Exta name:", utils.JSONString(resp[0].Name))
Output
Exta name: "page_rank"

Index

An Index object has the following fields:

Field
Type
Description
NamestringIndex name
PropertiesstringProperty name of the index
SchemastringSchema name of the index
StatusstringIndex status (done or creating)
SizestringIndex size in bytes
TypestringIndex type (DBNODE or DBEDGE)
Go
myQuery, _ := conn.Uql("show().index()", requestConfig)
resp, _ := myQuery.Alias("_nodeIndex").AsIndexes()

for i := 0; i < len(resp); i++ {
  println("Schema name:", resp[i].Schema)
  println("Properties:", resp[i].Properties)
  println("Size:", resp[i].Size)
}
Output
Schema name: user
Properties: shopping_level
Size: 4608287
Schema name: ad
Properties: price
Size: 7828760

Full-text

A FullText object has the following fields:

Field
Type
Description
NamestringIndex name
PropertiesstringProperty name of the index
SchemastringSchema name of the index
StatusstringIndex status (done or creating)
SizestringIndex size in bytes
TypestringIndex type (DBNODE or DBEDGE)
Go
myQuery, _ := conn.Uql("show().fulltext()", requestConfig)
resp, _ := myQuery.Alias("_edgeFulltext").AsFullTexts()

for i := 0; i < len(resp); i++ {
  println("Fulltext name:", resp[i].Name)
  println("Schema name:", resp[i].Schema)
  println("Properties:", resp[i].Properties)
}
Output
Fulltext name: nameFull
Schema name: review
Properties: content

Privilege

A Privilege object has the following fields:

Field
Type
Description
GraphPrivileges[]stringGraph privileges
SystemPrivileges[]stringSystem privileges
Go
myQuery, _ := conn.Uql("show().privilege()", requestConfig)
resp, _ := myQuery.Alias("_privilege").AsPrivilege()

println(utils.JSONString(resp[0].SystemPrivileges))
Output
["TRUNCATE","COMPACT","CREATE_GRAPH","SHOW_GRAPH","DROP_GRAPH","ALTER_GRAPH","MOUNT_GRAPH","UNMOUNT_GRAPH","TOP","KILL","STAT","SHOW_POLICY","CREATE_POLICY","DROP_POLICY","ALTER_POLICY","SHOW_USER","CREATE_USER","DROP_USER","ALTER_USER","GRANT","REVOKE","SHOW_PRIVILEGE"]

Policy

A Policy object has the following fields:

Field
Type
Description
NamestringPolicy name
GraphPrivilegesGraphPrivilegesGraph privileges and the corresponding graphsets included in the policy
SystemPrivileges[]stringSystem privileges included in the policy
PropertyPrivilegesPropertyPrivilegesProperty privileges included in the policy
Policies[]stringPolicies included in the policy
Go
myQuery, _ := conn.Uql("show().policy()", requestConfig)
resp, _ := myQuery.Alias("_policy").AsPolicies()

for i := 0; i < len(resp); i++ {
  println(resp[i].Name)
}
Output
operator
manager

User

A User object has the following fields:

Field
Type
Description
UsernamestringUsername
PasswordstringPassword
CreatestringWhen the user was created
GraphPrivilegesGraphPrivilegesGraph privileges and the corresponding graphsets granted to the user
SystemPrivileges[]stringSystem privileges granted to the user
Policies[]stringPolicies granted to the user
PropertyPrivilegesPropertyPrivilegesProperty privileges granted to the user
Go
myQuery, _ := conn.Uql("show().user('Tester')", requestConfig)
resp, _ := myQuery.Alias("_user").AsUsers()

println("Username:", resp[0].UserName)
println("Created at:", resp[0].Create)
println("Graph privileges:", utils.JSONString(resp[0].GraphPrivileges))
println("System privileges:", utils.JSONString(resp[0].SystemPrivileges))
println("Property privileges:", utils.JSONString(resp[0].PropertyPrivileges))
Output
Username: Tester
Created at: 1970-01-01 08:00:00
Graph privileges: {"Ad_Click":["FIND_EDGE","FIND_NODE"],"DFS_EG":["UPDATE","INSERT"]}
System privileges: ["MOUNT_GRAPH"]
Property privileges: {"edge":{"deny":[],"read":[],"write":[]},"node":{"deny":[],"read":[],"write":[["miniCircle","account","name"]]}}

Stats

A Stat object has the following fields:

Field
Type
Description
CPUUsagestringCPU usage in percentage
MemUsagestringMemory usage in megabytes
ExpiredDatestringExpiration date of the license
CPUCoresstringNumber of CPU cores
CompanystringCompany name
ServerTypestringServer type
VersionstringVersion of the server
Go
myQuery, _ := conn.Uql("stats()", requestConfig)
resp, _ := myQuery.Alias("_statistic").AsStats()

println("CPU usage::", resp.CPUUsage, "%")
println("Memory usage:", resp.MemUsage, "%")
Output
CPU usage: 16.926739 %
Memory usage: 11558.082031 %

Process

A Process (Top) object has the following fields:

Field
Type
Description
ProcessIdstringProcess ID
StatusstringProcess status
ProcessUqlstringThe UQL run with the process
DurationstringThe duration in seconds the task has run so far
Go
myQuery, _ := conn.Uql("top()", requestConfig)
resp, _ := myQuery.Alias("_top").AsTops()

println(resp[0].ProcessId)
Output
a_5_15518_2

Task

A Task object has the following fields:

Field
Type
Description
ParamobjectAlgorithm parameters and their corresponding values
TaskInfoTaskInfoTask information including TaskID, AlgoName, StartTime, TaskStatus, etc.
ErrorMsgstringError message of the task
ResultobjectAlgorithm result and statistics and their corresponding values
Go
myQuery, _ := conn.Uql("show().task()", requestConfig)
resp, _ := myQuery.Alias("_task").AsTasks()

println("Algo name:", resp[0].TaskInfo.AlgoName)
println("Parameters:", utils.JSONString(resp[0].Param))
println("Result:", utils.JSONString(resp[0].Result))
Output
Algo name: louvain
Parameters: {"min_modularity_increase":"0.001","phase1_loop_num":"20"}
Result: {"community_count":"1228589","modularity":"0.635263","result_files":"communityID"}

Table

A Table object has the following fields:

Field
Type
Description
NamestringTable name
Headers[]PropertyTable headers
Rows[]RowTable rows

Methods on a Table object:

Method
Return
Description
ToKV()[]ValuesConvert all rows of the table to a key-value list.
Go
myQuery, _ := conn.Uql("find().nodes() as n return table(n._id, n._uuid) as myTable limit 5", requestConfig)
resp, _ := myQuery.Alias("myTable").AsTable()

println("2nd row in table:", utils.JSONString(resp.ToKV()[1]))
Output
2nd row in table: {"Data":{"n._id":"u604510","n._uuid":2}}

Attr

An Attr object has the following fields:

Field
Type
Description
NamestringAlias name
PropertyTypePropertyTypeAttr type
ResultTypeResultTypeAttr type description
RowsRowAttr rows
Go
myQuery, _ := conn.Uql("find().nodes({@ad}) as n return n.brand limit 5", requestConfig)
resp, _ := myQuery.Alias("n.brand").AsAttr()
println(utils.JSONString(resp.Rows))
Output
[14655,14655,14655,14655,434760]