Skip to content

Adding compatibility with SQLAlchemy 2.0 - #457

Merged
bkyryliuk merged 1 commit into
dropbox:masterfrom
mdeshmu:sqlalchemy-2.0-support
Jul 8, 2023
Merged

Adding compatibility with SQLAlchemy 2.0#457
bkyryliuk merged 1 commit into
dropbox:masterfrom
mdeshmu:sqlalchemy-2.0-support

Conversation

@mdeshmu

@mdeshmumdeshmu commented Jun 23, 2023

Copy link
Copy Markdown
Contributor

Description

This PR includes minimal changes to add SQLAlchemy 2.0 support without breaking compatibility with SQLAlchemy 1.3 and SQLAlchemy 1.4.

Test Environment

SQLALchemy 1.3.24, 1.4.36, and 2.0.16 was used with this hive docker setup for running the test cases. Trino isn't present in that setup, so I added the below lines to docker-compose.yaml and copied trino config from pyhive repository to the Trino container as a volume. That's it, My testing setup was ready.

trino:
image: trinodb/trino:351
ports:
- "18080:18080"
volumes:
- ./trino:/etc/trino

Software versions used in test setup

Hive version - 2.3.2
Presto version - 0.181
Trino version - 351

Local test case run results:

  1. SQLAlchemy 1.3 + Hive

1 3-hive

  1. SQLAlchemy 1.3 + Presto

1 3-presto

  1. SQLAlchemy 1.3 + Trino

image

  1. SQLAlchemy 1.4 + Hive

1 4-hive

  1. SQLAlchemy 1.4 + Presto

1 4-presto

  1. SQLAlchemy 1.4 + Trino

image

  1. SQLAlchemy 2.0 + Hive

2 0-hive

  1. SQLAlchemy 2.0 + Presto

2 0-presto

  1. SQLAlchemy 2.0 + Trino

image

@mdeshmu
mdeshmuforce-pushed the sqlalchemy-2.0-support branch 2 times, most recently from d1bf344 to eb1ed24CompareJune 23, 2023 18:00
Comment threadpyhive/tests/test_sqlalchemy_hive.py
Comment threadpyhive/tests/test_sqlalchemy_presto.py
Comment threadpyhive/sqlalchemy_hive.py
Comment threadpyhive/sqlalchemy_hive.py
Comment threadpyhive/tests/sqlalchemy_test_case.py
Comment threadpyhive/tests/sqlalchemy_test_case.py Outdated
Comment threadpyhive/tests/sqlalchemy_test_case.py Outdated
Comment threadpyhive/tests/test_sqlalchemy_hive.py
@mdeshmumdeshmu changed the title Adding Compatibility with SQLAlchemy 2.0Adding compatibility with SQLAlchemy 2.0Jun 25, 2023
Comment threadpyhive/sqlalchemy_presto.py
@mdeshmu
mdeshmu marked this pull request as ready for review June 25, 2023 19:57
@mdeshmu
mdeshmuforce-pushed the sqlalchemy-2.0-support branch 3 times, most recently from 23f6cc2 to 49d582eCompareJune 27, 2023 14:09
Comment threadpyhive/sqlalchemy_hive.py
Comment threadpyhive/sqlalchemy_presto.py
Comment threadpyhive/tests/test_sqlalchemy_hive.py
@mdeshmu
mdeshmuforce-pushed the sqlalchemy-2.0-support branch from fae253b to 838727eCompareJune 28, 2023 06:39
@mdeshmu

Copy link
Copy Markdown
ContributorAuthor

@bkyryliuk This PR is ready for review.

Comment threadpyhive/tests/sqlalchemy_test_case.py Outdated
Comment threadpyhive/tests/test_sqlalchemy_hive.py

@bkyryliukbkyryliuk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LG%small nits

@mdeshmu
mdeshmuforce-pushed the sqlalchemy-2.0-support branch from 7d533b7 to 08d062fCompareJuly 8, 2023 02:09
@mdeshmu
mdeshmuforce-pushed the sqlalchemy-2.0-support branch from 419bd66 to 112c707CompareJuly 8, 2023 02:16
@bkyryliuk
bkyryliuk merged commit 5f0ee1f into dropbox:masterJul 8, 2023
@mdeshmumdeshmu mentioned this pull request Aug 22, 2023
9 tasks
@mdeshmu
mdeshmu deleted the sqlalchemy-2.0-support branch August 23, 2023 00:36
betodealmeida added a commit to preset-io/PyHive that referenced this pull request Aug 8, 2024
* feat: add HTTP and HTTPS to hive (dropbox#385)
* feat: add https protocol
* support HTTP
* fix: make hive https py2 compat (dropbox#389)
* fix: make hive https py2 compat
* fix lint
* Update README.rst (dropbox#423)
* chore: rename Trino entry point (dropbox#428)
* Support for Presto decimals (dropbox#430)
* Support for Presto decimals
* lower
* Use str type for driver and name in HiveDialect (dropbox#450)
PyHive's HiveDialect usage of bytes for the name and driver fields is not the norm is causing issues upstream: apache/superset#22316
Even other dialects within PyHive use strings. SQLAlchemy does not strictly require a string, but all the stock dialects return a string, so I figure it is heavily implied.
I think the risk of breaking something upstream with this change is low (but it is there ofc). I figure in most cases we just make someone's `str(dialect.driver)` expression redundant.
Examples for some of the other stock sqlalchemy dialects (name and driver fields using str):
https://github.com/zzzeek/sqlalchemy/blob/main/lib/sqlalchemy/dialects/sqlite/pysqlite.py#L501https://github.com/zzzeek/sqlalchemy/blob/main/lib/sqlalchemy/dialects/sqlite/base.py#L1891https://github.com/zzzeek/sqlalchemy/blob/main/lib/sqlalchemy/dialects/mysql/base.py#L2383https://github.com/zzzeek/sqlalchemy/blob/main/lib/sqlalchemy/dialects/mysql/mysqldb.py#L113https://github.com/zzzeek/sqlalchemy/blob/main/lib/sqlalchemy/dialects/mysql/pymysql.py#L59
* Correcting Iterable import for python 3.10 (dropbox#451)
* changing drivers to support hive, presto and trino with sqlalchemy>=2.0 (dropbox#448)
* Revert "changing drivers to support hive, presto and trino with sqlalchemy>=2.0 (dropbox#448)" (dropbox#452)
This reverts commit b0206d3.
* Update __init__.py (dropbox#453)
dropbox@1c1da8bdropbox@1f99552
* use pure-sasl with python 3.11 (dropbox#454)
* minimal changes for sqlalchemy 2.0 support (dropbox#457)
* update readme to reflect recent changes (dropbox#459)
* Update README.rst (dropbox#475)
* Update README.rst (dropbox#476)
* feat: JWT support
* Add CI to build package
---------
Co-authored-by: Daniel Vaz Gaspar <danielvazgaspar@gmail.com>
Co-authored-by: Bogdan <b.kyryliuk@gmail.com>
Co-authored-by: serenajiang <serena.jiang@airbnb.com>
Co-authored-by: Usiel Riedl <usiel.riedl@gmail.com>
Co-authored-by: Multazim Deshmukh <57723564+mdeshmu@users.noreply.github.com>
Co-authored-by: nicholas-miles <nicholas.miles6@gmail.com>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@mdeshmu@bkyryliuk