diff --git a/ibis/backends/sql/datatypes.py b/ibis/backends/sql/datatypes.py index e17f7ef2ad38..62f3a24edb39 100644 --- a/ibis/backends/sql/datatypes.py +++ b/ibis/backends/sql/datatypes.py @@ -42,6 +42,7 @@ typecode.MONEY: dt.Decimal(19, 4), typecode.NCHAR: dt.String, typecode.UUID: dt.UUID, + typecode.NAME: dt.String, typecode.NULL: dt.Null, typecode.NVARCHAR: dt.String, typecode.OBJECT: partial(dt.Map, dt.string, dt.json), @@ -191,8 +192,14 @@ def from_string(cls, text: str, nullable: bool | None = None) -> dt.DataType: if dtype := cls.unknown_type_strings.get(text.lower()): return dtype - sgtype = sg.parse_one(text, into=sge.DataType, read=cls.dialect) - return cls.to_ibis(sgtype, nullable=nullable) + try: + sgtype = sg.parse_one(text, into=sge.DataType, read=cls.dialect) + return cls.to_ibis(sgtype, nullable=nullable) + except sg.errors.ParseError: + # If sqlglot can't parse the type fall back to `dt.unknown` + pass + + return dt.unknown @classmethod def to_string(cls, dtype: dt.DataType) -> str: diff --git a/ibis/backends/tests/test_struct.py b/ibis/backends/tests/test_struct.py index 6a7429a6c2ff..0888d233a287 100644 --- a/ibis/backends/tests/test_struct.py +++ b/ibis/backends/tests/test_struct.py @@ -7,7 +7,6 @@ import pandas as pd import pandas.testing as tm import pytest -import sqlglot as sg from pytest import param import ibis @@ -158,7 +157,9 @@ def test_field_access_after_case(con): ) @pytest.mark.notimpl(["flink"], raises=IbisError, reason="not implemented in ibis") @pytest.mark.notyet( - ["clickhouse"], raises=sg.ParseError, reason="sqlglot fails to parse" + ["clickhouse"], + raises=AssertionError, + reason="sqlglot fails to parse, fall back to unknown", ) @pytest.mark.parametrize( "nullable", @@ -189,8 +190,8 @@ def test_field_access_after_case(con): ) @pytest.mark.broken( ["trino"], - raises=sg.ParseError, - reason="trino returns unquoted and therefore unparsable struct field names", + raises=AssertionError, + reason="trino returns unquoted and therefore unparsable struct field names, we fall back to dt.unknown", ) @pytest.mark.notyet( ["snowflake"],