|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
3 |
| -import contextlib |
4 | 3 | from functools import partial
|
5 | 4 | from typing import NoReturn
|
6 | 5 |
|
|
19 | 18 | typecode.BIGDECIMAL: partial(dt.Decimal, 76, 38),
|
20 | 19 | typecode.BIGINT: dt.Int64,
|
21 | 20 | typecode.BINARY: dt.Binary,
|
22 |
| - typecode.BLOB: dt.Binary, |
23 | 21 | typecode.BOOLEAN: dt.Boolean,
|
24 | 22 | typecode.CHAR: dt.String,
|
25 | 23 | typecode.DATE: dt.Date,
|
|
73 | 71 | }
|
74 | 72 |
|
75 | 73 |
|
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 |
79 | 86 |
|
80 |
| -if sg.__version_tuple__[0] >= 26: |
81 |
| - _from_sqlglot_types |= { |
82 |
| - typecode.DATETIME2: dt.Timestamp, |
83 |
| - typecode.SMALLDATETIME: dt.Timestamp, |
84 |
| - } |
85 | 87 |
|
86 | 88 | _to_sqlglot_types = {
|
87 | 89 | dt.Null: typecode.NULL,
|
|
0 commit comments