Skip to content

Commit

Permalink
feat(sql): load parsed but unsupported types as unknown (#9868)
Browse files Browse the repository at this point in the history
  • Loading branch information
gforsyth authored Aug 19, 2024
1 parent 9af3efe commit a76acfc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
4 changes: 3 additions & 1 deletion ibis/backends/sql/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ def to_ibis(cls, typ: sge.DataType, nullable: bool | None = None) -> dt.DataType

if method := getattr(cls, f"_from_sqlglot_{typecode.name}", None):
dtype = method(*typ.expressions)
elif (known_typ := _from_sqlglot_types.get(typecode)) is not None:
dtype = known_typ(nullable=cls.default_nullable)
else:
dtype = _from_sqlglot_types[typecode](nullable=cls.default_nullable)
dtype = dt.unknown

if nullable is not None:
return dtype.copy(nullable=nullable)
Expand Down
24 changes: 23 additions & 1 deletion ibis/backends/sql/tests/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
import ibis.common.exceptions as com
import ibis.expr.datatypes as dt
import ibis.tests.strategies as its
from ibis.backends.sql.datatypes import DuckDBType, PostgresType, SqlglotType
from ibis.backends.sql.datatypes import (
ClickHouseType,
DuckDBType,
PostgresType,
SqlglotType,
)


def assert_dtype_roundtrip(ibis_type, sqlglot_expected=None):
Expand Down Expand Up @@ -63,3 +68,20 @@ def test_interval_without_unit():
SqlglotType.from_string("INTERVAL")
assert PostgresType.from_string("INTERVAL") == dt.Interval("s")
assert DuckDBType.from_string("INTERVAL") == dt.Interval("us")


@pytest.mark.parametrize(
"typ",
[
sge.DataType.Type.UINT256,
sge.DataType.Type.UINT128,
sge.DataType.Type.BIGSERIAL,
sge.DataType.Type.HLLSKETCH,
],
)
@pytest.mark.parametrize(
"typengine",
[ClickHouseType, PostgresType, DuckDBType],
)
def test_unsupported_dtypes_are_unknown(typengine, typ):
assert typengine.to_ibis(sge.DataType(this=typ)) == dt.unknown

0 comments on commit a76acfc

Please sign in to comment.