Remove clashed columns from totals for StorageJoin

This commit is contained in:
vdimir 2021-04-23 15:37:05 +03:00
parent 0b990c9519
commit 9460989721
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
3 changed files with 13 additions and 0 deletions

View File

@ -284,6 +284,11 @@ void joinTotals(const Block & totals, const Block & columns_to_add, const TableJ
for (size_t i = 0; i < columns_to_add.columns(); ++i)
{
const auto & col = columns_to_add.getByPosition(i);
if (block.has(col.name))
{
/// For StorageJoin we discarded table qualifiers, so some names may clash
continue;
}
block.insert({
col.type->createColumnConstWithDefaultValue(1)->convertToFullColumnIfConst(),
col.type,

View File

@ -38,3 +38,7 @@ ghi []
1 [] 2 3 7 4
1 [] 2 3 8 4
1 [] 2 3 9 4
0 a []
1 a [0]
0 a []

View File

@ -11,4 +11,8 @@ SELECT s, x FROM (SELECT number AS k FROM system.numbers LIMIT 10) js1 ANY LEFT
SELECT x, s, k FROM (SELECT number AS k FROM system.numbers LIMIT 10) js1 ANY LEFT JOIN join USING k;
SELECT 1, x, 2, s, 3, k, 4 FROM (SELECT number AS k FROM system.numbers LIMIT 10) js1 ANY LEFT JOIN join USING k;
SELECT t1.k, t1.s, t2.x
FROM ( SELECT number AS k, 'a' AS s FROM numbers(2) GROUP BY number WITH TOTALS ) AS t1
ANY LEFT JOIN join AS t2 USING(k);
DROP TABLE join;