Skip to content

Commit 0674fff

Browse files
committed
fix(datatypes): ensure that newer sqlglot BLOB type is not accessed if it does not exist
1 parent 2ee6a91 commit 0674fff

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

ibis/backends/sql/datatypes.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import annotations
22

3-
import contextlib
43
from functools import partial
54
from typing import NoReturn
65

@@ -19,7 +18,6 @@
1918
typecode.BIGDECIMAL: partial(dt.Decimal, 76, 38),
2019
typecode.BIGINT: dt.Int64,
2120
typecode.BINARY: dt.Binary,
22-
typecode.BLOB: dt.Binary,
2321
typecode.BOOLEAN: dt.Boolean,
2422
typecode.CHAR: dt.String,
2523
typecode.DATE: dt.Date,
@@ -73,15 +71,23 @@
7371
}
7472

7573

76-
# typecode.UNIQUEIDENTIFIER was supplanted by typecode.UUID around sqlglot 26.6
77-
with contextlib.suppress(AttributeError):
78-
_from_sqlglot_types[typecode.UNIQUEIDENTIFIER] = dt.UUID
74+
# these types are not present in all versions of sqlglot that we support, so we
75+
# need to check if they exist before using them
76+
for _attr, _ibis_type in (
77+
("UNIQUEIDENTIFIER", dt.UUID),
78+
("BLOB", dt.Binary),
79+
("DATETIME2", dt.Timestamp),
80+
("SMALLDATETIME", dt.Timestamp),
81+
):
82+
try:
83+
_sg_type = getattr(typecode, _attr)
84+
except AttributeError:
85+
pass
86+
else:
87+
_from_sqlglot_types[_sg_type] = _ibis_type
88+
89+
del _attr, _ibis_type, _sg_type
7990

80-
if sg.__version_tuple__[0] >= 26:
81-
_from_sqlglot_types |= {
82-
typecode.DATETIME2: dt.Timestamp,
83-
typecode.SMALLDATETIME: dt.Timestamp,
84-
}
8591

8692
_to_sqlglot_types = {
8793
dt.Null: typecode.NULL,

0 commit comments

Comments
 (0)