ClickHouse / metabase-clickhouse-driver

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

`Sum If` cannot be applied to `Int` Columns #156

Closed pulsar256 closed 1 year ago

pulsar256 commented 1 year ago

Describe the bug

applying Sum If expression in Metabase to Int columns will generate invalid SQL

Steps to reproduce

Given Schema

create table public.sum_if_test
(
    id            Int64,
    int_value     Int64,
    discriminator String
) ENGINE = MergeTree()
      primary key (id, discriminator);

Given Test Data

insert into public.sum_if_test values (1, 1, 'foo');
insert into public.sum_if_test values (2, 1, 'foo');
insert into public.sum_if_test values (3, 3, 'bar');
insert into public.sum_if_test values (4, 5, 'bar');

Given Metbase Report Configuration

custom expression configured in Metabase when summarizing this table:

image

Will generate SQL:

SELECT sum(CASE WHEN `public`.`sum_if_test`.`discriminator` = 'bar' THEN `public`.`sum_if_test`.`int_value` ELSE 0.0 END) AS `sum_if_with_int`
FROM `public`.`sum_if_test`

using a float 0.0 default value instead of 0 in ELSE 0.0

Expected behaviour

Sum If expression can be applied to Int typed columns

Error log

ode: 386. DB::Exception: There is no supertype for types Float64, Int64 because some of them are integers and some are floating point, but there is no floating point type, that can exactly represent all required integers: While processing if(discriminator = 'bar', int_value, 0.). (NO_COMMON_TYPE) (version 22.8.15.1) , server ClickHouseNode [uri=https://(...)/public, options={use_server_time_zone_for_dates=true,use_no_proxy=false,product_name=metabase/1.1.2}]@92216918

Configuration

Environment

ClickHouse server

slvrtrn commented 1 year ago

Thanks for the report. I will look into it.

slvrtrn commented 1 year ago

@pulsar256, could you try 1.1.4? It should work there now.

pulsar256 commented 1 year ago

@slvrtrn thank you for the fix! I have just deployed the new version and it seems to be working now.

slvrtrn commented 1 year ago

Glad that it worked!