ClickHouse / metabase-clickhouse-driver

ClickHouse database driver for the Metabase business intelligence front-end
Apache License 2.0
476 stars 92 forks source link

Field filter functionality is broken for Date columns with Null values #243

Closed Tony-metabase closed 3 months ago

Tony-metabase commented 3 months ago

Describe the bug

If you have a date column with null filters you are not able to use field filters. This is happening with the latest driver 1.5.0

Steps to reproduce

Just create a table with one column of type date or datetime and add data including some null values.

image

Then just try to apply a field filter and it breaks

image

Expected behaviour

I want to be able to use field filters on date columns that havenull values

Error log

Code: 349. DB::Exception: Cannot convert NULL value to non-Nullable type: while executing 'FUNCTION CAST(updated_at : 0, 'date' :: 1) -> CAST(updated_at, 'date') Date : 4': While executing MergeTreeSelect(pool: PrefetchedReadPool, algorithm: Thread). (CANNOT_INSERT_NULL_IN_ORDINARY_COLUMN) (version 24.2.2.16288 (official build)) , server ClickHouseNode [uri=https://jkwor7vhzu.eu-central-1.aws.clickhouse.cloud:8443/default, options={databaseTerm=schema,use_server_time_zone_for_dates=true,use_no_proxy=false,remember_last_set_roles=true,http_connection_provider=HTTP_URL_CONNECTION,product_name=metabase/1.5.0,select_sequential_consistency=true,sslmode=STRICT}]@-580620226

ClickHouse server

CREATE TABLE default.test_dates
(
    id              UInt64,
    updated_at      Nullable(DateTime),
    updated_at_date Nullable(Date)
)
    ENGINE = MergeTree
        ORDER BY id;

INSERT INTO test_dates (id) Values (1);