Skip to content

bug: ApproxMedian with where clause applies where clause to the quantile argument #11951

@ssabdb

Description

@ssabdb

What happened?

t.float_col.approx_median(where=t.string_col > "a")

produces the SQL

SELECT
  APPROX_QUANTILES(
    IF(`t0`.`string_col` > 'a', `t0`.`float_col`, NULL),
    IF(`t0`.`string_col` > 'a', 2, NULL) <--- INCORRECT SQL HERE
  )[offset(1)] AS `ApproxMedian_float_col_Greater_string_col_'a'`
FROM `functional_alltypes` AS `t0`

which is incorrect, as the quantile spec must be a constant, e.g.

SELECT
  APPROX_QUANTILES(IF(`t0`.`string_col` > 'a', `t0`.`float_col`, NULL), 
  2 IGNORE NULLS)[1] <--- CORRECT SQL HERE
  AS `ApproxQuantile_float_col_0_5_Greater_string_col_'a'`
FROM `functional_alltypes` AS `t0`

What version of ibis are you using?

11.0.0

What backend(s) are you using, if any?

Bigquery

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior inside of ibis

    Type

    No type

    Projects

    Status

    backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions