StorageJoin clashing column name with JOIN ON

This commit is contained in:
vdimir 2021-05-10 17:56:12 +03:00
parent f03f591e55
commit cb89a2be97
No known key found for this signature in database
GPG Key ID: F57B3E10A21DBB31
4 changed files with 31 additions and 6 deletions

View File

@ -1096,7 +1096,8 @@ void HashJoin::joinBlockImpl(
const auto & col = block.getByName(left_name);
bool is_nullable = nullable_right_side || right_key.type->isNullable();
block.insert(correctNullability({col.column, col.type, right_key.name}, is_nullable));
auto right_col_name = getTableJoin().renamedRightColumnName(right_key.name);
block.insert(correctNullability({col.column, col.type, right_col_name}, is_nullable));
}
}
else if (has_required_right_keys)
@ -1121,7 +1122,8 @@ void HashJoin::joinBlockImpl(
bool is_nullable = nullable_right_side || right_key.type->isNullable();
ColumnPtr thin_column = filterWithBlanks(col.column, filter);
block.insert(correctNullability({thin_column, col.type, right_key.name}, is_nullable, null_map_filter));
auto right_col_name = getTableJoin().renamedRightColumnName(right_key.name);
block.insert(correctNullability({thin_column, col.type, right_col_name}, is_nullable, null_map_filter));
if constexpr (need_replication)
right_keys_to_replicate.push_back(block.getPositionByName(right_key.name));

View File

@ -156,9 +156,12 @@ NameSet TableJoin::requiredRightKeys() const
{
NameSet required;
for (const auto & name : key_names_right)
{
auto rename = renamedRightColumnName(name);
for (const auto & column : columns_added_by_join)
if (name == column.name)
if (rename == column.name)
required.insert(name);
}
return required;
}

View File

@ -28,6 +28,16 @@
7 7
8 8
9 9
0 0 0
1 1 1 abc
2 2 2 def
3 0 3
4 0 4
5 0 5
6 6 6 ghi
7 0 7
8 0 8
9 0 9
0 3
3 9
2 21 def
@ -44,3 +54,13 @@
7 7
8 8
9 9
0 0 0
1 1 1 abc
2 2 2 def
3 0 3
4 0 4
5 0 5
6 6 6 ghi
7 0 7
8 0 8
9 0 9

View File

@ -9,11 +9,11 @@ INSERT INTO t2 VALUES (6, 'ghi');
SELECT k, s FROM (SELECT number AS k FROM system.numbers LIMIT 10) js1 ANY LEFT JOIN t2 USING k;
SELECT k, js1.s, t2.s FROM (SELECT number AS k, number as s FROM system.numbers LIMIT 10) js1 ANY LEFT JOIN t2 USING k;
SELECT k, t2.k, js1.s, t2.s FROM (SELECT number AS k, number as s FROM system.numbers LIMIT 10) js1 ANY LEFT JOIN t2 USING k;
SELECT k, js1.s, t2.s FROM (SELECT toUInt64(number / 3) AS k, sum(number) as s FROM numbers(10) GROUP BY toUInt64(number / 3) WITH TOTALS) js1 ANY LEFT JOIN t2 USING k;
SELECT k, js1.s, t2.s FROM (SELECT number AS k, number AS s FROM system.numbers LIMIT 10) js1 ANY LEFT JOIN t2 ON js1.k == t2.k;
-- getting qualified key columns from Join table still doen't work
SELECT t2.k FROM (SELECT number AS k, number AS s FROM system.numbers LIMIT 10) js1 ANY LEFT JOIN t2 ON js1.k == t2.k; -- { serverError 8 }
SELECT k, t2.k, js1.s, t2.s FROM (SELECT number AS k, number AS s FROM system.numbers LIMIT 10) js1 ANY LEFT JOIN t2 ON js1.k == t2.k;
DROP TABLE t2;