UltipaDocs
Try Playground
  • Introduction
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Installation
    • Connection
      • Overview and Request Configuration
      • UQL Execution
      • GQL Execution
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Result Processing
    • Driver Data Classes
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Quick Start
    • Connect to Database
    • Query the Database
      • Graph
      • Schema and Property
      • Data Insertion
      • Query Acceleration
      • HDC Graph and Algorithm
      • Data Export
      • Process and Job
      • Access Control
    • Process Query Results
    • Data Structures
    • Installation
    • Connection
    • Request Configuration
    • UQL Execution
    • GQL Execution
    • Graphset Management
    • Schema and Property Management
    • Data Insertion and Deletion
    • Query Acceleration
    • Algorithm Management
    • Downloads and Exports
    • Process and Task Management
    • Access Management
    • Server Statistics
    • Result Processing
    • Types Mapping Ultipa and C#
  • RESTful API
  1. Docs
  2. /
  3. Ultipa Drivers
  4. /
  5. Python

Result Processing

The results from database read and write operations must be properly processed before being utilized in your application.

Return a Response

Methods such as gql() and uql() return a Response object. To serve the application, you need to first extract the DataItem from the Response object, and then transform it into an appropriate driver data class.

A Response object includes the following attributes:

Attribute
Type
Description
aliasesList[Alias]The list of result aliases; each Alias includes attributes name and type.
itemsDict[str, DataItem]A dictionary where each key is an alias name and each value is the corresponding data item.
explainPlanExplainPlanThe execution plan.
statusStatusThe status of the execution, inlcuding attributes code and message.
statisticsStatisticsStatistics related to the execution, including attributes nodeAffected, edgeAffected, totalCost, and engineCost.

Extract DataItem

To extract DataItem from a Response object, use the get() or alias() method.

A DataItem object includes the following attributes:

Attribute
Type
Description
aliasstrThe alias name.
typeResultTypeThe type of the results.
entitiesanyThe result entities.

get()

Retrieves data by the alias index.

Parameters

  • index: int: Index of the alias.

Returns

  • DataItem: The returned data.
Python
response = Conn.gql("MATCH (n)-[e]->() RETURN n, e LIMIT 3")
print(response.get(0).toJSON())

The GQL query returns two aliases (n, e), and the get() method gets the DataItem of the alias n at index 0.

Output
{"alias": "n", "entities": [{"uuid": 72059793061183504, "id": "ULTIPA800000000000003B", "schema": "account", "values": {"gender": "female", "industry": "Publishing", "name": "Velox", "year": 1976}}, {"uuid": 648520545364606993, "id": "ULTIPA800000000000003E", "schema": "account", "values": {"gender": "female", "industry": "Food&Beverage", "name": "Claire", "year": 1989}}, {"uuid": 720578139402534937, "id": "ULTIPA8000000000000050", "schema": "account", "values": {"gender": "male", "industry": "Education", "name": "Holly", "year": 2000}}], "type": "NODE"}

alias()

Retrieves data by the alias name.

Parameters

  • alias: str: Name of the alias.

Returns

  • DataItem: The returned data.
Python
response = Conn.gql("MATCH (n)-[e]->() RETURN n, e LIMIT 3")
print(response.alias("e").toJSON())

The GQL query returns two aliases (n, e), and the alias() method gets DataItem of the alias e.

Output
{"alias": "e", "entities": [{"schema": "agree", "uuid": 139, "fromId": "ULTIPA800000000000000E", "toId": "ULTIPA800000000000000D", "fromUuid": 6269012880322985990, "toUuid": 7998395137233256453, "values": {"targetPost": 905, "timestamp": 1572662452, "datetime": "2019-11-02 18:40:52"}}, {"schema": "agree", "uuid": 167, "fromId": "ULTIPA800000000000000E", "toId": "ULTIPA800000000000000F", "fromUuid": 6269012880322985990, "toUuid": 8214567919347040263, "values": {"targetPost": 1419, "timestamp": 1554431053, "datetime": "2019-04-05 18:24:13"}}, {"schema": "agree", "uuid": 15, "fromId": "ULTIPA8000000000000065", "toId": "ULTIPA8000000000000067", "fromUuid": 6629300850512625701, "toUuid": 5764609722057490465, "values": {"targetPost": 1374, "timestamp": 1552775174, "datetime": "2019-03-17 14:26:14"}}], "type": "EDGE"}

