snowflakedb / snowflake-sqlalchemy

Snowflake SQLAlchemy
https://pypi.python.org/pypi/snowflake-sqlalchemy/
Apache License 2.0
231 stars 152 forks source link

SNOW-299559: Feature request: support async queries (sqlalchemy 1.4.0) #218

Open shahargl opened 3 years ago

shahargl commented 3 years ago

What is the current behavior?

SQLAlchemy 1.4.0 introduced the asyncio extension that add the ability to run queries in paralell.

The following code should create async engine:

engine = create_async_engine('snowflake://shahar:PASSWORD@ACCOUNT.us-central1.gcp/TEST?cache
   ...: _column_metadata=True&client_session_keep_alive=True&warehouse=TEST')

But instead it throws the following error:

----> 1 engine = create_async_engine(u, echo=True)

~/git/tmp/lib/python3.9/site-packages/sqlalchemy/ext/asyncio/engine.py in create_async_engine(*arg, **kw)
     46     kw["future"] = True
     47     sync_engine = _create_engine(*arg, **kw)
---> 48     return AsyncEngine(sync_engine)
     49 
     50 

~/git/tmp/lib/python3.9/site-packages/sqlalchemy/ext/asyncio/engine.py in __init__(self, sync_engine)
    536     def __init__(self, sync_engine: Engine):
    537         if not sync_engine.dialect.is_async:
--> 538             raise exc.InvalidRequestError(
    539                 "The asyncio extension requires an async driver to be used. "
    540                 f"The loaded {sync_engine.dialect.driver!r} is not async."

InvalidRequestError: The asyncio extension requires an async driver to be used. The loaded 'snowflake' is not async.

What is the desired behavior?

The engine will be created successfully

How would this improve snowflake-sqlalchemy?

It'll support running async queries

References, Other Background

https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html

TRManderson commented 3 years ago

I'd be happy to provide asyncio SQLAlchemy support as an external contributor, but that would require asyncio support for the underlying connection, which doesn't look like it's coming any time soon https://github.com/snowflakedb/snowflake-connector-python/issues/38

shahargl commented 2 years ago

Any updates?

dbfreem commented 1 year ago

Any update on this? Asyncio support would be a nice feature to add.

alex-linx commented 1 year ago

+1 We are also using snowflake and this has a significant negative affect on performance. We have to rely on workaround with multiprocessing/multithreading etc. The alternative of using snowflake connector directly means losing all the benefits of an ORM, which is unacceptable

Viciooo commented 1 year ago

bump

David-Salazar commented 8 months ago

bump

sfc-gh-dszmolka commented 4 months ago

hi folks, thanks for all the feedback. Prerequisite I guess would be the Snowflake PythonConnector to support asyncio (https://github.com/snowflakedb/snowflake-connector-python/issues/38) first.