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转换成字符串 |
示例:发送嬴图GQL语句查询一列点,获取第二个点的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转换成字符串 |
示例:发送嬴图GQL语句查询一列边,获取第二个边的起点的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转换成字符串 |
示例:发送嬴图GQL语句查询一列路径,获取第一个路径的第二个点
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的状态 |
示例:发送嬴图GQL语句查询图集列表,获取第三个图集的名称
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转换成字符串 |
示例:发送嬴图GQL语句查询当前图集的点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转换成字符串 |
示例:发送嬴图GQL语句查询当前图集的点属性列表,获取第三个点属性的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转换成字符串 |
示例:发送嬴图GQL语句查询已安装的算法列表,获取第三个算法的名称及版本
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列表 |
示例:发送嬴图GQL语句查询一个表格,获取该表格的第二行数据
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>> 。
示例:发送嬴图GQL语句查询一列数组,获取第二个数组的第三个元素
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格式的字符串 |
示例:发送嬴图GQL语句查询一列属性,获取第二个属性
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