Skip to content

Commit ce99631

Browse files
authored
Merge pull request ClickHouse#45565 from ClickHouse/backport/22.8/41189
Backport ClickHouse#41189 to 22.8: Fix for positional arguments
2 parents 9c18d92 + 6e8842e commit ce99631

File tree

3 files changed

+29
-3
lines changed

3 files changed

+29
-3
lines changed

src/Interpreters/TreeRewriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1253,9 +1253,6 @@ TreeRewriterResultPtr TreeRewriter::analyzeSelect(
12531253
all_source_columns_set.insert(name);
12541254
}
12551255

1256-
normalize(query, result.aliases, all_source_columns_set, select_options.ignore_alias, settings, /* allow_self_aliases = */ true, getContext());
1257-
1258-
12591256
if (getContext()->getSettingsRef().enable_positional_arguments)
12601257
{
12611258
if (select_query->groupBy())
@@ -1275,6 +1272,8 @@ TreeRewriterResultPtr TreeRewriter::analyzeSelect(
12751272
}
12761273
}
12771274

1275+
normalize(query, result.aliases, all_source_columns_set, select_options.ignore_alias, settings, /* allow_self_aliases = */ true, getContext());
1276+
12781277
/// Remove unneeded columns according to 'required_result_columns'.
12791278
/// Leave all selected columns in case of DISTINCT; columns that contain arrayJoin function inside.
12801279
/// Must be after 'normalizeTree' (after expanding aliases, for aliases not get lost)

tests/queries/0_stateless/02006_test_positional_arguments.reference

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,19 @@ select b from (select 5 as a, 'Hello' as b group by a);
117117
Hello
118118
select b from (select 5 as a, 'Hello' as b order by 1);
119119
Hello
120+
drop table if exists tp2;
120121
create table tp2(first_col String, second_col Int32) engine = MergeTree() order by tuple();
121122
select count(*) from (select first_col, count(second_col) from tp2 group by 1);
122123
0
123124
select total from (select first_col, count(second_col) as total from tp2 group by 1);
125+
drop table if exists test;
126+
create table test
127+
(
128+
`id` UInt32,
129+
`time` UInt32,
130+
index `id` (`id`) type set(0) granularity 3,
131+
index `time` (`time`) type minmax granularity 3
132+
) engine = MergeTree()
133+
order by (`time`);
134+
select count(*) as `value`, 0 as `data` from test group by `data`;
135+
drop table test;

tests/queries/0_stateless/02006_test_positional_arguments.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,21 @@ select b from (select 5 as a, 'Hello' as b order by a);
4949
select b from (select 5 as a, 'Hello' as b group by a);
5050
select b from (select 5 as a, 'Hello' as b order by 1);
5151

52+
drop table if exists tp2;
5253
create table tp2(first_col String, second_col Int32) engine = MergeTree() order by tuple();
5354
select count(*) from (select first_col, count(second_col) from tp2 group by 1);
5455
select total from (select first_col, count(second_col) as total from tp2 group by 1);
56+
57+
drop table if exists test;
58+
create table test
59+
(
60+
`id` UInt32,
61+
`time` UInt32,
62+
index `id` (`id`) type set(0) granularity 3,
63+
index `time` (`time`) type minmax granularity 3
64+
) engine = MergeTree()
65+
order by (`time`);
66+
67+
select count(*) as `value`, 0 as `data` from test group by `data`;
68+
69+
drop table test;

0 commit comments

Comments
 (0)