Mapping Methods
Response类的get()方法或alias()方法返回一个DataItem,内嵌在查询结果中。您需使用DataItem的as<Type>()方法将结果转换成合适的驱动类型。
let requestConfig = <RequestType.RequestConfig>{
useMaster: true,
graphSetName: "miniCircle",
};
let resp = await conn.uql(
"find().nodes() as n return n{*} limit 5",
requestConfig
);
console.log(resp.data?.get(0).asNodes());
从数据库返回的结果n包含5个节点,均为NODE类型。asNodes()方法将这些节点转换成Node列表。
DataItem的类型映射方法:
| UQL类型 | UQL别名 | 方法 | 驱动类型 | 描述 |
|---|---|---|---|---|
| NODE | Any | asNodes() |
Node[] | 将NODE类型的DataItem映射为Node对象的列表 |
| EDGE | Any | asEdges() |
Edge[] | 将EDGE类型的DataItem映射为Edge对象的列表 |
| PATH | Any | asPaths() |
Path[] | 将PATH类型的DataItem映射为Path对象的列表 |
| GRAPH | Any | asGraph() |
Graph | 将GRAPH类型的DataItem映射为一个Graph对象 |
| TABLE | _graph |
asGraphInfos() |
GraphSet[] | 将别名为_graph的DataItem映射为GraphSet对象的列表 |
| TABLE | _nodeSchema, _edgeSchema |
asSchemas() |
Schema[] | 将别名为_nodeSchema或_edgeSchema的DataItem映射为Schema对象的列表 |
| TABLE | _nodeProperty, _edgeProperty |
asProperties() |
Property[] | 将别名为_nodeProperty或_edgeProperty的DataItem映射为Property对象的列表 |
| TABLE | _algoList |
asAlgos() |
Algo[] | 将别名为_algoList的DataItem映射为Algo对象的列表 |
| TABLE | _extaList |
asExtas() |
Exta[] | 将别名为_extaList的DataItem映射为Exta对象的列表 |
| TABLE | _nodeIndex, _edgeIndex, _nodeFulltext, _edgeFulltext |
/ |
Index[] | 将别名为_nodeIndex,_edgeIndex,_nodeFulltext或_edgeFulltext的DataItem映射为Index对象的列表 |
| TABLE | _privilege |
/ |
Priviliege | 将别名为_privilege的DataItem映射为一个Priviliege对象 |
| TABLE | _policy |
/ |
Policy[] | 将别名为_policy的DataItem映射为Policy对象的列表 |
| TABLE | _user |
/ |
User[] | 将别名为_user的DataItem映射为User对象的列表 |
| TABLE | _statistic |
/ |
Stats | 将别名为_statistic的DataItem映射为一个Stats对象 |
| TABLE | _top |
/ |
Process[] | 将别名为_top的DataItem映射为Process对象的列表 |
| TABLE | _task |
asTasks() |
Task[] | 将别名为_task的DataItem映射为Task对象的列表 |
| TABLE | Any | asTable() |
Table | 将TABLE类型的DataItem映射为一个Table对象 |
| ATTR | Any | asAttr() |
Attr | 将ATTR类型的DataItem映射为一个Attr对象 |
Driver Types
所有驱动类型的对象均支持使用getter方法获取字段值,以及使用setter方法设定字段值,即便这些对象并未在下文中明确列出。
Node
Node对象包含以下字段:
| 字段 | 类型 | 描述 |
|---|---|---|
uuid |
string | 点的UUID |
id |
string | 点的ID |
schema |
string | 点的schema |
values |
object | 点的自定义属性 |
作用在Node对象上的方法:
方法 |
返回值 |
描述 |
|---|---|---|
get("<propertyName>") |
Object | 获取点的指定自定义属性的值 |
set("<propertyName>", <propertyValue> |
设置点的指定自定义属性的值;若指定的<propertyName>不存在,则为点的values增加一个键值对 |
let resp = await conn.uql(
"find().nodes() as n return n{*} limit 5",
requestConfig
);
let nodeList = resp.data?.alias("n").asNodes();
console.log("ID of the 1st node:", nodeList[0].getID());
console.log("Name of the 1st node:", nodeList[0].get("name"));
ID of the 1st node: ULTIPA8000000000000001
Name of the 1st node: Titanic
Edge
Edge对象包含以下字段:
| 字段 | 类型 | 描述 |
|---|---|---|
schema |
string | 边的schema |
from |
string | 边的起点的ID |
to |
string | 边的终点的ID |
uuid |
string | 边的UUID |
from_uuid |
string | 边的起点的UUID |
to_uuid |
string | 边的终点的UUID |
values |
object | 边的自定义属性 |
作用在Edge对象上的方法:
方法 |
返回值 |
描述 |
|---|---|---|
get("<propertyName>") |
Object | 获取边的指定自定义属性的值 |
set("<propertyName>", <propertyValue> |
设置边的指定自定义属性的值;若指定的<propertyName>不存在,则为边的values增加一个键值对 |
let resp = await conn.uql(
"find().edges() as e return e{*} limit 5",
requestConfig
);
let edgeList = resp.data?.alias("e").asEdges();
console.log("Values of the 1st edge", edgeList[0].getValues());
Values of the 1st edge {
datetime: '2019-01-06 02:57:57',
timestamp: 1546714677,
targetPost: '703'
}
Path
Path对象包含以下字段:
| 字段 | 类型 |
描述 |
|---|---|---|
nodes |
Node[] | 路径中的Node列表 |
edges |
Edge[] | 路径中的Edge列表 |
length |
number | 路径的长度,即路径中边的数量 |
let resp = await conn.uql(
"n().e()[:2].n() as paths return paths{*} limit 5",
requestConfig
);
let pathList = resp.data?.alias("paths").asPaths();
console.log("Length of the 1st path:", pathList[0].length);
console.log("Edge list of the 1st path:", pathList[0].getEdges());
console.log(
"Information of the 2nd node in the 1st path:",
pathList[0].getNodes()[1]
);
Length of the 1st path: 2
Edge list of the 1st path: [
Edge {
from: 'ULTIPA800000000000001B',
to: 'ULTIPA8000000000000001',
uuid: '7',
from_uuid: '27',
to_uuid: '1',
schema: 'follow',
values: {}
},
Edge {
from: 'ULTIPA8000000000000021',
to: 'ULTIPA800000000000001B',
uuid: '99',
from_uuid: '33',
to_uuid: '27',
schema: 'follow',
values: {}
}
]
Information of the 2nd node in the 1st path: Node {
id: 'ULTIPA800000000000001B',
uuid: '27',
schema: 'account',
values: {
year: 1988,
industry: 'Transportation',
double: '3.72'
}
}
Graph
Graph对象包含以下字段:
| 字段 | 类型 |
描述 |
|---|---|---|
nodes |
Node[] | 路径中的Node列表 |
edges |
Edge[] | 路径中的Edge列表 |
nodeSchemas |
map<string, schema> | 路径中全部点schema的映射 |
edgeSchemas |
map<string, schema> | 路径中全部边schema的映射 |
let resp = await 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
);
let graphList = resp.data?.alias("graph").asGraph();
let nodeList = graphList.getNodes();
let edgeList = graphList.getEdges();
console.log(
"Node IDs:",
nodeList.map((node) => node.getID())
);
console.log(
"Edge UUIDs:",
edgeList.map((edge) => edge.getUUID())
);
Node IDs: [
'ULTIPA8000000000000017',
'ULTIPA8000000000000001',
'ULTIPA800000000000001B',
'ULTIPA8000000000000061'
]
Edge UUIDs: [ '43', '1576', '29' ]
GraphSet
GraphSet对象包含以下字段:
字段 |
类型 | 描述 |
|---|---|---|
id |
string | 图集ID |
name |
string | 图集名称 |
description |
string | 图集描述 |
totalNodes |
string | 图集总点数 |
totalEdges |
string | 图集总边数 |
status |
string | 图集状态(已挂载 MOUNTED、挂载中 MOUNTING 或未挂载 UNMOUNTED) |
let resp = await conn.uql("show().graph()");
let graphList = resp.data?.alias("_graph").asGraphInfos();
let unmountedGraph = graphList.filter((item) => item.status == "UNMOUNTED");
console.log(unmountedGraph.map((item) => item.name));
[ 'DFS_EG', 'cyber', 'cyber2' ]
Schema
Schema对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
string | Schema名称 |
description |
string | Schema描述 |
properties |
Property[] | Schema属性列表 |
totalNodes |
string | Schema的总点数 |
totalEdges |
string | Schema的总边数 |
let resp = await conn.uql("show().node_schema()", requestConfig);
let schemaList = resp.data?.alias("_nodeSchema").asSchemas();
for (let schema of schemaList) {
console.log(schema.name, "has", schema.totalNodes, "nodes");
}
default has 0 nodes
account has 111 nodes
movie has 92 nodes
country has 23 nodes
celebrity has 78 nodes
Property
Property对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
string | 属性名称 |
description |
string | 属性描述 |
schema |
string | 属性的关联schema |
type |
string | 属性数据类型 |
lte |
string | 属性LTE状态(true、false 或 creating) |
extra |
PropertyExtraInfo | 属性的额外信息 |
let resp = await conn.uql("show().node_property(@user)", requestConfig);
let propertyList = resp.data?.alias("_nodeProperty").asProperties();
for (let property of propertyList) {
if (property.lte == "true")
console.log("LTE-ed property name:", property.name);
}
LTE-ed property name: location
Algo
Algo对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
clusterId |
string | 集群ID |
name |
string | 算法名称 |
param |
object | 算法参数,包括name、description、parameters、result_opt和version |
detail |
string | 算法详细信息 |
result_opt |
object | 算法结果选项 |
let resp = await conn.uql("show().algo()");
let algoList = resp.data?.alias("_algoList").asAlgos();
console.log("Algo name:", algoList[0].param.name);
console.log("Algo version:", algoList[0].param.version);
console.log("Description:", algoList[0].param.description);
Algo name: lpa
Algo version: 1.0.10
Description: label propagation algorithm
Exta
Exta是由用户开发的自定义算法。
Exta对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
author |
string | Exta作者 |
detail |
string | Exta的YML配置文件内容 |
name |
string | Exta名称 |
version |
string | Exta版本 |
let resp = await conn.uql("show().exta()");
let extaList = resp.data?.alias("_extaList").asExtas();
console.log("Exta name:", extaList[0].name);
Exta name: page_rank 1
Index
Index对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
string | 索引名称 |
properties |
string | 索引的属性名称 |
schema |
string | 索引的schema名称 |
status |
string | 索引状态,包括done和creating |
size |
string | 索引大小(字节) |
dbType |
Ultipa.DBType | 索引类型,包括DBNODE和DBEDGE |
let resp = await conn.uql("show().index()");
let indexList = resp.data?.alias("_nodeIndex");
console.log(indexList.data);
Table {
name: '_nodeIndex',
alias: '_nodeIndex',
headers: [ 'name', 'properties', 'schema', 'status', 'size' ],
rows: []
}
let resp = await conn.uql("show().fulltext()");
let indexList = resp.data?.alias("_nodeFulltext");
console.log(indexList.data);
Table {
name: '_nodeFulltext',
alias: '_nodeFulltext',
headers: [ 'name', 'properties', 'schema', 'status' ],
rows: []
}
Privilege
Privilege对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
systemPrivileges |
string[] | 系统权限 |
graphPrivileges |
string[] | 图权限 |
let resp = await conn.uql("show().privilege()");
let privilegeList = resp.data?.alias("_privilege").asTable();
console.log("System privileges:", privilegeList.rows[0][1]);
[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 | 策略名称 |
graph_privileges |
GraphPrivilege | 策略中的图权限和对应图集 |
system_privileges |
string[] | 策略中的系统权限 |
policies |
string[] | 策略中的策略 |
property_privileges |
PropertyPrivilege | 策略中的属性权限 |
let resp = await conn.uql("show().policy()");
let policyList = resp.data?.alias("_policy");
console.log(policyList.data.rows[4]);
[
'policy',
'{"amz":["SHOW_ALGO","CREATE_PROPERTY","CLEAR_TASK","RESUME_TASK","CREATE_BACKUP","SHOW_PROPERTY","SHOW_FULLTEXT","SHOW_INDEX"]}',
'["GRANT","DROP_GRAPH","CREATE_USER","COMPACT","UNMOUNT_GRAPH","STAT","DROP_POLICY"]',
'{"node":{"read":[],"write":[],"deny":[]},"edge":{"read":[],"write":[],"deny":[]}}',
'["subpolicy"]'
]
User
User对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
username |
string | 用户名 |
create |
string | 用户创建时间 |
lastLogin |
string | 用户上次登录时间 |
system_privileges |
string[] | 授予用户的系统权限 |
graph_privileges |
GraphPrivilege | 授予用户的图权限和对应图集 |
policies |
string[] | 授予用户的策略 |
property_privileges |
PropertyPrivilege | 授予用户的属性权限 |
let resp = await conn.uql("show().user('Tester')");
let userList = resp.data.alias("_user").asTable();
console.log(userList.headers[0], ":", userList.rows[0][0]);
console.log(userList.headers[1], ":", userList.rows[0][1]);
console.log(userList.headers[2], ":", userList.rows[0][2]);
console.log(userList.headers[3], ":", userList.rows[0][3]);
console.log(userList.headers[4], ":", userList.rows[0][4]);
username : Tester
create : 1721974206
graphPrivileges : {"Ad_Click":["FIND_EDGE","FIND_NODE"],"DFS_EG":["UPDATE","INSERT"]}
systemPrivileges : ["MOUNT_GRAPH"]
propertyPrivileges : {"node":{"read":[],"write":[["miniCircle","account","name"]],"deny":[]},"edge":{"read":[],"write":[],"deny":[]}}
Stats
Stats对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
cpuUsage |
string | CPU使用百分比 |
memUsage |
string | 内存使用量(兆字节) |
expiredDate |
string | 许可证过期日期 |
cpuCores |
string | CPU核数 |
company |
string | 公司名称 |
serverType |
string | 服务器类型 |
version |
string | 服务器版本 |
let resp = await conn.stats();
console.log("CPU usage:", resp.data.cpuUsage, "%");
console.log("Memory usage:", resp.data.memUsage);
CPU usage: 15.209929 %
Memory usage: 10418.183594
Process
Process对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
process_id |
string | 进程ID |
process_uql |
string | 与进程一起运行的UQL |
status |
string | 进程状态 |
duration |
string | 任务已运行时长,单位为秒 |
let requestConfig = <RequestType.RequestConfig>{
useMaster: true,
graphSetName: "amz",
};
let resp = await conn.uql("top()", requestConfig);
let processList = resp.data?.alias("_top");
console.log(processList.data.rows[0][0]);
a_1_3259_2
Task
Task对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
param |
object | 算法参数和对应值 |
task_info |
object | 任务信息,包括task_id, algo_name, start_time, TASK_STATUS等 |
error_msg |
string | 任务执行过程中的错误信息 |
result |
object | 算法的计算结果、统计信息及其对应的值 |
return_type |
object | 结果的返回类型 |
let requestConfig = <RequestType.RequestConfig>{
useMaster: true,
graphSetName: "miniCircle",
};
let resp = await conn.uql("show().task()", requestConfig);
let taskList = resp.data.alias("_task").asTasks();
console.log("Algo name:", taskList[0].task_info["algo_name"]);
console.log("Algo parameters:", taskList[0].param);
console.log("Result:", taskList[0].result);
Algo name: louvain
Algo parameters: { phase1_loop_num: '20', min_modularity_increase: '0.001' }
Result: {
community_count: '11',
modularity: '0.532784',
result_files: 'communityID'
}
Table
Table对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
string | 表格名称 |
headers |
object | 表头 |
rows |
object | 表格行 |
作用在Table对象上的方法:
方法 |
返回值 |
描述 |
|---|---|---|
toKV() |
List<Value> | 将表的所有行转换成键值列表 |
let resp = await conn.uql(
"find().nodes() as n return table(n._id, n._uuid) as myTable limit 5",
requestConfig
);
let tableInfo = resp.data.alias("myTable").asTable();
console.log("2nd row in table:", tableInfo.toKV()[1]);
2nd row in table: { 'n._id': 'ULTIPA8000000000000002', 'n._uuid': '2' }
Attr
Attr对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
alias |
string | Attr名称 |
type |
number | Attr类型 |
type_desc |
string | Attr类型描述 |
values |
object | Attr行 |
let resp = await conn.uql(
"find().nodes({@account}) as n return n.year limit 5",
requestConfig
);
let myAttr = resp.data.alias("n.year").asAttrs();
console.log(myAttr.values);
[ 1978, 1989, 1982, 2007, 1973 ]