Transform DataItem

You should use a as<DataStructure>() method to convert the DataItem.entities into the corresponding driver data class.

For example, the GQL query contained in the request below retrieves 3 nodes from the graph, the asNodes() method is used to convert the DataItem associated with the alias n into a list of Node objects:

Python
response = Conn.gql("MATCH (n) RETURN n LIMIT 3")
nodeList = response.alias('n').asNodes()
for node in nodeList:
    print(node.getID())

The following lists all the transformation methods available on DataItem. Please note the applicable DataItem.type and DataItem.alias of each method.

Method
DataItem.type
DataItem.alias
Returns
Description
asNodes()NODEAnyList[Node]Converts to a list of Node objects.
asFirstNode()NODEAnyNodeConverts the first returned entity to a Node object.
asEdges()EDGEAnyList[Edge]Converts to a list of Edge objects.
asFirstEdge()EDGEAnyEdgeConverts the first returned entity to an Edge object.
asGraph()GRAPHAnyGraphConverts to a Graph object.
asGraphSets()TABLE_graphList[GraphSet]Converts to a list of GraphSet objects.
asSchemas()TABLE_nodeSchema, _edgeSchemaList[Schema]Converts to a list of Schema objects.
asProperties()TABLE_nodeProperty, _edgePropertyList[Property]Converts to a list of Property objects.
asAttr()ATTRAnyAttrConverts to an Attr object.
asTable()TABLEAnyTableConverts to a Table object.
asHDCGraphs()TABLE_hdcGraphListList[HDCGraph]Converts to a list of HDCGraph objects.
asAlgos()TABLE_algoListList[Algo]Converts to a list of Algo objects.
asProjections()TABLE_projectionListList[Projection]Converts to a list of Projection objects.
asIndexes()TABLE_nodeIndex, _edgeIndex, _nodeFulltext, _edgeFulltextList[Index]Converts to a list of Index objects.
asPrivilieges()TABLE_privilegeList[Priviliege]Converts to a list of Priviliege objects.
asPolicies()TABLE_policyList[Policy]Converts to a list of Policy objects.
asUsers()TABLE_userList[User]Converts to a list of User objects.
asProcesses()TABLE_topList[Process]Converts to a list of Process objects.
asJobs()TABLE_jobList[Job]Converts to a list of Job objects.

Return a ResponseWithExistCheck

Methods such as createGraphIfNotExist() return a ResponseWithExistCheck object.

A ResponseWithExistCheck object includes the following attributes:

Attribute
Type
Description
existboolWhether the object to create already exist.
responseResponseMain response of the method.

Return an InsertResponse

Some data insertion methods such as insertNodesBatchBySchema() and insertNodesBatchAuto() return an InsertResponse object.

An InsertResponse object includes the following attributes:

Attribute
Type
Description
idsList[str]The list of _ids of the inserted nodes; note that the list is empty when InsertRequestConfig.silent is True.
uuidsList[int]The list of _uuids of the inserted edges; note that the list is empty when InsertRequestConfig.silent is True.
errorItemsDict[int,InsertErrorCode]A dictionary containing error details, where each key represents the index of a node or edge with an error, and the value is the error code.
statusStatusThe status of the execution, inlcuding attributes code and message.
statisticsStatisticsStatistics releated to the execution, including attributes nodeAffected, edgeAffected, totalCost, and engineCost.

Return a JobResponse

Methods such as createFulltext() return a JobResponse object.

A JobResponse object includes the following attributes:

Attribute
Type
Description
jobIdstrID of the job of the execution.
statusStatusThe status of the execution, inlcuding attributes code and message.
statisticsStatisticsStatistics releated to the execution, including attributes nodeAffected, edgeAffected, totalCost, and engineCost.

Return Driver Data Classes

Some methods return either a single instance or a list of driver data class, which can be used directly. For example:

  • The getGraph() method returns a single GraphSet object.
  • The showGraph() method returns List[GraphSet].