From fc1d00fb8f06ffeba7f10a90b6ef4b9f87e9ff57 Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Tue, 4 Jun 2024 03:00:51 -0800 Subject: [PATCH] fix(clickhouse): more explicitly disallow null structs (#9305) --- ibis/backends/sql/datatypes.py | 7 ++++--- ibis/backends/tests/test_array.py | 5 ----- ibis/backends/tests/test_struct.py | 21 ++++----------------- 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/ibis/backends/sql/datatypes.py b/ibis/backends/sql/datatypes.py index 79f0b6728f3e..30932a65ffbb 100644 --- a/ibis/backends/sql/datatypes.py +++ b/ibis/backends/sql/datatypes.py @@ -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 diff --git a/ibis/backends/tests/test_array.py b/ibis/backends/tests/test_array.py index 4fd150297d2a..82beee0ddb68 100644 --- a/ibis/backends/tests/test_array.py +++ b/ibis/backends/tests/test_array.py @@ -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) diff --git a/ibis/backends/tests/test_struct.py b/ibis/backends/tests/test_struct.py index 4e8d94960814..c791318f15d6 100644 --- a/ibis/backends/tests/test_struct.py +++ b/ibis/backends/tests/test_struct.py @@ -14,7 +14,6 @@ import ibis.expr.datatypes as dt from ibis import util from ibis.backends.tests.errors import ( - ClickHouseDatabaseError, PolarsColumnNotFoundError, PsycoPg2InternalError, PsycoPg2SyntaxError, @@ -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,