Repository navigation
Closed
Labels
bugConfirmed user-visible misbehaviour in official releasecomp-sql-syntaxSQL/grammar parsing, AST nodes, syntax-level features.minorPriority: minorst-acceptedThe issue is in our backlog, ready to take
Description
Describe the bug
Following code snippet calculates percents wrong when all the statements are on one SELECT block and calculates percents wright when arrayMap function is on the other SELECT clause
How to reproduce
select t.1 as cnt,
t.2 as name,
t.3 as percent
from (
select arrayJoin(result) as t
from (
select [
(79, 'name1'),
(62, 'name2'),
(44, 'name3')
] as data,
arraySum(arrayMap(t -> t.1, data)) as total,
arrayMap(t ->
tuple(t.1, t.2,
multiIf(total = 0, 0, t.1 > 0 and t.1 < 10, -1.0,
(toFloat32(t.1) / toFloat32(total)) * 100)
),
data
) as result
)
);
- Which ClickHouse server version to use
20.9.2.20 - Which interface to use, if matters
Request from intellij idea via jdbc
Expected behavior
Expected result is:
cnt,name,percent
79,name1,42.7027027027027
62,name2,33.513513513513516
44,name3,23.783783783783786
Actual result
cnt,name,percent
79,name1,33.33333333333333
62,name2,33.33333333333333
44,name3,33.33333333333333
Additional context
I found out that this piece of code can work properly with following changes
select t.1 as cnt,
t.2 as name,
t.3 as percent
from (
select arrayJoin(result) t
from (
select arrayMap(t ->
tuple(t.1, t.2,
multiIf(total = 0, 0, t.1 > 0 and t.1 < 10, - 1.0,
(toFloat32(t.1) / toFloat32(total)) * 100)
),
data
) as result
from (
select [
(79, 79),
(62, 24),
(44, 44)
] as data,
arraySum(arrayMap(t -> t.1, data)) as total
)
)
);
Metadata
Metadata
Assignees
Labels
bugConfirmed user-visible misbehaviour in official releasecomp-sql-syntaxSQL/grammar parsing, AST nodes, syntax-level features.minorPriority: minorst-acceptedThe issue is in our backlog, ready to take
Activity
den-crane commentedon Sep 28, 2020
it seems this bug existed for very long time.
WA: different lambda var. name.
t ->replaced withx ->alexey-milovidov commentedon Jan 25, 2021
Minimal example:
alexey-milovidov commentedon Mar 20, 2023
It is fixed by enabling the analyzer.