Fix constants in the result of MergingSortedAlgorithm.

This commit is contained in:
Nikolai Kochetov 2023-02-16 17:58:35 +00:00
parent ecc6ff707b
commit 9cca571777
3 changed files with 42 additions and 1 deletions

View File

@ -60,7 +60,19 @@ public:
throw Exception(ErrorCodes::LOGICAL_ERROR, "Cannot insert to MergedData from Chunk because MergedData is not empty.");
UInt64 num_rows = chunk.getNumRows();
columns = chunk.mutateColumns();
UInt64 num_columns = chunk.getNumColumns();
auto chunk_columns = chunk.mutateColumns();
/// Here is a special code for constant columns.
/// Currently, 'columns' will contain constants, but 'chunk_columns' will not.
/// We want to keep constants in the result, so just re-create them carefully.
for (size_t i = 0; i < num_columns; ++i)
{
if (isColumnConst(*columns[i]))
columns[i] = columns[i]->cloneResized(num_rows);
else
columns[i] = std::move(chunk_columns[i]);
}
if (rows_size < num_rows)
{

View File

@ -0,0 +1,4 @@
constant_1 250000
constant_1 2000000
constant_1 test_value_1
constant_1 test_value_2

View File

@ -0,0 +1,25 @@
drop table if exists test_table;
CREATE TABLE test_table (string_value String) ENGINE = MergeTree ORDER BY string_value;
insert into test_table select * from (
select 'test_value_1'
from numbers_mt(250000)
union all
select 'test_value_2'
from numbers_mt(2000000)
)
order by rand();
select distinct
'constant_1' as constant_value,
count(*) over(partition by constant_value, string_value) as value_cnt
from (
select string_value
from test_table
);
select distinct
'constant_1' as constant_value, *
from (select string_value from test_table)
ORDER BY constant_value, string_value settings max_threads=1;
drop table test_table;