Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function 'has' works incorrectly with 'Nullable' columns #60214

Closed
DimasKovas opened this issue Feb 21, 2024 · 2 comments · Fixed by #61249
Closed

Function 'has' works incorrectly with 'Nullable' columns #60214

DimasKovas opened this issue Feb 21, 2024 · 2 comments · Fixed by #61249
Labels
bug Confirmed user-visible misbehaviour in official release

Comments

@DimasKovas
Copy link
Contributor

Describe what's wrong

Function has works incorrectly when the second argument is a nullable column.

It may return 1 for expression has([0, 1], a), when a is Null.

It looks like that for nullable columns the function uses an underlying column (assumeNotNullable), and the null bitmap is ignored.

(the result for second query is wrong)
https://fiddle.clickhouse.com/d508fc65-6e05-495f-a923-a142f6b906b7

Does it reproduce on the most recent release?

Yes

How to reproduce

  • Which ClickHouse server version to use
    23.8/24.1/latest

  • CREATE TABLE statements for all tables involved

CREATE TABLE test (a Nullable(Int64)) ENGINE=Memory;
INSERT INTO test VALUES (1), (Null);
  • Queries to run that lead to an unexpected result
SELECT a, has([0, 1], a) as b FROM test;

-----
1	1
\N	1
-----

Expected behavior
has should return 0 if the value is Null and Null is missing in the array

-----
1	1
\N	0
-----

A clear and concise description of what you expected to happen.

@DimasKovas DimasKovas added the potential bug To be reviewed by developers and confirmed/rejected. label Feb 21, 2024
@Algunenano Algunenano added bug Confirmed user-visible misbehaviour in official release and removed potential bug To be reviewed by developers and confirmed/rejected. labels Feb 21, 2024
@alexey-milovidov
Copy link
Member

@myrrc, you can take a look - it might be related to #12550

@myrrc
Copy link
Contributor

myrrc commented Feb 21, 2024 via email

mkmkme added a commit to mkmkme/ClickHouse that referenced this issue Mar 12, 2024
Previous implementation didn't check for `null_map` when the given
argument was not `Null`. This commit adds the missing check.

Fixes ClickHouse#60214
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Confirmed user-visible misbehaviour in official release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants