Skip to content

Commit b0206d3

Browse files
changing drivers to support hive, presto and trino with sqlalchemy>=2.0 (#448)
1 parent 1c1da8b commit b0206d3

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

pyhive/sqlalchemy_hive.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,19 @@
1313

1414
import re
1515
from sqlalchemy import exc
16-
from sqlalchemy import processors
16+
try:
17+
from sqlalchemy import processors
18+
except ImportError:
19+
# Newer versions of sqlalchemy require:
20+
from sqlalchemy.engine import processors
1721
from sqlalchemy import types
1822
from sqlalchemy import util
1923
# TODO shouldn't use mysql type
20-
from sqlalchemy.databases import mysql
24+
try:
25+
from sqlalchemy.databases.mysql import MSTinyInteger
26+
except ImportError:
27+
# Newer versions of sqlalchemy require:
28+
from sqlalchemy.dialects.mysql import MSTinyInteger
2129
from sqlalchemy.engine import default
2230
from sqlalchemy.sql import compiler
2331
from sqlalchemy.sql.compiler import SQLCompiler
@@ -121,7 +129,7 @@ def __init__(self, dialect):
121129

122130
_type_map = {
123131
'boolean': types.Boolean,
124-
'tinyint': mysql.MSTinyInteger,
132+
'tinyint': MSTinyInteger,
125133
'smallint': types.SmallInteger,
126134
'int': types.Integer,
127135
'bigint': types.BigInteger,

pyhive/sqlalchemy_presto.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
from sqlalchemy import types
1414
from sqlalchemy import util
1515
# TODO shouldn't use mysql type
16-
from sqlalchemy.databases import mysql
16+
try:
17+
from sqlalchemy.databases.mysql import MSTinyInteger
18+
except ImportError:
19+
# Newer versions of sqlalchemy require:
20+
from sqlalchemy.dialects.mysql import MSTinyInteger
1721
from sqlalchemy.engine import default
1822
from sqlalchemy.sql import compiler
1923
from sqlalchemy.sql.compiler import SQLCompiler
@@ -29,7 +33,7 @@ class PrestoIdentifierPreparer(compiler.IdentifierPreparer):
2933

3034
_type_map = {
3135
'boolean': types.Boolean,
32-
'tinyint': mysql.MSTinyInteger,
36+
'tinyint': MSTinyInteger,
3337
'smallint': types.SmallInteger,
3438
'integer': types.Integer,
3539
'bigint': types.BigInteger,

pyhive/sqlalchemy_trino.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
from sqlalchemy import types
1414
from sqlalchemy import util
1515
# TODO shouldn't use mysql type
16-
from sqlalchemy.databases import mysql
16+
try:
17+
from sqlalchemy.databases.mysql import MSTinyInteger
18+
except ImportError:
19+
# Newer versions of sqlalchemy require:
20+
from sqlalchemy.dialects.mysql import MSTinyInteger
1721
from sqlalchemy.engine import default
1822
from sqlalchemy.sql import compiler
1923
from sqlalchemy.sql.compiler import SQLCompiler
@@ -28,7 +32,7 @@ class TrinoIdentifierPreparer(PrestoIdentifierPreparer):
2832

2933
_type_map = {
3034
'boolean': types.Boolean,
31-
'tinyint': mysql.MSTinyInteger,
35+
'tinyint': MSTinyInteger,
3236
'smallint': types.SmallInteger,
3337
'integer': types.Integer,
3438
'bigint': types.BigInteger,

0 commit comments

Comments
 (0)