Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/Interpreters/TreeRewriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1353,7 +1353,14 @@ TreeRewriterResultPtr TreeRewriter::analyzeSelect(
result.analyzed_join = std::make_shared<TableJoin>();

if (remove_duplicates)
{
Aliases aliases;
NameSet name_set;

normalize(query, aliases, name_set, select_options.ignore_alias, settings, /* allow_self_aliases = */ true, getContext(), select_options.is_create_parameterized_view);
renameDuplicatedColumns(select_query);
}


/// Perform it before analyzing JOINs, because it may change number of columns with names unique and break some logic inside JOINs
if (settings[Setting::optimize_normalize_count_variants])
Expand Down
4 changes: 4 additions & 0 deletions tests/queries/0_stateless/03903_join_alias_dups.reference
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
42
1 g
42
1 g
32 changes: 32 additions & 0 deletions tests/queries/0_stateless/03903_join_alias_dups.sql.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{% for enable_analyzer in [0, 1] -%}

SET enable_analyzer = {{ enable_analyzer }};
SET join_algorithm = 'hash';

SELECT A.g
FROM ( SELECT 1::Int8 AS d ) AS B
JOIN ( SELECT 1::Int8 as d, g, 42::Int32 AS g FROM ( SELECT '128' AS g ) ) AS A
USING (d);

WITH B AS (
SELECT
1 AS d
),
A AS (
SELECT
g, d,
MAX(IF(m = 'A', g, NULL)) AS g
FROM
(
SELECT
'g' AS g, 1 d,
'A' m
)
GROUP BY ALL )
SELECT
B.*,
A.g
FROM
B
LEFT JOIN A USING d;
{% endfor -%}
Loading