Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(dtypes): fall back to dt.unknown for unknown types #9576

Merged
merged 1 commit into from
Jul 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading