trinodb / trino-python-client

Python client for Trino
Apache License 2.0
327 stars 163 forks source link

How to get infoUri before query finishes #388

Open zyxue opened 1 year ago

zyxue commented 1 year ago

Expected behavior

execute returns soon after it's run so that infoUri can be available for tracking.

Actual behavior

executes is blocked until at least one row is received or query is finished or cancelled (https://github.com/trinodb/trino-python-client/blob/0.326.0/trino/client.py#L819-L821)

Steps To Reproduce

from trino.dbapi import connect

conn = connect(
    host="<host>",
    port=<port>,
    user="<username>",
    catalog="<catalog>",
    schema="<schema>",
)
cur = conn.cursor()
result = cur.execute("SELECT * FROM system.runtime.nodes") # this used to return quickly, but not anymore.

Log output

No response

Operating System

NAME="Ubuntu" VERSION="20.04.4 LTS (Focal Fossa)"

Trino Python client version

0.319.0

Trino Server version

419

Python version

3.8.13

Are you willing to submit PR?

hashhar commented 1 year ago

What do you actually plan to do? Maybe there's an alternative.

We intentionally changed the behaviour to fix a bug where queries which don't return result sets silently swallowed errors. It has the side effect to make the client API easier to use since users no longer need to call fetch methods to actually start the query. See https://github.com/trinodb/trino-python-client/pull/220 and the release notes/CHANGES.md for that version.

zyxue commented 1 year ago

Is it possible to expose a method that does the non-blocking stuff (esp. self._info_uri = status.info_uri) before the blocking while loop?