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

-OrNull combinator return unexpected values #38128

Closed
UnamedRus opened this issue Jun 16, 2022 · 1 comment · Fixed by #48817
Closed

-OrNull combinator return unexpected values #38128

UnamedRus opened this issue Jun 16, 2022 · 1 comment · Fixed by #48817

Comments

@UnamedRus
Copy link
Contributor

Describe the unexpected behaviour
A clear and concise description of what works not as it is supposed to.

How to reproduce
ClickHouse 22.3, 22.6

SELECT argMaxOrNull(id, timestamp)
FROM
(
    SELECT
        CAST(NULL, 'Nullable(UInt32)') AS id,
        2 AS timestamp
)

Query id: 17bf3c85-de37-428f-990e-e82c78cc06fa

┌─argMaxOrNull(id, timestamp)─┐
│                           0 │  <-- expected to have NULL here
└─────────────────────────────┘

SELECT
    argMax(id, timestamp),
    argMaxOrNull(id, timestamp)
FROM
(
    SELECT
        CAST(NULL, 'Nullable(UInt32)') AS id,
        2 AS timestamp
    UNION ALL
    SELECT
        1 AS id,
        1 AS timestamp
)

Query id: 01180512-509b-481e-9833-1256cc4d01c1

┌─argMax(id, timestamp)─┬─argMaxOrNull(id, timestamp)─┐
│                     1 │                           0 │  <- expected to have 1 here as latest non-null value
└───────────────────────┴─────────────────────────────┘

Workaround for second issue:

SELECT argMaxIfOrNull(id, timestamp, id IS NOT NULL)
FROM
(
    SELECT
        CAST(NULL, 'Nullable(UInt32)') AS id,
        2 AS timestamp
    UNION ALL
    SELECT
        1 AS id,
        1 AS timestamp
)

Query id: a3f72ba8-b17c-40b3-955e-22d311c0e428

┌─argMaxOrNullIf(id, timestamp, isNotNull(id))─┐
│                                            1 │
└──────────────────────────────────────────────┘

Expected behavior
For first query, it should return NULL
For second either return 1, either confirm that argMaxOrNull working as intended.

@alexey-milovidov
Copy link
Member

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants