From 9c365dbff93eb5f503c9602f7ad73e43ff2fbefd Mon Sep 17 00:00:00 2001 From: SoloTel Date: Mon, 6 Mar 2023 12:10:54 +0000 Subject: [PATCH] Update sqlalchemy_hive.py Support for sqlalchemy version 2.x --- pyhive/sqlalchemy_hive.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/pyhive/sqlalchemy_hive.py b/pyhive/sqlalchemy_hive.py index 2ef49652..083c9a32 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 import mysql +except ImportError: + # Newer versions require import from dialects not databases + from sqlalchemy.dialects import mysql from sqlalchemy.engine import default from sqlalchemy.sql import compiler from sqlalchemy.sql.compiler import SQLCompiler @@ -121,7 +129,6 @@ def __init__(self, dialect): _type_map = { 'boolean': types.Boolean, - 'tinyint': mysql.MSTinyInteger, 'smallint': types.SmallInteger, 'int': types.Integer, 'bigint': types.BigInteger, @@ -140,6 +147,16 @@ def __init__(self, dialect): 'decimal': HiveDecimal, } +try: + _type_map.update({ + 'tinyint': mysql.MSTinyInteger + }) +except AttributeError: + # Support for version 2.x of sqlalchemy + _type_map.update({ + 'tinyint': mysql.base.MSTinyInteger + }) + class HiveCompiler(SQLCompiler): def visit_concat_op_binary(self, binary, operator, **kw):