Skip to content

Commit

Permalink
fix(clickhouse): handle nullable nested types
Browse files Browse the repository at this point in the history
I remove the docstring because it is obvious from the type signature,
and the docstring was wrong. The superclass has the correct docstring though,
just inherit that.
  • Loading branch information
NickCrews committed Jun 4, 2024
1 parent 91b0500 commit f930668
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 25 deletions.
7 changes: 4 additions & 3 deletions ibis/backends/sql/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,10 +1016,11 @@ class ClickHouseType(SqlglotType):

@classmethod
def from_ibis(cls, dtype: dt.DataType) -> sge.DataType:
"""Convert a sqlglot type to an ibis type."""
typ = super().from_ibis(dtype)
if dtype.nullable and not (dtype.is_map() or dtype.is_array()):
# map cannot be nullable in clickhouse
# nested types cannot be nullable in clickhouse
if dtype.nullable and not (
dtype.is_map() or dtype.is_array() or dtype.is_struct()
):
return sge.DataType(this=typecode.NULLABLE, expressions=[typ])
else:
return typ
Expand Down
5 changes: 0 additions & 5 deletions ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,11 +923,6 @@ def test_zip_null(con, fn):


@builtin_array
@pytest.mark.notyet(
["clickhouse"],
raises=ClickHouseDatabaseError,
reason="https://github.com/ClickHouse/ClickHouse/issues/41112",
)
@pytest.mark.notimpl(["postgres"], raises=PsycoPg2SyntaxError)
@pytest.mark.notimpl(["risingwave"], raises=PsycoPg2ProgrammingError)
@pytest.mark.notimpl(["datafusion"], raises=com.OperationNotDefinedError)
Expand Down
21 changes: 4 additions & 17 deletions ibis/backends/tests/test_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import ibis.expr.datatypes as dt
from ibis import util
from ibis.backends.tests.errors import (
ClickHouseDatabaseError,
PolarsColumnNotFoundError,
PsycoPg2InternalError,
PsycoPg2SyntaxError,
Expand Down Expand Up @@ -158,28 +157,16 @@ def test_field_access_after_case(con):
["postgres"], reason="struct literals not implemented", raises=PsycoPg2SyntaxError
)
@pytest.mark.notimpl(["flink"], raises=IbisError, reason="not implemented in ibis")
@pytest.mark.notyet(
["clickhouse"], raises=sg.ParseError, reason="sqlglot fails to parse"
)
@pytest.mark.parametrize(
"nullable",
[
param(
True,
marks=[
pytest.mark.notyet(
["clickhouse"],
raises=ClickHouseDatabaseError,
reason="ClickHouse doesn't support nested nullable types",
)
],
id="nullable",
),
param(True, id="nullable"),
param(
False,
marks=[
pytest.mark.notyet(
["clickhouse"],
raises=sg.ParseError,
reason="sqlglot fails to parse",
),
pytest.mark.notyet(
["polars"],
raises=AssertionError,
Expand Down

0 comments on commit f930668

Please sign in to comment.