Skip to content

Commit

Permalink
feat(dtypes): fall back to dt.unknown for unknown types (#9576)
Browse files Browse the repository at this point in the history
  • Loading branch information
gforsyth authored Jul 14, 2024
1 parent 9047b26 commit 56a10d2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 9 additions & 2 deletions ibis/backends/sql/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 5 additions & 4 deletions ibis/backends/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"],
Expand Down

0 comments on commit 56a10d2

Please sign in to comment.