Skip to content

Commit

Permalink
Merge pull request #59642 from ClickHouse/cherrypick/23.11/79d91294c6…
Browse files Browse the repository at this point in the history
…27ce823ecdd3c2280627bfd2d4e54a

Cherry pick #59594 to 23.11: Fix incorrect result of arrayElement / map[] on empty value
  • Loading branch information
robot-clickhouse-ci-2 committed Feb 6, 2024
2 parents a3dafce + 79d9129 commit f86894d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/Functions/array/arrayElement.cpp
Expand Up @@ -277,8 +277,7 @@ struct ArrayElementStringImpl
ColumnArray::Offset current_offset = 0;
/// get the total result bytes at first, and reduce the cost of result_data.resize.
size_t total_result_bytes = 0;
ColumnString::Chars zero_buf(1);
zero_buf.push_back(0);
ColumnString::Chars zero_buf(16, '\0'); /// Needs 15 extra bytes for memcpySmallAllowReadWriteOverflow15
std::vector<std::pair<const ColumnString::Char *, UInt64>> selected_bufs;
selected_bufs.reserve(size);
for (size_t i = 0; i < size; ++i)
Expand Down Expand Up @@ -344,8 +343,7 @@ struct ArrayElementStringImpl
size_t size = offsets.size();
result_offsets.resize(size);

ColumnString::Chars zero_buf(1);
zero_buf.push_back(0);
ColumnString::Chars zero_buf(16, '\0'); /// Needs 15 extra bytes for memcpySmallAllowReadWriteOverflow15
ColumnArray::Offset current_offset = 0;
/// get the total result bytes at first, and reduce the cost of result_data.resize.
size_t total_result_bytes = 0;
Expand Down
7 changes: 7 additions & 0 deletions tests/queries/0_stateless/02983_empty_map.reference
@@ -0,0 +1,7 @@
-- { echoOn }
SELECT f1, f2['2'], count() FROM t1 GROUP BY 1,2 order by 1,2;
1 1000111
SELECT f1, f3['2'], count() FROM t1 GROUP BY 1,2 order by 1,2;
1 1000111
SELECT f1, f4[2], count() FROM t1 GROUP BY 1,2 order by 1,2;
1 0 1000111
21 changes: 21 additions & 0 deletions tests/queries/0_stateless/02983_empty_map.sql
@@ -0,0 +1,21 @@
--https://github.com/ClickHouse/ClickHouse/issues/59402
CREATE TABLE t1
(
f1 Int32,
f2 Map(LowCardinality(String),LowCardinality(String)),
f3 Map(String,String),
f4 Map(Int32,Int32)
)
ENGINE=Memory AS
SELECT 1 as f1,
map(number%2,number%10) as f2,
f2 as f3,
f2 as f4
from numbers(1000111);

SET max_block_size=10;

-- { echoOn }
SELECT f1, f2['2'], count() FROM t1 GROUP BY 1,2 order by 1,2;
SELECT f1, f3['2'], count() FROM t1 GROUP BY 1,2 order by 1,2;
SELECT f1, f4[2], count() FROM t1 GROUP BY 1,2 order by 1,2;

0 comments on commit f86894d

Please sign in to comment.