Merge pull request #52259 from Chen768959/fix-50582

fix issue#50582 Not found column NULL in block
This commit is contained in:
Alexey Milovidov 2023-07-22 01:05:59 +03:00 committed by GitHub
commit d0cb6596e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 1 deletions

View File

@ -35,9 +35,20 @@ FinishSortingTransform::FinishSortingTransform(
"Can't finish sorting. SortDescription "
"of already sorted stream is not prefix of SortDescription needed to sort");
/// Remove constants from description_sorted_.
SortDescription description_sorted_without_constants;
description_sorted_without_constants.reserve(description_sorted_.size());
size_t num_columns = const_columns_to_remove.size();
for (const auto & column_description : description_sorted_)
{
auto pos = header.getPositionByName(column_description.column_name);
if (pos < num_columns && !const_columns_to_remove[pos])
description_sorted_without_constants.push_back(column_description);
}
/// The target description is modified in SortingTransform constructor.
/// To avoid doing the same actions with description_sorted just copy it from prefix of target description.
for (const auto & column_sort_desc : description_sorted_)
for (const auto & column_sort_desc : description_sorted_without_constants)
description_with_positions.emplace_back(column_sort_desc, header_without_constants.getPositionByName(column_sort_desc.column_name));
}

View File

@ -0,0 +1,2 @@
\N 1 19000
\N 1 19000

View File

@ -0,0 +1,6 @@
DROP TABLE IF EXISTS t0;
CREATE TABLE t0 (vkey UInt32, c0 Float32, primary key(c0)) engine = AggregatingMergeTree;
insert into t0 values (19000, 1);
select null as c_2_0, ref_2.c0 as c_2_1, ref_2.vkey as c_2_2 from t0 as ref_2 order by c_2_0 asc, c_2_1 asc, c_2_2 asc;
select null as c_2_0, ref_2.c0 as c_2_1, ref_2.vkey as c_2_2 from t0 as ref_2 order by c_2_0 asc, c_2_1 asc;
DROP TABLE t0;