uql()
Method and class:
def uql(self,
uql: str,
requestConfig: ULTIPA_REQUEST.RequestConfig = ULTIPA_REQUEST.RequestConfig()
) -> ULTIPA_RESPONSE.UltipaResponse
Sending uql()
request will return class UltipaResponse.
UltipaResponse has below fields:
Field | Type | Description |
---|---|---|
aliases | List[ResultAlias] | aliases and types of each return value |
items | Dict | aliases and values (DataItem) of each return value |
explainPlan | ExplainPlan | UQL statement explanation tree |
req | ReturnReq | UQL request info |
status | Status | status of request execution |
statistics | UltipaStatistics | statistics of request execution, including timecost, metadata affected, etc. |
UltipaResponse has below methods:
Method | Type | Description |
---|---|---|
Print() | output to console in table format | |
toJson(pretty: bool) | str | convert to json formatted string, either with linefeed (pretty=true) or not (as defaulted) |
toDict() | Dict | convert to dict format |
get(index: int) | DataItem | acquire an alias as DataItem by index |
alias(alias: str) | DataItem | acquire an alias as DataItem by name |
Alias types such as NODE, EDGE and PATH can be connverted to corresponding classes using methods of class DataItem, see next chapter Alias Structs for detail.
Print()
Example: Send UQL show().grpah()
to server and print the result in table format
from ultipa import Connection, UltipaConfig
# omit code of establishing server connection 'conn' using graphset 'default'
req = conn.uql("show().graph()")
req.Print()
Output:
+----------------+
| STATUS |
+------+---------+
| Code | Message |
+------+---------+
| 0 | |
+------+---------+
+------------------------------------------------------+
| Statistics |
+--------------+--------------+------------+-----------+
| edgeAffected | nodeAffected | engineCost | totalCost |
+--------------+--------------+------------+-----------+
| 0 | 0 | 0 | 0 |
+--------------+--------------+------------+-----------+
+--------------------------------------------------------------------------------------------+
| Alias: _graph AliasType: TABLE |
+------+---------------+------------+------------+-------------------------------+-----------+
| id | name | totalNodes | totalEdges | description | status |
+------+---------------+------------+------------+-------------------------------+-----------+
| 1046 | amz | 403393 | 3387374 | | MOUNTED |
| 0 | default | 111 | 274 | System default graph! | MOUNTED |
| 1332 | miniCircle | 303 | 1961 | | MOUNTED |
| 1024 | newTest | 14 | 7 | rename test as newTest | MOUNTED |
+------+---------------+------------+------------+-------------------------------+-----------+
toJson()
Example: Send UQL find().nodes(1) as nodes return nodes
to server and print the result in json format with linefeed
from ultipa import Connection, UltipaConfig
# omit code of establishing server connection 'conn' using graphset 'default'
req = conn.uql("find().nodes(1) as nodes return nodes")
print(req.toJSON(True))
Output:
{
"aliases": [
{
"alias": "nodes",
"result_type": "NODE"
}
],
"explainPlan": [],
"items": {
"nodes": {
"alias": "nodes",
"data": [
{
"id": "",
"schema": "account",
"uuid": 1,
"values": {}
}
],
"type": "NODE"
}
},
"req": null,
"statistics": {
"edgeAffected": 0,
"engineCost": 0,
"nodeAffected": 0,
"totalCost": 0
},
"status": {
"clusterInfo": {
"leader": null,
"raftPeers": [],
"redirect": ""
},
"code": 0,
"message": ""
}
}
toDict()
Example: Send UQL find().nodes(1) as nodes return nodes
to server and print the result in json format
from ultipa import Connection, UltipaConfig
# omit code of establishing server connection 'conn' using graphset 'default'
req = conn.uql("find().nodes(1) as nodes return nodes")
print(req.toDict())
Output:
{'aliases': [], 'explainPlan': [], 'items': {}, 'req': None, 'statistics': {'edgeAffected': 0, 'engineCost': 0, 'nodeAffected': 0, 'totalCost': 0}, 'status': {'clusterInfo': {'leader': None, 'raftPeers': [], 'redirect': ''}, 'code': 0, 'message': ''}}
get()
Example: Send UQL find().nodes({@account}) as nodes return nodes.name, nodes.gender limit 5
to server and print the first alias in json format with linefeed
from ultipa import Connection, UltipaConfig
# omit code of establishing server connection 'conn' using graphset 'default'
req = conn.uql("find().nodes({@customer}) as nodes return nodes.nickname, nodes.gender limit 5")
print(req.get(0).toJSON(True))
Output:
{
"alias": "nodes.nickname",
"data": {
"name": "nodes.nickname",
"rows": [
"jo",
"jibber-jabber",
"HolyC",
"pixiedust",
"tommy"
],
"type": "string"
},
"type": "ATTR"
}
alias()
Example: Send UQL find().nodes({@account}) as nodes return nodes.name, nodes.gender limit 5
to server and print the 2nd alias in json format with linefeed
from ultipa import Connection, UltipaConfig
# omit code of establishing server connection 'conn' using graphset 'default'
req = conn.uql("find().nodes({@customer}) as nodes return nodes.nickname, nodes.gender limit 5")
print(req.alias("nodes.gender").toJSON(True))
Output:
{
"alias": "nodes.gender",
"data": {
"name": "nodes.gender",
"rows": [
"female",
"female",
"male",
"female",
"male"
],
"type": "string"
},
"type": "ATTR"
}