Skip to content

Expose query ID during query execution (not only after completion) #578

@EdenKik

Description

@EdenKik

Expected behavior

The query ID should be available as soon as the statement is submitted and the coordinator responds — while the query is still running.

Actual behavior

With the 0.332.0 version of trino-python-client, the query ID cannot be retrieved until after cursor.execute() has finished.
For example:

cursor.execute(sql)
print(cursor.query_id)  # not available until finished

The call to cursor.execute() is fully blocking, so the query ID is only accessible after the query has finished.
This makes it impossible to log or monitor queries while they are still in-flight.

In past versions (not 100% sure which, since I used a wrapper library around this client), I believe the query ID was available earlier in the execution lifecycle. At least, I was able to log it while the query was still running.
Right now, the only way I was managed to think of is to wrap cursor.execute in a separate thread/async task and poll internal attributes (cursor.query_id), which is not ideal for me.

Steps To Reproduce

cursor.execute(sql)
print(cursor.query_id)  # not available until finished

Log output

No response

Operating System

Trino Python client version

0.332.0

Trino Server version

475

Python version

3.11.4

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions