forked from dropbox/PyHive
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsqlalchemy_trino.py
More file actions
77 lines (59 loc) · 2.01 KB
/
sqlalchemy_trino.py
File metadata and controls
77 lines (59 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""Integration between SQLAlchemy and Trino.
Some code based on
https://github.com/zzzeek/sqlalchemy/blob/rel_0_5/lib/sqlalchemy/databases/sqlite.py
which is released under the MIT license.
"""
from __future__ import absolute_import
from __future__ import unicode_literals
import re
from sqlalchemy import exc
from sqlalchemy import types
from sqlalchemy import util
# TODO shouldn't use mysql type
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
from pyhive import trino
from pyhive.common import UniversalSet
from pyhive.sqlalchemy_presto import PrestoDialect, PrestoCompiler, PrestoIdentifierPreparer
class TrinoIdentifierPreparer(PrestoIdentifierPreparer):
pass
_type_map = {
'boolean': types.Boolean,
'tinyint': MSTinyInteger,
'smallint': types.SmallInteger,
'integer': types.Integer,
'bigint': types.BigInteger,
'real': types.Float,
'double': types.Float,
'varchar': types.String,
'timestamp': types.TIMESTAMP,
'date': types.DATE,
'varbinary': types.VARBINARY,
}
class TrinoCompiler(PrestoCompiler):
pass
class TrinoTypeCompiler(PrestoCompiler):
def visit_CLOB(self, type_, **kw):
raise ValueError("Trino does not support the CLOB column type.")
def visit_NCLOB(self, type_, **kw):
raise ValueError("Trino does not support the NCLOB column type.")
def visit_DATETIME(self, type_, **kw):
raise ValueError("Trino does not support the DATETIME column type.")
def visit_FLOAT(self, type_, **kw):
return 'DOUBLE'
def visit_TEXT(self, type_, **kw):
if type_.length:
return 'VARCHAR({:d})'.format(type_.length)
else:
return 'VARCHAR'
class TrinoDialect(PrestoDialect):
name = 'trino'
@classmethod
def dbapi(cls):
return trino