映射方法
Response类的get()方法或alias()方法返回一个DataItem,内嵌在查询结果中。您需使用DataItem的as<Type>()方法将结果转换成合适的驱动类型。
Response response = client.uql("find().nodes() as n return n{*} limit 5");
List<Node> nodeList = response.alias("n").asNodes();
从数据库返回的结果n包含5个节点,均为NODE类型。asNodes()方法将这些节点转换成Node列表。
DataItem的类型映射方法:
| UQL类型 | UQL别名 | 方法 | 驱动类型 | 描述 |
|---|---|---|---|---|
| NODE | 任意 | asNodes() |
List<Node> | 将NODE类型的DataItem映射为Node对象列表 |
| NODE | 任意 | asFirstNode() |
Node | 将NODE类型的DataItem中第一个点映射为一个Node对象。等同于asNodes().get(0) |
| EDGE | 任意 | asEdges() |
List<Edge> | 将EDGE类型的DataItem映射为Edge对象列表 |
| EDGE | 任意 | asFirstEdge() |
Edge | 将EDGE类型的DataItem中第一条边映射为一个Edge对象。等同于asEdges().get(0) |
| PATH | 任意 | asPaths() |
List<Path> | 将PATH类型的DataItem映射为Path对象列表 |
| GRAPH | 任意 | 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 |
asPriviliege() |
Priviliege | 将别名为_privilege的DataItem映射为一个Priviliege对象 |
| TABLE | _policy |
asPolicy() |
List<Policy> | 将别名为_policy的DataItem映射为Policy对象列表 |
| TABLE | _user |
asUsers() |
List<User> | 将别名为_user的DataItem映射为User对象列表 |
| TABLE | _statistic |
asStats() |
Stats | 将别名为_statistic的DataItem映射为一个Stats对象 |
| TABLE | _top |
asProcesses() |
List<Process> | 将别名为_top的DataItem映射为Process对象列表 |
| TABLE | _task |
asTasks() |
List<Task> | 将别名为_task的DataItem映射为Task对象列表 |
| TABLE | 任意 | asTable() |
Table | 将TABLE类型的DataItem映射为一个Table对象 |
| ATTR | 任意 | asAttr() |
Attr | 将ATTR类型的DataItem映射为一个Attr对象 |
驱动类型
所有驱动类型的对象均支持使用getter方法获取字段值,以及使用setter方法设定字段值,即便这些对象并未在下文中明确列出。
Node
Node对象包含以下字段:
| 字段 | 类型 | 描述 |
|---|---|---|
uuid |
Long | 点的UUID |
id |
String | 点的ID |
schema |
String | 点的schema |
values |
Value | 点的自定义属性 |
作用在Node对象上的方法:
方法 |
返回值 |
描述 |
|---|---|---|
get("<propertyName>") |
Object | 获取点的指定自定义属性的值 |
set("<propertyName>", <propertyValue>) |
设置点的指定自定义属性的值;若指定的<propertyName>不存在,则为点的values增加一个键值对 |
Response response = client.uql("find().nodes() as n return n{*} limit 5");
List<Node> nodeList = response.alias("n").asNodes();
System.out.println("ID of the 1st node: " + nodeList.get(0).getID());
System.out.println("Store name of the 1st node: " + nodeList.get(0).get("storeName"));
ID of the 1st node: 47370-257954
Store name of the 1st node: Meritxell, 96
Edge
Edge对象包含以下字段:
| 字段 | 类型 | 描述 |
|---|---|---|
uuid |
Long | 边的UUID |
fromUuid |
Long | 边的起点的UUID |
toUuid |
Long | 边的终点的UUID |
from |
String | 边的起点的ID |
to |
String | 边的终点的ID |
schema |
String | 边的schema |
values |
Value | 边的自定义属性 |
作用在Edge对象上的方法:
方法 |
返回值 |
描述 |
|---|---|---|
get("<propertyName>") |
Object | 获取边的指定自定义属性的值 |
set("<propertyName>", <propertyValue> |
设置边的指定自定义属性的值;若指定的<propertyName>不存在,则为边的values增加一个键值对 |
Response response = client.uql("find().edges() as e return e{*} limit 5");
Edge edge = response.alias("e").asFirstEdge();
System.out.println("Values of the 1st edge: " + edge.getValues());
Values of the 1st edge: {distanceMeters=20, duration=21s, staticDuration=25s, travelMode=Walk, transportationCost=46}
Path
Path对象包含以下字段:
| 字段 | 类型 |
描述 |
|---|---|---|
nodes |
List<Node> | 路径中的Node列表 |
edges |
List<Edge> | 路径中的Edge列表 |
nodeSchemas |
Map<String, Schema> | 路径中全部点schema的映射 |
edgeSchemas |
Map<String, Schema> | 路径中全部边schema的映射 |
作用在Path对象上的方法:
方法 |
返回值 |
描述 |
|---|---|---|
length() |
Integer | 获取路径的长度,即路径中的边数 |
Response response = client.uql("n().e()[:2].n() as paths return paths{*} limit 5");
List<Path> pathList = response.alias("paths").asPaths();
System.out.println("Length of the 1st path: " + pathList.get(0).length());
System.out.println("Edge list of the 1st path: " + pathList.get(0).getEdges());
System.out.println("Information of the 2nd node in the 1st path: " + pathList.get(0).getNodes().get(1).toJson());
Length of the 1st path: 2
Edge list of the 1st path: [Edge(uuid=591, fromUuid=20, toUuid=1, from=15219-158845, to=47370-257954, schema=transport, values={distanceMeters=10521283, duration=527864s, staticDuration=52606s, travelMode=Airplane, transportationCost=21043}), Edge(uuid=599, fromUuid=21, toUuid=20, from=15474-156010, to=15219-158845, schema=transport, values={distanceMeters=233389, duration=13469s, staticDuration=1167s, travelMode=Airplane, transportationCost=467})]
Information of the 2nd node in the 1st path: {"brand":"Starbucks","storeName":"Las Palmas","ownershipType":"Licensed","city":"Pilar","provinceState":"B","timezone":"GMT-03:00 America/Argentina/Bu","point":{"latitude":-33.39,"longitude":-60.22},"_uuid":20,"_id":"15219-158845","schema":"warehouse"}
Graph
Graph对象包含以下字段:
| 字段 | 类型 |
描述 |
|---|---|---|
nodes |
List<Node> | 路径中的Node列表 |
edges |
List<Edge> | 路径中的Edge列表 |
nodeSchemas |
Map<String, Schema> | 路径中全部点schema的映射 |
edgeSchemas |
Map<String, Schema> | 路径中全部边schema的映射 |
Response response = client.uql("n(as n1).re(as e).n(as n2).limit(3) with toGraph(collect(n1), collect(n2), collect(e)) as graph return graph");
Graph graph = response.alias("graph").asGraph();
List<Node> nodes = graph.getNodes();
List<Edge> edges = graph.getEdges();
System.out.println("Node IDs:");
for (Node node : nodes) {
System.out.println(node.getID());
}
System.out.println("Edge UUIDs:");
for (Edge edge : edges) {
System.out.println(edge.getUUID());
}
Node IDs:
ad304833
u604131
ad534784
ad6880
Edge UUIDs:
363347
774098
527786
3
GraphSet
GraphSet对象包含以下字段:
字段 |
类型 | 描述 |
|---|---|---|
id |
Integer | 图集ID |
name |
String | 图集名称 |
description |
String | 图集描述 |
totalNodes |
Long | 图集总点数 |
totalEdges |
Long | 图集总边数 |
status |
String | 图集属性,包括MOUNTED,MOUNTING和UNMOUNTED |
Response response = client.uql("show().graph()");
List<GraphSet> graphSetList = response.alias("_graph").asGraphSets();
for (GraphSet graphSet : graphSetList) {
if (graphSet.getStatus().equals("UNMOUNTED")) {
System.out.println(graphSet.getName());
}
}
DFS_EG
cyber
netflow
Schema
Schema对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
String | Schema名称 |
description |
String | Schema描述 |
properties |
List<Property> | Schema属性列表 |
dbType |
Ultipa.DBType | Schema 类型,包括DBNODE和DBEDGE |
total |
Integer | Schema的总点数或总边数 |
Response response = client.uql("show().node_schema()");
List<Schema> schemaList = response.alias("_nodeSchema").asSchemas();
for (Schema schema : schemaList) {
System.out.println(schema.getName() + " has " + schema.getTotal() + " nodes");
}
default has 0 nodes
user has 1092511 nodes
ad has 846811 nodes
Property
Property对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
String | 属性名称 |
description |
String | 属性描述 |
schema |
String | 属性的关联schema |
type |
String | 属性数据类型 |
lte |
Boolean | 属性LTE状态,包括true和false |
Response response = client.uql("show().node_property(@user)");
List<Property> propertyList = response.alias("_nodeProperty").asProperties();
for (Property property : propertyList) {
if (property.getLte()) {
System.out.println("LTE-ed property name: " + property.getName());
}
}
LTE-ed property name: cms_group_id
Algo
Algo对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
String | 算法名称 |
desc |
String | 算法描述 |
version |
String | 算法版本 |
detail |
String | 算法参数 |
Response res = client.uql("show().algo()");
List<Algo> algoList = res.alias("_algoList").asAlgos();
System.out.println(algoList.get(0).toString());
Algo(name=fastRP, desc={"name":"fastRP","description":"Fast and Accurate Network Embeddings via Very Sparse Random Projection","version":"1.0.1","parameters":{"dimension":"int,required","normalizationStrength":"float,optional, 0 as default","iterationWeights":"float[],optional,[0.0,1.0,1.0] as default","edge_schema_property":"optional,for weighted random projection","node_schema_property":"optional","propertyDimension":"int,optional, maximum value is dimension","limit":"optional,-1 for all results, >=0 partial results"},"write_to_db_parameters":{"property":"set write back property name for each schema and nodes"},"write_to_file_parameters":{"filename":"set file name"},"result_opt":"27"}, version=null, params=null)
Exta
Exta是由用户开发的自定义算法。
Exta对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
String | Exta名称 |
author |
String | Exta作者 |
version |
String | Exta版本 |
detail |
String | Exta的YML配置文件内容 |
Response response = client.uql("show().exta()");
List<Exta> extaList = response.alias("_extaList").asExtas();
System.out.println(extaList.get(0).getName());
page_rank
Index
Index对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
name |
String | 索引名称 |
properties |
String | 索引属性名称 |
schema |
String | 索引的schema名称 |
status |
String | 索引状态,包括done和creating |
size |
String | 索引大小,单位为字节 |
dbType |
Ultipa.DBType | 索引类型,包括DBNODE和DBEDGE |
Response response = client.uql("show().index()");
List<Index> indexList = response.alias("_nodeIndex").asIndexes();
for (Index index : indexList) {
System.out.println(index.getSchema() + " " + index.getProperties() + " " + index.getSize());
}
account name 0
movie name 2526
Response response = client.uql("show().fulltext()");
List<Index> indexList = response.alias("_edgeFulltext").asIndexes();
for (Index index : indexList) {
System.out.println(index.getName() + " " + index.getProperties() + " " + index.getSchema());
}
contentFull content review
Privilege
Privilege对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
systemPrivileges |
List<String> | 系统权限 |
graphPrivileges |
List<String> | 图权限 |
Response response = client.uql("show().privilege()");
Privilege privilege = response.alias("_privilege").asPrivilege();
System.out.println(privilege.getSystemPrivileges());
[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 | 策略名称 |
systemPrivileges |
List<String> | 策略中的系统权限 |
graphPrivileges |
Map<String, List<String>> | 策略中的图权限和对应图集 |
propertyPrivileges |
PropertyPrivilege | 策略中的属性权限 |
policies |
List<String> | 策略中的策略 |
Response response = client.uql("show().policy()");
List<Policy> policyList = response.alias("_policy").asPolicies();
for (Policy policy : policyList) {
System.out.println(policy.getName());
}
manager
operator
User
User对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
username |
String | 用户名 |
create |
String | 用户创建时间 |
systemPrivileges |
List<String> | 授予用户的系统权限 |
graphPrivileges |
Map<String, List<String>> | 授予用户的图权限和对应图集 |
propertyPrivileges |
PropertyPrivilege | 授予用户的属性权限 |
policies |
List<String> | 授予用户的策略 |
Response response = client.uql("show().user('Tester')");
List<User> user = response.alias("_user").asUsers();
System.out.println(user.get(0).toString());
User(username=Tester, create=Fri Jul 26 14:10:06 CST 2024, systemPrivileges=[MOUNT_GRAPH, SHOW_GRAPH], graphPrivileges={Ad_Click=[FIND_EDGE, FIND_NODE], DFS_EG=[UPDATE, INSERT]}, propertyPrivileges=PropertyPrivilege(node=PropertyPrivilegeElement(read=[], write=[], deny=[]), edge=PropertyPrivilegeElement(read=[], write=[], deny=[])), policies=[operator])
Stats
Stats对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
cpuUsage |
String | CPU使用百分比 |
memUsage |
String | 内存使用,单位为兆字节 |
expiredDate |
String | 许可证过期时间 |
cpuCores |
String | CPU核数 |
company |
String | 公司名称 |
serverType |
String | 服务器类型 |
version |
String | 服务器版本 |
Response response = client.uql("stats()");
Stats stats = response.get(0).asStats();
System.out.println("CPU usage: " + stats.getCpuUsage() + "%");
System.out.println("Memory usage: " + stats.getMemUsage());
CPU usage: 5.415697%
Memory usage: 9292.265625
Process
Process对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
processId |
String | 进程ID |
processUql |
String | 与进程一起运行的UQL |
status |
String | 进程状态 |
duration |
String | 任务已运行时长,单位为秒 |
RequestConfig requestConfig = new RequestConfig();
requestConfig.setGraphName("amz");
Response response = client.uql("top()", requestConfig);
List<Process> processList = response.alias("_top").asProcesses();
for (Process process : processList) {
System.out.println(process.getProcessId());
}
a_2_569_2
a_3_367_1
Task
Task对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
taskInfo |
TaskInfo | 任务信息包括taskId,serverId,algoName,startTime等 |
param |
Map<String, Object> | 算法参数和对应值 |
result |
Map<String, Object> | 算法结果和统计数据及对应值 |
errorMsg |
String | 任务错误信息 |
Response response = client.uql("show().task()", requestConfig);
List<Task> tasks = response.alias("_task").asTasks();
System.out.println(tasks.get(0).getTaskInfo().getAlgoName());
System.out.println(tasks.get(0).getParam().toString());
System.out.println(tasks.get(0).getResult().toString());
degree
{order=desc, limit=10}
{total_degree=590.000000, avarage_degree=1.940789, result_files=top10}
Table
Table对象包含以下字段:
字段 |
类型 |
描述 |
|---|---|---|
tableName |
String | 表格名称 |
headers |
List<Header> | 表头 |
rows |
List<List<Object>> | 表格行 |
作用在Table对象上的方法:
方法 |
返回值 |
描述 |
|---|---|---|
toKV() |
List<Value> | 将表的所有行转换成键值列表 |
Response response = client.uql("find().nodes() as n return table(n._id, n._uuid) as myTable limit 5");
Table table = response.alias("myTable").asTable();
System.out.println("2nd row in table: " + table.toKV().get(1));
2nd row in table: {n._id=u604510, n._uuid=2}
Attr
Attr对象包含以下字段:
Field |
Type |
Description |
|---|---|---|
name |
String | Attr名称 |
values |
List<Object> | Attr行 |
type |
Ultipa.PropertyType | Attr类型 |
Response response = client.uql("find().nodes({@ad}) as n return n.brand limit 5");
Attr attr = response.alias("n.brand").asAttr();
System.out.println(attr.getValues());
[14655, 14655, 14655, 14655, 434760]