Skip to content

Commit a76acfc

Browse files
authored
feat(sql): load parsed but unsupported types as unknown (#9868)
1 parent 9af3efe commit a76acfc

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

ibis/backends/sql/datatypes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,10 @@ def to_ibis(cls, typ: sge.DataType, nullable: bool | None = None) -> dt.DataType
169169

170170
if method := getattr(cls, f"_from_sqlglot_{typecode.name}", None):
171171
dtype = method(*typ.expressions)
172+
elif (known_typ := _from_sqlglot_types.get(typecode)) is not None:
173+
dtype = known_typ(nullable=cls.default_nullable)
172174
else:
173-
dtype = _from_sqlglot_types[typecode](nullable=cls.default_nullable)
175+
dtype = dt.unknown
174176

175177
if nullable is not None:
176178
return dtype.copy(nullable=nullable)

ibis/backends/sql/tests/test_datatypes.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
import ibis.common.exceptions as com
99
import ibis.expr.datatypes as dt
1010
import ibis.tests.strategies as its
11-
from ibis.backends.sql.datatypes import DuckDBType, PostgresType, SqlglotType
11+
from ibis.backends.sql.datatypes import (
12+
ClickHouseType,
13+
DuckDBType,
14+
PostgresType,
15+
SqlglotType,
16+
)
1217

1318

1419
def assert_dtype_roundtrip(ibis_type, sqlglot_expected=None):
@@ -63,3 +68,20 @@ def test_interval_without_unit():
6368
SqlglotType.from_string("INTERVAL")
6469
assert PostgresType.from_string("INTERVAL") == dt.Interval("s")
6570
assert DuckDBType.from_string("INTERVAL") == dt.Interval("us")
71+
72+
73+
@pytest.mark.parametrize(
74+
"typ",
75+
[
76+
sge.DataType.Type.UINT256,
77+
sge.DataType.Type.UINT128,
78+
sge.DataType.Type.BIGSERIAL,
79+
sge.DataType.Type.HLLSKETCH,
80+
],
81+
)
82+
@pytest.mark.parametrize(
83+
"typengine",
84+
[ClickHouseType, PostgresType, DuckDBType],
85+
)
86+
def test_unsupported_dtypes_are_unknown(typengine, typ):
87+
assert typengine.to_ibis(sge.DataType(this=typ)) == dt.unknown

0 commit comments

Comments
 (0)