Mapping Methods
Response
类的get()
方法或alias()
方法返回一个DataItem
,内嵌在查询结果中。您需使用DataItem
的As<Type>()
方法将结果转换成合适的驱动类型。
var res = await ultipa.Uql("find().nodes() as n return n{*} limit 5");
var nodeList = res.Alias("n").AsNodes();
Console.WriteLine(JsonConvert.SerializeObject(nodeList));
从数据库返回的结果n
包含5个节点,均为NODE类型。AsNodes()
方法将这些节点转换成Node
列表。
DataItem
的类型映射方法:
UQL类型 | UQL别名 | 方法 | 驱动类型 | 描述 |
---|---|---|---|---|
NODE | Any | AsNodes() |
List<Node>? | 将NODE类型的DataItem 映射为Node 对象的列表 |
EDGE | Any | AsEdges() |
List<Edge>? | 将EDGE类型的DataItem 映射为Edge 对象的列表 |
PATH | Any | AsPaths() |
List<Path>? | 将PATH类型的DataItem 映射为Path 对象的列表 |
TABLE | Any | AsGraph() |
Graph | 将GRAPH类型的 DataItem 映射为Graph 对象列表。 |
TABLE | _graph |
AsGraphSets() |
List<GraphSet>? | 将别名为_graph 的DataItem 映射为GraphSet 对象的列表 |
TABLE | _nodeSchema , _edgeSchema |
AsSchemas() |
List<Schema> | 将别名为_nodeSchema 或_edgeSchema 的DataItem 映射为Schema 对象的列表 |
TABLE | _nodeProperty , _edgeProperty |
AsProperties() |
List<Property> | 将别名为_nodeProperty 或_edgeProperty 的DataItem 映射为Property 对象的列表 |
TABLE | _algoList |
AsAlgos() |
List<Algo> | 将别名为_algoList 的DataItem 映射为Algo 对象的列表 |
TABLE | _extaList |
AsExtas() |
List<Exta> | 将别名为_extaList 的DataItem 映射为Exta 对象的列表 |
TABLE | _nodeIndex , _edgeIndex , _nodeFulltext , _edgeFulltext |
AsIndexes() |
List<Index> | 将别名为_nodeIndex ,_edgeIndex ,_nodeFulltext 或_edgeFulltext 的DataItem 映射为Index 对象的列表 |
TABLE | _privilege |
AsPrivileges() |
List<Privilege> | 将别名为_privilege 的DataItem 映射为一个Priviliege 对象 |
TABLE | _policy |
AsPolicies() |
List<Policy> | 将别名为_policy 的DataItem 映射为Policy 对象的列表 |
TABLE | _user |
AsUsers() |
List<User> | 将别名为_user 的DataItem 映射为User 对象的列表 |
TABLE | _statistic |
AsStats() |
DatabaseStats | 将别名为_statistic 的DataItem 映射为一个Stats 对象 |
TABLE | _top |
AsProcesses() |
List<Process> | 将别名为_top 的DataItem 映射为Process 对象的列表 |
TABLE | _task |
AsTasks() |
List<UltipaTask> | 将别名为_task 的DataItem 映射为UltipaTask 对象列表。 |
TABLE | Any | AsTable() |
Table | 将TABLE类型的DataItem 映射为一个Table 对象 |
ATTR | Any | AsAttr() |
Attr | 将ATTR类型的DataItem 映射为一个Attr 对象 |
ATTR | Any | AsAttrOriginal() |
AttrList | 将 ATTR 类型的DataItem 映射为AttrList 对象 |
Driver Types
Node
Node
对象包含以下字段:
字段 | 类型 | 描述 |
---|---|---|
Uuid |
uint64 | 点的UUID |
Id |
string | 点的ID |
Schema |
string | 点的schema |
Values |
Dictionary<string, object?> | 点的自定义属性 |
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"))
);
ID of the 1st node: ULTIPA8000000000000001
Name of the 1st node: Titanic
Edge
Edge
对象包含以下字段:
字段 | 类型 | 描述 |
---|---|---|
Uuid |
uint64 | 边的UUID |
FromUuid |
uint64 | 边的起点的UUID |
ToUuid |
uint64 | 边的终点的UUID |
FromId |
string | 边的起点的ID |
ToId |
string | 边的终点的ID |
Schema |
string | 边的schema |
Values |
Dictionary<string, object?> | 边的自定义属性 |
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)
);
Value of the 1st edge: {"datetime":"2019-01-06T02:56:00Z","timestamp":"2019-01-05T18:57:57Z","targetPost":0}
Path
Path
对象包含以下字段:
字段 | 类型 |
描述 |
---|---|---|
Nodes |
List<Node> | 路径中的Node列表 |
Edges |
List<Edge> | 路径中的Edge列表 |
NodeSchemas |
object | 点schema的信息 |
EdgeSchemas |
object | 边schema的信息 |
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])
);
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
Graph
对象包含以下字段:
字段 |
类型 | 描述 |
---|---|---|
Nodes |
List<Node> | 路径中的Node列表 |
Edges |
List<Edge> | 路径中的Edge列表 |
NodeSchemas |
Dictionary<string, Schema> | 路径中全部点schema的映射 |
EdgeSchemas |
Dictionary<string, Schema> | 路径中全部边schema的映射 |
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);
}
Node IDs:
ULTIPA8000000000000017
ULTIPA8000000000000001
ULTIPA8000000000000061
ULTIPA800000000000001B
Edge UUIDs:
1576
43
29
GraphSet
GraphSet
对象包含以下字段:
字段 |
类型 | 描述 |
---|---|---|
Id |
string | 图集ID |
Name |
string | 图集名称 |
Desc |
string | 图集描述 |
TotalNodes |
ulong | 图集总点数 |
TotalEdges |
ulong | 图集总边数 |
Status |
string | 图集属性,包括MOUNTED,MOUNTING和UNMOUNTED |
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);
}
}
DFS_EG
cyber
cyber2
Schema
Schema
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Name |
string | Schema名称 |
Desc |
string | Schema描述 |
DbType |
DBType | Schema类型(点或边) |
Total |
int | Schema中点/边的总数 |
Properties |
List<Property> | Schema的属性列表 |
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");
}
default has 0 nodes
user has 1092511 nodes
ad has 846811 nodes
Property
Property
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Name |
string | 属性名称 |
Desc |
string | 属性描述 |
Lte |
bool | 属性LTE状态(true、false 或 creating) |
Read |
bool | 属性读取状态 |
Write |
bool | 属性写入状态 |
Schema |
string | 属性关联的schema |
Type |
PropertyType | 属性数据类型 |
SubTypes |
PropertyType[] | 属性数据类型列表 |
Extra |
string | 属性的额外信息 |
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);
}
}
LTE-ed property name: year
Algo
Algo
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Name |
string | 算法名称 |
Param |
string | 算法参数 |
Detail |
string | 算法详细信息 |
var res = await ultipa.Uql("show().algo()", requestConfig);
var algoList = res.Alias("_algoList")?.AsAlgos();
Console.WriteLine(JsonConvert.SerializeObject(algoList[0]));
{"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
Exta是由用户开发的自定义算法。
Exta
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Author |
string | Exta作者 |
Name |
string | Exta名称 |
Version |
string | Exta版本 |
Detail |
string | Exta的YML配置文件内容 |
var res = await ultipa.Uql("show().exta()");
var extaList = res.Alias("_extaList")?.AsExtas();
Console.WriteLine(JsonConvert.SerializeObject("Exta name: " + extaList[0].Name));
"Exta name: page_rank"
Index
Index
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Schema |
string | 索引的schema名称 |
Name |
string | 索引名称 |
Properties |
string | 索引的属性名称 |
Status |
string | 索引状态(done或creating) |
Size |
string | 索引大小(字节) |
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);
}
Schema name: account
Properties: name
Size: 0
Schema name: movie
Properties: name
Size: 2526
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);
}
Fulltext name: nameFull
Schema name: review
Properties: content
Privilege
Privilege
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Name |
string | 权限名称 |
Level |
PrivilegeType | 权限类型,包括GraphLevel和SystemLevel |
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));
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
Policy
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Name |
string | 策略名称 |
GraphPrivileges |
Dictionary<string, List<string>> | 策略中的图权限和对应图集 |
SystemPrivileges |
List<string> | 策略中的系统权限 |
SubPolicies |
List<string> | 策略中的策略 |
PropertyPrivileges |
PropertyPrivilegeMap? | 策略中的属性权限 |
var res = await ultipa.Uql("show().policy()");
var policyList = res.Alias("_policy")?.AsPolicies();
foreach (var item in policyList)
{
Console.WriteLine("Policy name: " + item.Name);
}
Policy name: operator
Policy name: manager
User
User
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Username |
string | 用户名 |
Password |
string | 密码 |
CreatedTime |
string | 用户创建时间 |
GraphPrivileges |
Dictionary<string, List<string>>? | 授予用户的图权限和对应图集 |
SystemPrivileges |
List<string> | 授予用户的系统权限 |
PropertyPrivileges |
PropertyPrivileges | 授予用户的属性权限 |
Policies |
List<string> | 授予用户的策略 |
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)
);
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
DatabaseStats
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
CpuUsage |
string | CPU使用百分比 |
MemUsage |
string | 内存使用量 |
ExpiredDate |
string | 许可证过期日期 |
CpuCores |
string | CPU核数 |
Company |
string | 公司名称 |
ServerType |
string | 服务器类型 |
Version |
string | 服务器版本 |
var res = await ultipa.Uql("stats()");
var statsList = res.Alias("_statistic")?.AsStats();
Console.WriteLine("CPU usage: " + statsList.CpuUsage);
Console.WriteLine("Memory usage: " + statsList.MemUsage);
CPU usage: 12.204036
Memory usage: 11348.136719
Process
Process
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Id |
string | 进程ID |
Uql |
string | 与进程一起运行的UQL |
Duration |
int | 任务已运行时长,单位为秒 |
Status |
string | 进程状态 |
var res = await ultipa.Uql("top()");
var processList = res.Alias("_top")?.AsProcesses();
Console.WriteLine("Process ID: " + processList[0].Id);
Process ID: a_7_14568_1
Task
UltipaTask
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Param |
object | 算法参数和对应值 |
Info |
TaskInfo | 任务信息,包括TaskID , AlgoName , StartTime , TaskStatus 等 |
result |
object | 算法的计算结果、统计信息及其对应的值 |
ErrorMsg |
string | 任务执行过程中的错误信息 |
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);
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
Table
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
Name |
string | 表格名称 |
Headers |
[]Property | 表头 |
Rows |
[]Row | 表格行 |
Table
对象的方法:
方法 |
返回值 |
描述 |
---|---|---|
ToKv() |
List<Dictionary<string, object?>> | 将表格的所有行转换为键值对列表 |
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]));
2nd row in table: {"n._id":"ULTIPA8000000000000002","n._uuid":0}
Attr
An Attr
对象包含以下字段:
字段 |
类型 |
描述 |
---|---|---|
ResultType |
ResultType | Attr类型描述 |
PropertyType |
PropertyType | Attr类型 |
Nodes |
List<Node> | Node 对象列表 |
Edges |
List<Edge> | Edge 对象列表 |
Paths |
List<Path> | Path 对象列表 |
Attrs |
AttrList | Attr 对象列表 |
Value |
object | 数据的值 |
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));
[14655,14655,14655,14655,434760]