From a76acfc053f0b798cd6c1b7225fb86191369199c Mon Sep 17 00:00:00 2001 From: Gil Forsyth Date: Mon, 19 Aug 2024 12:01:41 -0400 Subject: [PATCH] feat(sql): load parsed but unsupported types as unknown (#9868) --- ibis/backends/sql/datatypes.py | 4 +++- ibis/backends/sql/tests/test_datatypes.py | 24 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ibis/backends/sql/datatypes.py b/ibis/backends/sql/datatypes.py index 02e852fc074a..a55556b7b812 100644 --- a/ibis/backends/sql/datatypes.py +++ b/ibis/backends/sql/datatypes.py @@ -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) diff --git a/ibis/backends/sql/tests/test_datatypes.py b/ibis/backends/sql/tests/test_datatypes.py index b772cdddd4fd..217830b21416 100644 --- a/ibis/backends/sql/tests/test_datatypes.py +++ b/ibis/backends/sql/tests/test_datatypes.py @@ -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): @@ -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