mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-24 00:22:29 +00:00
Continue fixing #36199.
This commit is contained in:
parent
425d429044
commit
1feba64a4e
@ -733,6 +733,38 @@ Block NotJoinedBlocks::read()
|
||||
copySameKeys(result_block);
|
||||
correctLowcardAndNullability(result_block);
|
||||
|
||||
/// This is a very dirty hack.
|
||||
/// Sometimes, columns from right joined table may be duplicating, and we can't properly process it.
|
||||
/// So, in case if column is empty in result, try to find non-empty column with the same name.
|
||||
/// Repro:
|
||||
/// select * from (select 2 as x) as t1 right join (select count('x'), count('y'), 0 as x) as t2 on t1.x = t2.x
|
||||
///
|
||||
/// Please, somebody, fix it in a proper way.
|
||||
{
|
||||
std::unordered_map<std::string, std::list<size_t>> result_block_positions;
|
||||
for (size_t i = 0; i < result_block.columns(); ++i)
|
||||
{
|
||||
const auto & col = result_block.getByPosition(i);
|
||||
result_block_positions[col.name].push_back(i);
|
||||
}
|
||||
|
||||
for (auto & col : result_block)
|
||||
{
|
||||
if (col.column->empty())
|
||||
{
|
||||
for (auto pos : result_block_positions[col.name])
|
||||
{
|
||||
const auto & same_col = result_block.getByPosition(pos);
|
||||
if (!same_col.column->empty())
|
||||
{
|
||||
col.column = same_col.column;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
assertBlocksHaveEqualStructure(result_block, result_sample_block, "NotJoinedBlocks");
|
||||
#endif
|
||||
|
@ -1,2 +1,4 @@
|
||||
2 1 2
|
||||
0 1 0
|
||||
2 1 2
|
||||
0 1 0
|
||||
|
@ -5,9 +5,13 @@ FROM ( SELECT 2 AS x ) AS t1
|
||||
RIGHT JOIN ( SELECT count('x'), count('y'), 2 AS x ) AS t2
|
||||
ON t1.x = t2.x;
|
||||
|
||||
select * from (select 2 as x) as t1 right join (select count('x'), count('y'), 0 as x) as t2 on t1.x = t2.x;
|
||||
|
||||
set join_algorithm = 'partial_merge';
|
||||
|
||||
SELECT *
|
||||
FROM ( SELECT 2 AS x ) AS t1
|
||||
RIGHT JOIN ( SELECT count('x'), count('y'), 2 AS x ) AS t2
|
||||
ON t1.x = t2.x;
|
||||
|
||||
select * from (select 2 as x) as t1 right join (select count('x'), count('y'), 0 as x) as t2 on t1.x = t2.x;
|
||||
|
Loading…
Reference in New Issue
Block a user