Skip to content

Commit

Permalink
fix(clickhouse): make arrays non nullable (#8501)
Browse files Browse the repository at this point in the history
  • Loading branch information
mneedham authored Feb 29, 2024
1 parent ce1584f commit 1caf6de
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
19 changes: 18 additions & 1 deletion ibis/backends/clickhouse/tests/test_datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import hypothesis as h
import hypothesis.strategies as st
import pytest
import sqlglot.expressions as sge
from pytest import param

import ibis
Expand Down Expand Up @@ -278,7 +279,7 @@ def test_parse_type(ch_type, ibis_type):
| its.date_dtype()
| its.time_dtype()
| its.timestamp_dtype(scale=st.integers(0, 9))
| its.array_dtypes(roundtrippable_types)
| its.array_dtypes(roundtrippable_types, nullable=false)
| its.map_dtypes(map_key_types, roundtrippable_types, nullable=false)
)
)
Expand All @@ -289,3 +290,19 @@ def test_type_roundtrip(ibis_type):
type_string = ClickHouseType.to_string(ibis_type)
parsed_ibis_type = ClickHouseType.from_string(type_string)
assert parsed_ibis_type == ibis_type


def test_arrays_nullable():
# if dtype.nullable and not (dtype.is_map() or dtype.is_array()):
sge_type = ClickHouseType.from_ibis(dt.Array("float"))
typecode = sge.DataType.Type

assert sge_type == sge.DataType(
this=typecode.ARRAY,
expressions=[
sge.DataType(
this=typecode.NULLABLE, expressions=[sge.DataType(this=typecode.DOUBLE)]
)
],
nested=True,
)
2 changes: 1 addition & 1 deletion ibis/backends/sql/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,7 +966,7 @@ class ClickHouseType(SqlglotType):
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():
if dtype.nullable and not (dtype.is_map() or dtype.is_array()):
# map cannot be nullable in clickhouse
return sge.DataType(this=typecode.NULLABLE, expressions=[typ])
else:
Expand Down
8 changes: 4 additions & 4 deletions ibis/backends/tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,8 +938,8 @@ def flatten_data():
marks=[
pytest.mark.notyet(
["clickhouse"],
reason="doesn't support nullable array elements",
raises=ClickHouseDatabaseError,
reason="Arrays are never nullable",
raises=AssertionError,
)
],
),
Expand All @@ -950,8 +950,8 @@ def flatten_data():
marks=[
pytest.mark.notyet(
["clickhouse"],
reason="doesn't support nullable array elements",
raises=ClickHouseDatabaseError,
reason="Arrays are never nullable",
raises=AssertionError,
)
],
),
Expand Down

0 comments on commit 1caf6de

Please sign in to comment.