trinodb / trino-python-client

Python client for Trino
Apache License 2.0
307 stars 150 forks source link

ORM support for engine without catalog #427

Closed olp966220 closed 6 months ago

olp966220 commented 7 months ago

Describe the feature

I use url : trino://username>:<password>@<host: to create engine and execute sql like 'SELECT * FROM catalog.shema.table', and it worked.

But when I try to use this url to do ORM operation, it can't get metadata or tables, for example:

  1. get metadata:

    metadata = Metadata(schema='catalog.schema') metadata.reflect(bind=engine) metadata.tables FacadeDict({}) # Shows it get none metadata by schema='catalog.schema'

  2. get table:

    metadata = Metadata(schema='catalog.schema') table = Table('table', metadata, autoload=True, autoload_with=engine) sqlalchemy.exc.NoSuchTableError: schema=catalog.schema, table=table

    I tried sql on 2 catalog and it worked: SELECT FROM catalog1.shema.table UNION ALL SELECT FROM catalog2.shema.table

But I also want to operate different ORM from different catalogs but use same engine, so I can operate like this:

session.query(ORM1, ORM2)

Describe alternatives you've considered

No response

Are you willing to submit PR?

hovaesco commented 6 months ago
olp966220 commented 6 months ago
table_with_catalog = Table(
    'nation',
    metadata,
    Column('nationkey', Integer),
    schema='tiny',
    trino_catalog='tpch',
)

It works ! Thx hovaesco !