Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shahargl opened this issue Mar 16, 2021 · 8 comments
Open
Labels
enhancement The issue is a request for improvement or a new feature status-triage_done Initial triage done, will be further handled by the driver team

Comments

@shahargl
Copy link

shahargl commented Mar 16, 2021

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:[email protected]/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

@github-actions github-actions bot changed the title Feature request: support async queries (sqlalchemy 1.4.0) SNOW-299559: Feature request: support async queries (sqlalchemy 1.4.0) Mar 16, 2021
@TRManderson
Copy link
Contributor

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 snowflakedb/snowflake-connector-python#38

@shahargl
Copy link
Author

Any updates?

@dbfreem
Copy link

dbfreem commented Feb 1, 2023

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

@alex-linx
Copy link

alex-linx commented May 4, 2023

+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
Copy link

Viciooo commented Aug 29, 2023

bump

1 similar comment
@David-Salazar
Copy link

bump

@sfc-gh-dszmolka sfc-gh-dszmolka added enhancement The issue is a request for improvement or a new feature status-triage_done Initial triage done, will be further handled by the driver team labels Mar 13, 2024
@sfc-gh-dszmolka
Copy link

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

@clbarnes
Copy link

clbarnes commented Nov 7, 2024

The snowflake connector does not necessarily need to be asyncio-compatible. The connector is thread safe https://docs.snowflake.com/en/developer-guide/python-connector/python-connector-api which means you can wrap any IO-bound sync calls in asyncio.to_thread. It's not as good as the connector supporting async directly but it's not a bad start.

It looks like we're not far off native async support, too snowflakedb/snowflake-connector-python#38 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement The issue is a request for improvement or a new feature status-triage_done Initial triage done, will be further handled by the driver team
Projects
None yet
Development

No branches or pull requests

8 participants