From b0206d3cb8a9f9a95a36feeae311f6b0141c6675 Mon Sep 17 00:00:00 2001 From: nicholas-miles Date: Wed, 17 May 2023 08:21:07 -0700 Subject: [PATCH] changing drivers to support hive, presto and trino with sqlalchemy>=2.0 (#448) --- pyhive/sqlalchemy_hive.py | 14 +++++++++++--- pyhive/sqlalchemy_presto.py | 8 ++++++-- pyhive/sqlalchemy_trino.py | 8 ++++++-- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/pyhive/sqlalchemy_hive.py b/pyhive/sqlalchemy_hive.py index f39f1793..34fdb648 100644 --- a/pyhive/sqlalchemy_hive.py +++ b/pyhive/sqlalchemy_hive.py @@ -13,11 +13,19 @@ import re from sqlalchemy import exc -from sqlalchemy import processors +try: + from sqlalchemy import processors +except ImportError: + # Newer versions of sqlalchemy require: + from sqlalchemy.engine import processors from sqlalchemy import types from sqlalchemy import util # TODO shouldn't use mysql type -from sqlalchemy.databases import mysql +try: + from sqlalchemy.databases.mysql import MSTinyInteger +except ImportError: + # Newer versions of sqlalchemy require: + from sqlalchemy.dialects.mysql import MSTinyInteger from sqlalchemy.engine import default from sqlalchemy.sql import compiler from sqlalchemy.sql.compiler import SQLCompiler @@ -121,7 +129,7 @@ def __init__(self, dialect): _type_map = { 'boolean': types.Boolean, - 'tinyint': mysql.MSTinyInteger, + 'tinyint': MSTinyInteger, 'smallint': types.SmallInteger, 'int': types.Integer, 'bigint': types.BigInteger, diff --git a/pyhive/sqlalchemy_presto.py b/pyhive/sqlalchemy_presto.py index a199ebe1..94d06412 100644 --- a/pyhive/sqlalchemy_presto.py +++ b/pyhive/sqlalchemy_presto.py @@ -13,7 +13,11 @@ from sqlalchemy import types from sqlalchemy import util # TODO shouldn't use mysql type -from sqlalchemy.databases import mysql +try: + from sqlalchemy.databases.mysql import MSTinyInteger +except ImportError: + # Newer versions of sqlalchemy require: + from sqlalchemy.dialects.mysql import MSTinyInteger from sqlalchemy.engine import default from sqlalchemy.sql import compiler from sqlalchemy.sql.compiler import SQLCompiler @@ -29,7 +33,7 @@ class PrestoIdentifierPreparer(compiler.IdentifierPreparer): _type_map = { 'boolean': types.Boolean, - 'tinyint': mysql.MSTinyInteger, + 'tinyint': MSTinyInteger, 'smallint': types.SmallInteger, 'integer': types.Integer, 'bigint': types.BigInteger, diff --git a/pyhive/sqlalchemy_trino.py b/pyhive/sqlalchemy_trino.py index 4b2b3698..686a42c7 100644 --- a/pyhive/sqlalchemy_trino.py +++ b/pyhive/sqlalchemy_trino.py @@ -13,7 +13,11 @@ from sqlalchemy import types from sqlalchemy import util # TODO shouldn't use mysql type -from sqlalchemy.databases import mysql +try: + from sqlalchemy.databases.mysql import MSTinyInteger +except ImportError: + # Newer versions of sqlalchemy require: + from sqlalchemy.dialects.mysql import MSTinyInteger from sqlalchemy.engine import default from sqlalchemy.sql import compiler from sqlalchemy.sql.compiler import SQLCompiler @@ -28,7 +32,7 @@ class TrinoIdentifierPreparer(PrestoIdentifierPreparer): _type_map = { 'boolean': types.Boolean, - 'tinyint': mysql.MSTinyInteger, + 'tinyint': MSTinyInteger, 'smallint': types.SmallInteger, 'integer': types.Integer, 'bigint': types.BigInteger,