Merge pull request #31420 from kssenii/fix-positional-args-bug

Fix group by with positional args
This commit is contained in:
Kseniia Sumarokova 2021-11-15 20:42:58 +03:00 committed by GitHub
commit b040890fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 1 deletions

View File

@ -164,7 +164,7 @@ void optimizeGroupBy(ASTSelectQuery * select_query, ContextPtr context)
if (value.getType() == Field::Types::UInt64)
{
auto pos = value.get<UInt64>();
if (pos > 0 && pos <= select_query->children.size())
if (pos > 0 && pos <= select_query->select()->children.size())
keep_position = true;
}
}

View File

@ -145,3 +145,6 @@ select x1, x1 * 2, max(x2), max(x3) from test2 group by 2, 1, x1 order by 1, 2,
1 2 10 100
10 20 1 10
100 200 100 1
select a, b, c, d, e, f from (select 44 a, 88 b, 13 c, 14 d, 15 e, 16 f) t group by 1,2,3,4,5,6
44 88 13 14 15 16

View File

@ -47,3 +47,5 @@ explain syntax select x1 + x3, x3 from test group by 1, 2;
create table test2(x1 Int, x2 Int, x3 Int) engine=Memory;
insert into test2 values (1, 10, 100), (10, 1, 10), (100, 100, 1);
select x1, x1 * 2, max(x2), max(x3) from test2 group by 2, 1, x1 order by 1, 2, 4 desc, 3 asc;
select a, b, c, d, e, f from (select 44 a, 88 b, 13 c, 14 d, 15 e, 16 f) t group by 1,2,3,4,5,6