DataItem
Using methods get()
and alias()
of Response will return class DataItem.
DataItem has below methods:
Method | Type | Description |
---|---|---|
asNodes() | List<Node> | convert DataItem of NODE type to List<Node> |
asFirstNode() | Node | acquire the first Node from DataItem of NODE type, equivalent of asNodes().get(0) |
asEdges() | List<Edge> | convert DataItem of EDGE type to List<Edge> |
asFirstEdge() | Edge | acquire the first Edge from DataItem of EDGE type, equivalent of asEdges().get(0) |
asPaths() | List<Path> | convert DataItem of PATH type to List<Path> |
asGraphs() | List<Graph> | convert DataItem with alias _graph to List<Graph> |
asSchemas() | List<Schema> | convert DataItem with alias _nodeSchema or _edgeSchema to List<Schema> |
asProperties() | List<Property> | convert DataItem with alias _nodeProperty or _edgeProperty to List<Property> |
asAlgos() | List<Algo> | convert DataItem with alias _algoList to List<Algo> |
asTable() | Table | convert DataItem of TABLE type to Table |
asArray() | UqlArray | convert DataItem of ARRAY type to UqlArray |
asAttr() | Attr | convert DataItem of ATTR type to Attr |
toJson() | String | convert DataItem of any type to json formatted string |
It is also legal to convert DataItem with alias _graph, _nodeSchema, _edgeSchema, etc., to Table using method
asTable()
.
Node
Node has below fields:
Field | Type | Description |
---|---|---|
id | String | Node ID |
uuid | Long | Node UUID |
schema | String | Node Schema |
values | Value | Node customer properties |
Node has below methods:
Method | Type | Description |
---|---|---|
getID() | String | acquire ID of current Node |
getUUID() | Long | acquire UUID of current Node |
getSchema() | String | acquire Schema of current Node |
getValues() | Value | acquire Values (custom properties) of current Node |
get(String propName) | Object | acquire a custom property of current Node |
set(String propName, Object propValue) | set a custom property of current Node, or add KV pair if 'propName' is not an existing key | |
toJson() | String | convert current Node to json formatted string |
toString() | String | convert current Node to string |
Example: Send UQL query for a node list, print the ID of 2nd node, and set 'rating' of the 1st node to 8
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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"));
}
}
Output:
ID of 2nd node is: ULTIPA80000000000003EA
rating of 1st node was: 9
rating of 1st node now is: 8
Edge
Edge has below fields:
Field | Type | Description |
---|---|---|
uuid | Long | Edge UUID |
fromUuid | Long | Edge start node UUID |
toUuid | Long | Edge end node UUID |
from | String | Edge start node ID |
to | String | Edge end node ID |
schema | String | Edge Schema |
values | Value | Edge customer properties |
Edge has below methods:
Method | Type | Description |
---|---|---|
getUUID() | Long | acquire UUID of current Edge |
getFromUUID() | Long | acquire UUID of start node of current Edge |
getToUUID() | Long | acquire UUID of end node of current Edge |
getFrom() | String | acquire ID of start node of current Edge |
getTo() | String | acquire ID of end node of current Edge |
getSchema() | String | acquire Schema of current Edge |
getValues() | Value | acquire Values (custom properties) of current Edge |
get(String propName) | Object | acquire a custom property of current Edge |
set(String propName, Object propValue) | set a custom property of current Edge, or add KV pair if 'propName' is not an existing key | |
toJson() | String | convert current Edge to json formatted string |
toString() | String | convert current Edge to string |
Example: Send UQL query for an edge list, print the ID of the start node of the 2nd edge, and add 'time' for the 1st edge and set to '2022-04-13 09:23:24'
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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"));
}
}
Output:
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 has below fields:
Field | Type | Description |
---|---|---|
nodes | List<Node> | Node list of Path |
edges | List<Edge> | Edge list of Path |
nodeSchemas | Map<String, Schema> | Map of all node schemas of Path |
edgeSchemas | Map<String, Schema> | Map of all edge schemas of Path |
Path has below methods:
Method | Type | Description |
---|---|---|
length() | int | acquire length of current Path, namely the number of Edge |
getNodes() | List<Node> | acquire Node list of current Path |
getEdges() | List<Edge> | acquire Edge list of current Path |
toJson() | String | convert current Path to json formatted string |
toString() | String | convert current Path to string |
Example: Send UQL query for a path list, print the 2nd node of the 1st path
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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());
}
}
Output:
the 2nd node in the 1st path: {"name":"Meng","industry":"Construction","gender":"female","year":1982,"_uuid":20,"_id":"ULTIPA8000000000000014","schema":"account"}
Graph
Graph has below fields:
Field | Type | Description |
---|---|---|
id | int | Graph ID |
name | String | Graph name |
description | String | Graph description |
totalNodes | long | Graph total number of nodes |
totalEdges | long | Graph total number of edges |
status | String | Graph status (MOUNTED or UNMOUNTED) |
Graph has below methods:
Method | Type | Description |
---|---|---|
getId() | int | acquire current Graph ID |
getName() | String | acquire current Graph name |
getDescription() | String | acquire current Graph description |
getTotalNodes() | long | acquire current Graph total number of nodes |
getTotalEdges() | long | acquire current Graph total number of edges |
getStatus() | String | acquire current Graph status |
Example: Send UQL query for a graph list, print the name of the 3rd graph
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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());
}
}
Output:
name of 3rd graph is: miniCircle
Schema
Schema has below fields:
Field | Type | Description |
---|---|---|
name | String | Schema name |
description | String | Schema description |
properties | List<Property> | Property list of Schema |
dbType | Ultipa.DBType | Schema type (Node or Edge) |
total | int | Schema total number of nodes/edges |
Schema has below methods:
Method | Type | Description |
---|---|---|
getName() | String | acquire current Schema name |
getDescription() | String | acquire current Schema description |
getProperties() | List<Property> | acquire Property list of current Schema |
getDbType() | Ultipa.DBType | acquire current Schema type |
getTotal() | int | acquire current Schema total number of nodes/edges |
toString() | String | convert current Schema to string |
Example: Send UQL query for a node schema list, print the number of nodes of the 3rd node schema
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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());
}
}
Output:
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 has below fields:
Field | Type | Description |
---|---|---|
name | String | Property name |
description | String | Property description |
schema | String | Property Schema |
type | String | Property data type |
lte | Boolean | Property LTE status (true or false) |
Property has below methods:
Method | Type | Description |
---|---|---|
getName() | String | acquire current Property name |
getDescription() | String | acquire current Property description |
getSchema() | String | acquire current Property Schema |
getType() | String | acquire current Property data type |
getLte() | Boolean | acquire current Property LTE status |
toString() | String | convert current Property to string |
Example: Send UQL query for a node property list, print the LTE information of the 3rd node property
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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());
}
}
Output:
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 has below fields:
Field | Type | Description |
---|---|---|
name | String | Algo name |
desc | String | Algo description |
version | String | Algo version |
params | Map<String, AlgoParam> | Algo parameters |
Algo has below methods:
Method | Type | Description |
---|---|---|
getName() | String | acquire current Algo name |
getDesc() | String | acquire current Algo description |
getVersion() | String | acquire current Algo version |
getParams() | Map<String, AlgoParam> | acquire current Algo parameters |
toString() | String | convert current Algo to string |
Example: Send UQL query for an installed algorithm list, print the name and version of the 3rd algorithm
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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());
}
}
Output:
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 has below fields:
Field | Type | Description |
---|---|---|
tableName | String | Table alias |
headers | List<Header> | Table headers |
rows | List<List<Object>> | Table rows |
Table has below methods:
Method | Type | Description |
---|---|---|
getTableName() | String | acquire current Table alias |
getHeaders() | List<Header> | acquire current Table headers |
getRows() | List<List<Object>> | acquire current Table rows |
toJson() | String | convert current Table to json formatted string |
toKV() | List<Value> | convert current Table to KV list |
Example: Send UQL query for a table, print the 2nd row:
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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));
}
}
Output:
2nd row is: [female, 1989]
UqlArray
UqlArray is extended from ArrayList\<List\<Object>>
.
Example: Send UQL query for an array list, print the 3rd element of the 2nd array
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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));
}
}
Output:
2nd array is: [Meng, HolyC, pixiedust, sadmov]
3rd element of 2nd array is: pixiedust
Attr
Attr has below fields:
Field | Type | Description |
---|---|---|
name | String | Attr alias |
values | List<Object> | Attr rows |
type | Ultipa.PropertyType | Attr type |
Attr has below methods:
Method | Type | Description |
---|---|---|
getName() | String | acquire current Attr alias |
getValues() | List<Object> | acquire current Attr list |
getType() | Ultipa.PropertyType | acquire current Attr rows |
toJson() | String | convert current Attr to json formatted string |
Example: Send UQL query for an attribute list, print the 2nd attribute
public class Main {
public static void main(String[] args) {
// omit code of establishing server connection '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));
}
}
Output:
all attrs are: [Manufacturing, Health, Other, Education, Publishing]
2nd attr is: Health