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. Database Operations

UQL Execution

This section introduces the uql() and uqlStream() methods to execute UQL in the database.

NOTE

UQL (Ultipa Query Language) is the native language designed by Ultipa to fully interact with Ultipa graph databases. For detailed information on UQL, refer to the documentation.

uql()

Executes a UQL query in the database.

Parameters

  • uql: str: The UQL query to be executed.
  • config: RequestConfig (Optional): Request configuration.

Returns

  • Response: Response of the request.
Python
## Retrieves 5 movie nodes from the graph 'miniCircle'

requestConfig = RequestConfig(graph="miniCircle")
response = Conn.uql("find().nodes({@movie}) as n return n{*} limit 5", requestConfig)
nodeList = response.alias("n").asNodes()
for node in nodeList:
    print(node.get("name"))
Output
The Shawshank Redemption
Farewell My Concubine
Léon: The Professional
Titanic
Life is Beautiful

uqlStream()

Executes a UQL query in the database and returns the results incrementally, allowing handling of large datasets without loading everything into memory at once.

Parameters

  • uql: str: The UQL query to be executed.
  • cb: QueryResponseListener: Listener for the streaming process.
  • config: RequestConfig (Optional): Request configuration.

Returns

  • None
Python
# Retrieves all 1-step paths from the graph 'miniCircle'

requestConfig = RequestConfig(graph="miniCircle")

# Define the event handler functions
def on_start(requestConfig):
    print("Stream started.")

def on_data(res, requestConfig):
    print("Data received:", res)

def on_end(requestConfig):
    print("Stream ended.")

stream = QueryResponseListener()
stream.on("start", on_start)
stream.on("data", on_data)
stream.on("end", on_end)
uql = 'n().e().n() as p return p{*}'
result = Conn.uqlStream(uql, stream, requestConfig)
print()
Output
Stream started.
Data received: {'status': <ultipa.types.types.Status object at 0x000001E01762FCA0>, 'items': {'paths': <ultipa.types.types.DataItem object at 0x000001E017635730>}, 'aliases': None, 'req': None, 'statistics': <ultipa.types.types.UltipaStatistics object at 0x000001E017635850>, 'explainPlan': None}
Data received: {'status': <ultipa.types.types.Status object at 0x000001E01762F2B0>, 'items': {'paths': <ultipa.types.types.DataItem object at 0x000001E0189C4DF0>}, 'aliases': None, 'req': None, 'statistics': <ultipa.types.types.UltipaStatistics object at 0x000001E0189C4D60>, 'explainPlan': None}
Stream ended.

Full Example

example.py
from ultipa import UltipaConfig, Connection, RequestConfig

ultipaConfig = UltipaConfig()
# URI example: ultipaConfig.hosts = ["mqj4zouys.us-east-1.cloud.ultipa.com:60010"]
ultipaConfig.hosts = ["192.168.1.85:60061", "192.168.1.87:60061", "192.168.1.88:60061"]
ultipaConfig.username = "<username>"
ultipaConfig.password = "<password>"

Conn = Connection.NewConnection(defaultConfig=ultipaConfig)

# Retrieves 5 movie nodes from the graph 'miniCircle'

requestConfig = RequestConfig(graph="miniCircle")
response = Conn.uql("find().nodes({@movie}) as n return n{*} limit 5", requestConfig)
nodeList = response.alias("n").asNodes()
for node in nodeList:
    print(node.get("name"))