DataItem
使用 Response 的 get()
、alias()
方法时将获得 DataItem 类。
DataItem 的方法:
方法 | 类型 | 说明 |
---|---|---|
asNodes() | List<Node> | 将 NODE 类型的 DataItem 转为 List<Node> |
asFirstNode() | Node | 取出 NODE 类型的 DataItem 中的第一个 Node,相当于 asNodes().get(0) |
asEdges() | List<Edge> | 将 EDGE 类型的 DataItem 转为 List<Edge> |
asFirstEdge() | Edge | 取出 EDGE 类型的 DataItem 中的第一个 Edge,相当于 asEdges().get(0) |
asPaths() | List<Path> | 将 PATH 类型的 DataItem 转为 List<Path> |
asGraphs() | List<Graph> | 将默认别名 _graph 的 DataItem 转为 List<Graph> |
asSchemas() | List<Schema> | 将默认别名 _nodeSchema、_edgeSchema 的 DataItem 转为 List<Schema> |
asProperties() | List<Property> | 将默认别名 _nodeProperty、_edgeProperty 的 DataItem 转为 List<Property> |
asAlgos() | List<Algo> | 将默认别名 _algoList 的 DataItem 转为 List<Algo> |
asTable() | Table | 将 TABLE 类型的 DataItem 转为 Table |
asArray() | UqlArray | 将 ARRAY 类型的 DataItem 转为 UqlArray |
asAttr() | Attr | 将 ATTR 类型的 DataItem 转为 Attr |
toJson() | String | 将任意类型的 DataItem 转为 json 格式的字符串 |
也可以使用方法
asTable()
将默认别名 _graph、_nodeSchema、_edgeSchema 等的 DataItem 转为 Table。
Node
Node 类的字段:
字段 | 类型 | 说明 |
---|---|---|
id | String | Node 的 ID |
uuid | Long | Node 的 UUID |
schema | String | Node 的 Schema |
values | Value | Node 的自定义属性 |
Node 类的方法:
方法 | 类型 | 说明 |
---|---|---|
getID() | String | 获取当前 Node 的 ID |
getUUID() | Long | 获取当前 Node 的 UUID |
getSchema() | String | 获取当前 Node 的 Schema |
getValues() | Value | 获取当前 Node 的 Values(自定义属性) |
get(String propName) | Object | 获取当前 Node 的某个自定义属性 |
set(String propName, Object propValue) | 设置当前 Node 的某个自定义属性,属性名不存在时将则添加该键值对 | |
toJson() | String | 将当前 Node 转换成 json 格式的字符串 |
toString() | String | 将当前 Node 转换成字符串 |
示例:发送 UQL 语句查询一列点,获取第二个点的 ID,同时将第一个点的 rating 改为 8 并输出
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("find().nodes({@movie}) as nodes return nodes{*} limit 5");
List<Node> nodeList = res.alias("nodes").asNodes();
Node firstNode = res.alias("nodes").asFirstNode();
System.out.println("ID of 2nd node is: " + nodeList.get(1).getID());
System.out.println("rating of 1st node was: " + firstNode.get("rating"));
firstNode.set("rating",8);
System.out.println("rating of 1st node now is: " + firstNode.get("rating"));
}
}
输出:
ID of 2nd node is: ULTIPA80000000000003EA
rating of 1st node was: 9
rating of 1st node now is: 8
Edge
Edge 类的字段:
字段 | 类型 | 说明 |
---|---|---|
uuid | Long | Edge 的 UUID |
fromUuid | Long | Edge 起点的 UUID |
toUuid | Long | Edge 终点的 UUID |
from | String | Edge 起点的 ID |
to | String | Edge 终点的 ID |
schema | String | Edge 的 Schema |
values | Value | Edge 的自定义属性 |
Edge 类的方法:
方法 | 类型 | 说明 |
---|---|---|
getUUID() | Long | 获取当前 Edge 的 UUID |
getFromUUID() | Long | 获取当前 Edge 起点的 UUID |
getToUUID() | Long | 获取当前 Edge 终点的 UUID |
getFrom() | String | 获取当前 Edge 起点的 ID |
getTo() | String | 获取当前 Edge 终点的 ID |
getSchema() | String | 获取当前 Edge 的 Schema |
getValues() | Value | 获取当前 Edge 的 Values(自定义属性) |
get(String propName) | Object | 获取当前 Edge 的某个自定义属性 |
set(String propName, Object propValue) | 设置当前 Edge 的某个自定义属性,属性名不存在时将则添加该键值对 | |
toJson() | String | 将当前 Edge 转换成 json 格式的字符串 |
toString() | String | 将当前 Edge 转换成字符串 |
示例:发送 UQL 语句查询一列边,获取第二个边的起点的 ID,为第一个边添加属性 time 并设置为 2022-04-13 09:23:24 后再将该边输出
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("find().edges({@default}) as edges return edges{*} limit 5");
List<Edge> edgeList = res.alias("edges").asEdges();
Edge firstEdge = res.alias("edges").asFirstEdge();
System.out.println("ID of start node of 2nd edge is: " + edgeList.get(1).getFrom());
System.out.println("time of 1st edge was: " + firstEdge.get("time"));
firstEdge.set("time",Timestamp.valueOf("2022-04-13 09:23:24"));
System.out.println("time of 1st edge now is: " + firstEdge.get("time"));
}
}
输出:
ID of start node of 2nd edge is: ULTIPA8000000000000001
time of 1st node was: null
time of 1st node now is: 2022-04-13 09:23:24.0
Path
Path 类的字段:
字段 | 类型 | 说明 |
---|---|---|
nodes | List<Node> | Path 中的 Node 列表 |
edges | List<Edge> | Path 中的 Edge 列表 |
nodeSchemas | Map<String, Schema> | Path 中的所有点 Schema 的映射 |
edgeSchemas | Map<String, Schema> | Path 中的所有边 Schema 的映射 |
Path 类的方法:
方法 | 类型 | 说明 |
---|---|---|
length() | int | 获取当前 Path 的长度,即 Edge 的数量 |
getNodes() | List<Node> | 获取当前 Path 的 Node 列表 |
getEdges() | List<Edge> | 获取当前 Path 的 Edge 列表 |
toJson() | String | 将当前 Path 转换成 json 格式的字符串 |
toString() | String | 将当前 Path 转换成字符串 |
示例:发送 UQL 语句查询一列路径,获取第一个路径的第二个点
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("n().e()[2].n() as paths return paths{*} limit 3");
List<Path> pathList = res.alias("paths").asPaths();
System.out.println("the 2nd node in the 1st path: " + pathList.get(0).getNodes().get(1).toJson());
}
}
输出:
the 2nd node in the 1st path: {"name":"Meng","industry":"Construction","gender":"female","year":1982,"_uuid":20,"_id":"ULTIPA8000000000000014","schema":"account"}
Graph
Graph 类的字段:
字段 | 类型 | 说明 |
---|---|---|
id | int | Graph 的 ID |
name | String | Graph 的名称 |
description | String | Graph 的描述 |
totalNodes | long | Graph 的点数量 |
totalEdges | long | Graph 的边数量 |
status | String | Graph 的状态(MOUNTED、UNMOUNTED) |
Graph 类的方法:
方法 | 类型 | 说明 |
---|---|---|
getId() | int | 获取当前 Graph 的 ID |
getName() | String | 获取当前 Graph 的名称 |
getDescription() | String | 获取当前 Graph 的描述 |
getTotalNodes() | long | 获取当前 Graph 的点数量 |
getTotalEdges() | long | 获取当前 Graph 的边数量 |
getStatus() | String | 获取当前 Graph 的状态 |
示例:发送 UQL 语句查询图集列表,获取第三个图集的名称
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("show().graph()");
List<Graph> graphList = res.alias("_graph").asGraphs();
System.out.println("name of 3rd graph is: " + graphList.get(2).getName());
}
}
输出:
name of 3rd graph is: miniCircle
Schema
Schema 类的字段:
字段 | 类型 | 说明 |
---|---|---|
name | String | Schema 的名称 |
description | String | Schema 的描述 |
properties | List<Property> | Schema 的 Property 列表 |
dbType | Ultipa.DBType | Schema 的点/边类型 |
total | int | Schema 的点/边数量 |
Schema 类的方法:
方法 | 类型 | 说明 |
---|---|---|
getName() | String | 获取当前 Schema 的名称 |
getDescription() | String | 获取当前 Schema 的描述 |
getProperties() | List<Property> | 获取当前 Schema 的 Property 列表 |
getDbType() | Ultipa.DBType | 获取当前 Schema 的点/边类型 |
getTotal() | int | 获取当前 Schema 的点/边数量 |
toString() | String | 将当前 Schema 转换成字符串 |
示例:发送 UQL 语句查询当前图集的点 schema 列表,获取第三个点 schema 的点的数量
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("show().node_schema()");
List<Schema> schemaList = res.alias("_nodeSchema").asSchemas();
System.out.println("3rd node schema is: " + schemaList.get(2).toString());
System.out.println("number of nodes of 3rd node schema is: " + schemaList.get(2).getTotal());
}
}
输出:
3rd node schema is: Schema(name=country, description=, properties=[Property(name=name, propertyType=null, type=string, lte=false, schema=null, description=, ignored=false)], dbType=DBNODE, total=23)
number of nodes of 3rd node schema is: 23
Property
Property 类的字段:
字段 | 类型 | 说明 |
---|---|---|
name | String | Property 的名称 |
description | String | Property 的描述 |
schema | String | Property 的 Schema |
type | String | Property 的数据类型 |
lte | Boolean | Property 的 LTE 状态(true、false) |
Property 类的方法:
方法 | 类型 | 说明 |
---|---|---|
getName() | String | 获取当前 Property 的名称 |
getDescription() | String | 获取当前 Property 的描述 |
getSchema() | String | 获取当前 Property 的 Schema |
getType() | String | 获取当前 Property 的数据类型 |
getLte() | Boolean | 获取当前 Property 的 LTE 状态 |
toString() | String | 将当前 Property 转换成字符串 |
示例:发送 UQL 语句查询当前图集的点属性列表,获取第三个点属性的 LTE 信息
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("show().node_property()");
List<Property> propertyList = res.alias("_nodeProperty").asProperties();
System.out.println("3rd node property is: " + propertyList.get(2).toString());
System.out.println("lte of 3rd node property is: " + propertyList.get(2).getLte());
}
}
输出:
3rd node property is: Property(name=timestamp, propertyType=TIMESTAMP, type=timestamp, lte=false, schema=movie, description=, ignored=false)
lte of 3rd node property is: false
Algo
Algo 类的字段:
字段 | 类型 | 说明 |
---|---|---|
name | String | Algo 的名称 |
desc | String | Algo 的描述 |
version | String | Algo 的版本 |
params | Map<String, AlgoParam> | Algo 的参数 |
Algo 类的方法:
方法 | 类型 | 说明 |
---|---|---|
getName() | String | 获取当前 Algo 的名称 |
getDesc() | String | 获取当前 Algo 的描述 |
getVersion() | String | 获取当前 Algo 的版本 |
getParams() | Map<String, AlgoParam> | 获取当前 Algo 的参数 |
toString() | String | 将当前 Algo 转换成字符串 |
示例:发送 UQL 语句查询已安装的算法列表,获取第三个算法的名称及版本
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("show().algo()");
List<Algo> algoList = res.alias("_algoList").asAlgos();
System.out.println("3rd algorithm is: " + algoList.get(2).toString());
System.out.println("name of 3rd algorithm is: " + algoList.get(2).getName());
System.out.println("version of 3rd algorithm is: " + algoList.get(2).getVersion());
}
}
输出:
3rd algorithm is: Algo(name=random_walk_struc2vec, desc={"name":"struc2vec walk","description":"struc2vec walk to generate the sample data for next-step training","version":"1.0.1","parameters":{"walk_length":"size_t,required","walk_num":"size_t,required","k":"size_t,required","stay_probability":"float,required","ids":"nodes","limit":"optional,-1 for all results, >=0 partial results"},"write_to_file_parameters":{"filename":"set file name"},"result_opt":"25"}, version=null, params=null)
name of 3rd algorithm is: random_walk_struc2vec
version of 3rd algorithm is: null
Table
Table 类的字段:
字段 | 类型 | 说明 |
---|---|---|
tableName | String | Table 的别名 |
headers | List<Header> | Table 的表头 |
rows | List<List<Object>> | Table 的所有行 |
Table 类的方法:
方法 | 类型 | 说明 |
---|---|---|
getTableName() | String | 获取当前 Table 的别名 |
getHeaders() | List<Header> | 获取当前 Table 的表头 |
getRows() | List<List<Object>> | 获取当前 Table 的所有行 |
toJson() | String | 将当前 Table 转换成 json 格式的字符串 |
toKV() | List<Value> | 将当前 Table 转换成 KV 列表 |
示例:发送 UQL 语句查询一个表格,获取该表格的第二行数据
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("find().nodes({@account}) limit 5 return table(nodes.gender, nodes.year) as myTable");
Table table = res.alias("myTable").asTable();
System.out.println("2nd row is: " + table.getRows().get(1));
}
}
输出:
2nd row is: [female, 1989]
UqlArray
UqlArray 类继承于二维集合 ArrayList<List<Object>> 。
示例:发送 UQL 语句查询一列数组,获取第二个数组的第三个元素
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("find().nodes({@account}) as nodes group by nodes.industry return collect(nodes.name) as myArray limit 3");
UqlArray array = res.alias("myArray").asArray();
System.out.println("2nd array is: " + array.get(1));
System.out.println("3rd element of 2nd array is: " + array.get(1).get(2));
}
}
输出:
2nd array is: [Meng, HolyC, pixiedust, sadmov]
3rd element of 2nd array is: pixiedust
Attr
Attr 类的字段:
字段 | 类型 | 说明 |
---|---|---|
name | String | Attr 的别名 |
values | List<Object> | Attr 的所有行 |
type | Ultipa.PropertyType | Attr 的类型 |
Attr 类的方法:
方法 | 类型 | 说明 |
---|---|---|
getName() | String | 获取当前 Attr 的别名 |
getValues() | List<Object> | 获取当前 Attr 的所有行 |
getType() | Ultipa.PropertyType | 获取当前 Attr 的类型 |
toJson() | String | 将当前 Attr 转换成 json 格式的字符串 |
示例:发送 UQL 语句查询一列属性,获取第二个属性
public class Main {
public static void main(String[] args) {
// 创建名为 conn 的连接,此部分代码省略
Response res = conn.uql("find().nodes({@account}) as nodes return nodes.industry as myAttr limit 5");
Attr attr = res.alias("myAttr").asAttr();
System.out.println("all attrs are: " + attr.getValues());
System.out.println("2nd attr is: " + attr.getValues().get(1));
}
}
输出:
all attrs are: [Manufacturing, Health, Other, Education, Publishing]
2nd attr is: Health