Skip to content

Commit 6452a5e

Browse files
committed
fix(datatypes): ensure that newer sqlglot BLOB type is not accessed if it does not exist
1 parent a945c96 commit 6452a5e

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

ibis/backends/sql/datatypes.py

+12-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,19 @@
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+
if (_sg_type := getattr(typecode, _attr, None)) is not None:
83+
_from_sqlglot_types[_sg_type] = _ibis_type
84+
85+
del _attr, _ibis_type, _sg_type
7986

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

8688
_to_sqlglot_types = {
8789
dt.Null: typecode.NULL,

0 commit comments

Comments
 (0)