UltipaDocs
Try Playground
  • Introduction
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Installation
    • Connection
    • Request Configuration
    • UQL Execution
    • GQL Execution
    • Graphset Management
    • Schema and Property Management
    • Data Insertion and Deletion
    • Query Acceleration
    • Algorithm Management
    • Downloads and Exports
    • Process and Task Management
    • Access Management
    • Server Statistics
    • Result Processing
    • Types Mapping Ultipa and C#
  • RESTful API
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. C#

Types Mapping Ultipa and C#

Mapping Methods

The 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.

C#
var res = await ultipa.Uql("find().nodes() as n return n{*} limit 5");
var nodeList = res.Alias("n").AsNodes();
Console.WriteLine(JsonConvert.SerializeObject(nodeList));

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()List<Node>?Maps NODE-type DataItem to a list of Node objects.
EDGEAnyAsEdges()List<Edge>?Maps EDGE-type DataItem to a list of Edge objects.
PATHAnyAsPaths()List<Path>?Maps PATH-type DataItem to a list of Path objects.
TABLEAnyAsGraph()GraphMaps GRAPH-type DataItem to a list of Graph objects.
TABLE_graphAsGraphSets()List<GraphSet>?Maps DataItem with the alias _graph to a list of GraphSet objects.
TABLE_nodeSchema, _edgeSchemaAsSchemas()List<Schema>Maps DataItem with the alias _nodeSchema or _edgeSchema to a list of Schema objects.
TABLE_nodeProperty, _edgePropertyAsProperties()List<Property>Maps DataItem with the alias _nodeProperty or _edgeProperty to a list of Property objects.
TABLE_algoListAsAlgos()List<Algo>Maps DataItem with the alias _algoList to a list of Algo objects.
TABLE_extaListAsExtas()List<Exta>Maps DataItem with the alias _extaList to a list of Exta objects.
TABLE_nodeIndex, _edgeIndex, _nodeFulltext, _edgeFulltextAsIndexes()List<Index>Maps DataItem with the alias _nodeIndex, _edgeIndex, _nodeFulltext or _edgeFulltext to a list of Index objects.
TABLE_privilegeAsPrivileges()List<Privilege>Maps DataItem with the alias _privilege to a list of Privilege objects.
TABLE_policyAsPolicies()List<Policy>Maps DataItem with the alias _policy to a list of Policy objects.
TABLE_userAsUsers()List<User>Maps DataItem with the alias _user to a list of User objects.
TABLE_statisticAsStats()DatabaseStatsMaps DataItem with the alias _statistic to a DatabaseStats object.
TABLE_topAsProcesses()List<Process>Maps DataItem with the alias _top to a list of Process objects.
TABLE_taskAsTasks()List<UltipaTask>Maps DataItem with the alias _task to a list of UltipaTask objects.
TABLEAnyAsTable()TableMaps TABLE-type DataItem to a Table object.
ATTRAnyAsAttr()AttrMaps ATTR-type DataItem to an Attr object.
ATTRAnyAsAttrOriginal()AttrListMaps ATTR-type DataItem to an AttrList object.

Driver Types

Node

A Node object has the following fields:

FieldType
Description
Uuiduint64Node UUID
IdstringNode ID
SchemastringNode Schema
ValuesDictionary<string, object?>Node custom properties
C#
var res = await ultipa.Uql("find().nodes() as n return n{*} limit 5", requestConfig);
var nodeList = res.Alias("n")?.AsNodes();
Console.WriteLine("ID of the 1st node: " + JsonConvert.SerializeObject(nodeList[0].Id));
Console.WriteLine(
    "Name of the 1st node: "
        + JsonConvert.SerializeObject(nodeList[0].Values.GetValueOrDefault("name"))
);
Output
ID of the 1st node: ULTIPA8000000000000001
Name of the 1st node: Titanic

Edge

An Edge object has the following fields:

FieldType
Description
Uuiduint64Edge UUID
FromUuiduint64Start node UUID of the edge
ToUuiduint64End node UUID of the edge
FromIdstringStart node ID of the edge
ToIdstringEnd node ID of the edge
SchemastringEdge Schema
ValuesDictionary<string, object?>Edge custom properties
C#
var res = await ultipa.Uql("find().edges() as e return e{*} limit 5", requestConfig);
var edgeList = res.Alias("e")?.AsEdges();
Console.WriteLine(
    "Value of the 1st edge: " + JsonConvert.SerializeObject(edgeList[0].Values)
);
Output
Value of the 1st edge: {"datetime":"2019-01-06T02:56:00Z","timestamp":"2019-01-05T18:57:57Z","targetPost":0}

