Skip to content

Commit 8abfc0a

Browse files
committed
feat: TrinoTypeCompiper datatypes
1 parent cb24c8c commit 8abfc0a

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

trino/sqlalchemy/compiler.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,44 @@ class TrinoDDLCompiler(compiler.DDLCompiler):
9696

9797

9898
class TrinoTypeCompiler(compiler.GenericTypeCompiler):
99-
pass
99+
def visit_FLOAT(self, type_, **kw):
100+
precision = type_.precision or 32
101+
if 0 <= precision <= 32:
102+
return self.visit_REAL(type_, **kw)
103+
elif 32 < precision <= 64:
104+
return self.visit_DOUBLE(type_, **kw)
105+
else:
106+
raise ValueError(f"type.precision={type_.precision} is invalid")
107+
108+
def visit_DOUBLE(self, type_, **kw):
109+
return "DOUBLE"
110+
111+
def visit_NUMERIC(self, type_, **kw):
112+
return self.visit_DECIMAL(type_, **kw)
113+
114+
def visit_NCHAR(self, type_, **kw):
115+
return self.visit_CHAR(type_, **kw)
116+
117+
def visit_NVARCHAR(self, type_, **kw):
118+
return self.visit_VARCHAR(type_, **kw)
119+
120+
def visit_TEXT(self, type_, **kw):
121+
return self.visit_VARCHAR(type_, **kw)
122+
123+
def visit_BINARY(self, type_, **kw):
124+
return self.visit_VARBINARY(type_, **kw)
125+
126+
def visit_CLOB(self, type_, **kw):
127+
return self.visit_VARCHAR(type_, **kw)
128+
129+
def visit_NCLOB(self, type_, **kw):
130+
return self.visit_VARCHAR(type_, **kw)
131+
132+
def visit_BLOB(self, type_, **kw):
133+
return self.visit_VARBINARY(type_, **kw)
134+
135+
def visit_DATETIME(self, type_, **kw):
136+
return self.visit_TIMESTAMP(type_, **kw)
100137

101138

102139
class TrinoIdentifierPreparer(compiler.IdentifierPreparer):

0 commit comments

Comments
 (0)