Path

A Path object has the following fields:

Field
Type
Description
NodesList<Node>Node list of the path
EdgesList<Edge>Edge list of the path
NodeSchemasobjectInfomation of node schema
EdgeSchemasobjectInfomation of edge schema
C#
var res = await ultipa.Uql(
    "n().e()[:2].n() as paths return paths{*} limit 5",
    requestConfig
);
var pathList = res.Alias("paths")?.AsPaths();
Console.WriteLine(
    "Length of the 1st path: " + JsonConvert.SerializeObject(pathList[0].Edges.Count)
);
Console.WriteLine(
    "Edge list of the 1st path: " + JsonConvert.SerializeObject(pathList[0].Edges)
);
Console.WriteLine(
    "Information of the 2nd node in the 1st path: "
        + JsonConvert.SerializeObject(pathList[0].Nodes[1])
);
Output
Length of the 1st path: 2
Edge list of the 1st path: [{"Uuid":7,"FromUuid":27,"ToUuid":1,"Id":"","FromId":"ULTIPA800000000000001B","ToId":"ULTIPA8000000000000001","Schema":"follow","Values":{}},{"Uuid":99,"FromUuid":33,"ToUuid":27,"Id":"","FromId":"ULTIPA8000000000000021","ToId":"ULTIPA800000000000001B","Schema":"follow","Values":{}}]
Information of the 2nd node in the 1st path: {"Uuid":27,"Id":"ULTIPA800000000000001B","Schema":"account","Values":{"year":1988,"industry":"Transportation","name":"Sam123","stringList":[null],"int32List":[null],"float":3.72,"double":3.719999313354492}}

Graph

A Graph object has the following fields:

Field
Type
Description
NodesList<Node>Node list of the path
EdgesList<Edge>Edge list of the path
NodeSchemasDictionary<string, Schema>Map of all node schemas of the path
EdgeSchemasDictionary<string, Schema>Map of all edge schemas of the path
C#
var res = await ultipa.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
);
var graphList = res.Alias("graph")?.AsGraph();
var nodeList = graphList.Nodes;
var edgeList = graphList.Edges;
Console.WriteLine("Node IDs: ");
foreach (var node in nodeList)
{
    Console.WriteLine(node.Id);
}
Console.WriteLine("Edge UUIDs: ");
foreach (var edge in edgeList)
{
    Console.WriteLine(edge.Uuid);
}
Output
Node IDs:
ULTIPA8000000000000017
ULTIPA8000000000000001
ULTIPA8000000000000061
ULTIPA800000000000001B
Edge UUIDs:
1576
43
29

GraphSet

A GraphSet object has the following fields:

Field
Type
Description
IdstringGraphset ID
NamestringGraphset name
DescstringGraphset description
TotalNodesulongTotal number of nodes in the graphset
TotalEdgesulongTotal number of edges in the graphset
StatusstringGraphset status (MOUNTED, MOUNTING, or UNMOUNTED)
C#
var res = await ultipa.Uql("show().graph()");
var graphSetList = res.Alias("_graph")?.AsGraphSets();
foreach (var graph in graphSetList)
{
    if (graph.Status.Equals("UNMOUNTED"))
    {
        Console.WriteLine(graph.Name);
    }
}
Output
DFS_EG
cyber
cyber2

Schema

A Schema object has the following fields:

Field
Type
Description
NamestringSchema name
DescstringSchema description
DbTypeDBTypeType of the schema (node or edge)
TotalintTotal number of nodes/edges of the schema
PropertiesList<Property>Property list of the schema
C#
var res = await ultipa.Uql("show().node_schema()", requestConfig);
var schemaList = res.Alias("_nodeSchema")?.AsSchemas();
foreach (var schema in schemaList)
{
    Console.WriteLine(schema.Name + " has " + schema.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
ReadboolProperty read status
WriteboolProperty write status
SchemastringAssociated schema of the property
TypePropertyTypeProperty data type
SubTypesPropertyType[]List of property data type
ExtrastringExtra information of properties
C#
var res = await ultipa.Uql("show().node_property(@account)", requestConfig);
var propertyList = res.Alias("_nodeProperty")?.AsProperties();
foreach (var property in propertyList)
{
    if (property.Lte.Equals(true))
    {
        Console.WriteLine("LTE-ed property name: " + property.Name);
    }
}
Output
LTE-ed property name: year

Algo

An Algo object has the following fields:

Field
Type
Description
NamestringAlgorithm name
ParamstringParameters of the algorithm
DetailstringAlgorithm details
C#
var res = await ultipa.Uql("show().algo()", requestConfig);
var algoList = res.Alias("_algoList")?.AsAlgos();
Console.WriteLine(JsonConvert.SerializeObject(algoList[0]));
Output
{"Name":"bipartite","Param":"{\"name\":\"bipartite\",\"description\":\"bipartite check\",\"version\":\"1.0.1\",\"parameters\":{},\"result_opt\":\"56\"}","Detail":"base:\r\n  category: Connectivity & Compactness\r\n   name: Bipartite\r\n    desc: Judge if the current graph is bipartite.\r\n}

Exta

NOTE

An exta is a custom algorithm developed by users.

An Exta object has the following fields:

Field
Type
Description
AuthorstringExta author
NamestringExta name
VersionstringExta version
DetailstringContent of the YML configuration file of the Exta
C#
var res = await ultipa.Uql("show().exta()");
var extaList = res.Alias("_extaList")?.AsExtas();
Console.WriteLine(JsonConvert.SerializeObject("Exta name: " + extaList[0].Name));
Output
"Exta name: page_rank"

Index

An Index object has the following fields:

Field
Type
Description
SchemastringSchema name of the index
NamestringIndex name
PropertiesstringProperty name of the index
StatusstringIndex status (done or creating)
SizestringIndex size in bytes
C#
var res = await ultipa.Uql("show().index()", requestConfig);
var indexList = res.Alias("_nodeIndex")?.AsIndexes();
foreach (var index in indexList)
{
    Console.WriteLine("Schema name: " + index.Schema);
    Console.WriteLine("Properties: " + index.Properties);
    Console.WriteLine("Size: " + index.size);
}
Output
Schema name: account
Properties: name
Size: 0
Schema name: movie
Properties: name
Size: 2526
C#
var res = await ultipa.Uql("show().fulltext()", requestConfig);
var fulltextList = res.Alias("_edgeFulltext")?.AsIndexes();
foreach (var item in fulltextList)
{
    Console.WriteLine("Fulltext name: " + item.Name);
    Console.WriteLine("Schema name: " + item.Schema);
    Console.WriteLine("Properties: " + item.Properties);
}
Output
Fulltext name: nameFull
Schema name: review
Properties: content

Privilege

A Privilege object has the following fields:

Field
Type
Description
NamestringPrivilege name
LevelPrivilegeTypePrivilege type, including GraphLevel and SystemLevel
C#
var res = await ultipa.Uql("show().privilege()");
var privilegeList = res.Alias("_privilege")?.AsPrivileges();

var systemPrivilegeList = new List\<string>();
foreach (var item in privilegeList)
{
    if (item.Level == PrivilegeType.SystemLevel)
    {
        systemPrivilegeList.Add(item.Name);
    }
}
Console.WriteLine("System privileges include: ");
Console.WriteLine(JsonConvert.SerializeObject(systemPrivilegeList));
Output
System privileges include:
["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
GraphPrivilegesDictionary<string, List<string>>Graph privileges and the corresponding graphsets included in the policy
SystemPrivilegesList<string>System privileges included in the policy
SubPoliciesList<string>Policies included in the policy
PropertyPrivilegesPropertyPrivilegeMap?Property privileges included in the policy
C#
var res = await ultipa.Uql("show().policy()");
var policyList = res.Alias("_policy")?.AsPolicies();
foreach (var item in policyList)
{
    Console.WriteLine("Policy name: " + item.Name);
}
Output
Policy name: operator
Policy name: manager

User

A User object has the following fields:

Field
Type
Description
UsernamestringUsername
PasswordstringPassword
CreatedTimestringWhen the user was created
GraphPrivilegesDictionary<string, List<string>>?Graph privileges and the corresponding graphsets granted to the user
SystemPrivilegesList<string>System privileges granted to the user
PropertyPrivilegesPropertyPrivilegesProperty privileges granted to the user
PoliciesList<string>Policies granted to the user
C#
var res = await ultipa.Uql("show().user('Tester')");
var userList = res.Alias("_user")?.AsUsers();
Console.WriteLine("Username: " + userList[0].Username);
Console.WriteLine("Created at: " + userList[0].CreatedTime);
Console.WriteLine(
    "Graph privileges: " + JsonConvert.SerializeObject(userList[0].GraphPrivileges)
);
Console.WriteLine(
    "System privileges: " + JsonConvert.SerializeObject(userList[0].SystemPrivileges)
);
Console.WriteLine(
    "Property privileges: " + JsonConvert.SerializeObject(userList[0].PropertyPrivileges)
);
Output
Username: Tester
Created at: 7/26/2024 6:10:06 AM
Graph privileges: {"Ad_Click":["FIND_EDGE","FIND_NODE"],"DFS_EG":["UPDATE","INSERT"]}
System privileges: ["MOUNT_GRAPH"]
Property privileges: {"node":{"read":[["*","*","*"]],"write":[["*","*","*"],["miniCircle","account","name"]],"deny":[]},"edge":{"read":[["*","*","*"]],"write":[["*","*","*"]],"deny":[]}}

Stats

A DatabaseStats 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
C#
var res = await ultipa.Uql("stats()");
var statsList = res.Alias("_statistic")?.AsStats();
Console.WriteLine("CPU usage: " + statsList.CpuUsage);
Console.WriteLine("Memory usage: " + statsList.MemUsage);
Output
CPU usage: 12.204036
Memory usage: 11348.136719

Process

A Process object has the following fields:

Field
Type
Description
IdstringProcess ID
UqlstringThe UQL run with the process
DurationintThe duration in seconds the task has run so far
StatusstringProcess status
C#
var res = await ultipa.Uql("top()");
var processList = res.Alias("_top")?.AsProcesses();
Console.WriteLine("Process ID: " + processList[0].Id);
Output
Process ID: a_7_14568_1

Task

A UltipaTask object has the following fields:

Field
Type
Description
ParamobjectAlgorithm parameters and their corresponding values
InfoTaskInfoTask information including TaskID, AlgoName, StartTime, TaskStatus, etc.
resultobjectAlgorithm result and statistics and their corresponding values
ErrorMsgstringError message of the task
C#
var res = await ultipa.Uql("show().task()", requestConfig);
var taskList = res.Alias("_task")?.AsTasks();
Console.WriteLine("Algo Name: " + taskList[0].Info.AlgoName);
Console.WriteLine("Parameters: " + taskList[0].Param);
Console.WriteLine("Result: " + taskList[0].result);
Output
Algo Name: louvain
Parameters: {"phase1_loop_num":"20","min_modularity_increase":"0.001"}
Result: {
  "community_count": "10",
  "modularity": "0.535017",
  "result_files": "communityID,ids,num"
}

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()List<Dictionary<string, object?>>Convert all rows of the table to a key-value list.
C#
var res = await ultipa.Uql(
    "find().nodes() as n return table(n._id, n._uuid) as myTable limit 5"
);
var myTab = res.Alias("myTable")?.AsTable();
Console.WriteLine("2nd row in table: " + JsonConvert.SerializeObject(myTab.ToKv()[1]));
Output
2nd row in table: {"n._id":"ULTIPA8000000000000002","n._uuid":0}

Attr

An Attr object has the following fields:

Field
Type
Description
ResultTypeResultTypeAttr type description
PropertyTypePropertyTypeAttr type
NodesList<Node>List of Node objects
EdgesList<Edge>List of Edge objects
PathsList<Path>List of Path objects
AttrsAttrListList of Attr objects
ValueobjectValue of the data
C#
var res = await ultipa.Uql(
    "find().nodes({@ad}) as n return n.brand limit 5",
    requestConfig
);
var myAttr = res.Alias("n.brand")?.AsAttr();
Console.WriteLine(JsonConvert.SerializeObject(myAttr));
Output
[14655,14655,14655,14655,434760]