Skip to content

Commit 33cd85a

Browse files
authored
[YQL-18456] Fix partition by grouping() (#4902)
1 parent ed3ba1f commit 33cd85a

File tree

8 files changed

+97
-7
lines changed

8 files changed

+97
-7
lines changed

ydb/library/yql/sql/v1/node.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,14 @@ TWindowSpecificationPtr TWindowSpecification::Clone() const {
10871087
return res;
10881088
}
10891089

1090+
TWinSpecs CloneContainer(const TWinSpecs& specs) {
1091+
TWinSpecs newSpecs;
1092+
for (auto cur: specs) {
1093+
newSpecs.emplace(cur.first, cur.second->Clone());
1094+
}
1095+
return newSpecs;
1096+
}
1097+
10901098
TLegacyHoppingWindowSpecPtr TLegacyHoppingWindowSpec::Clone() const {
10911099
auto res = MakeIntrusive<TLegacyHoppingWindowSpec>();
10921100
res->TimeExtractor = TimeExtractor->Clone();

ydb/library/yql/sql/v1/node.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,8 @@ namespace NSQLTranslationV1 {
669669
typedef TIntrusivePtr<TWindowSpecification> TWindowSpecificationPtr;
670670
typedef TMap<TString, TWindowSpecificationPtr> TWinSpecs;
671671

672+
TWinSpecs CloneContainer(const TWinSpecs& specs);
673+
672674
void WarnIfAliasFromSelectIsUsedInGroupBy(TContext& ctx, const TVector<TNodePtr>& selectTerms, const TVector<TNodePtr>& groupByTerms,
673675
const TVector<TNodePtr>& groupByExprTerms);
674676
bool ValidateAllNodesForAggregation(TContext& ctx, const TVector<TNodePtr>& nodes);

ydb/library/yql/sql/v1/select.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,7 @@ class TSelectCore: public IRealSource, public IComposableSource {
14541454
bool assumeSorted,
14551455
const TVector<TSortSpecificationPtr>& orderBy,
14561456
TNodePtr having,
1457-
TWinSpecs& winSpecs,
1457+
const TWinSpecs& winSpecs,
14581458
TLegacyHoppingWindowSpecPtr legacyHoppingWindowSpec,
14591459
const TVector<TNodePtr>& terms,
14601460
bool distinct,
@@ -1888,13 +1888,9 @@ class TSelectCore: public IRealSource, public IComposableSource {
18881888
}
18891889

18901890
TNodePtr DoClone() const final {
1891-
TWinSpecs newSpecs;
1892-
for (auto cur: WinSpecs) {
1893-
newSpecs.emplace(cur.first, cur.second->Clone());
1894-
}
18951891
return new TSelectCore(Pos, Source->CloneSource(), CloneContainer(GroupByExpr),
18961892
CloneContainer(GroupBy), CompactGroupBy, GroupBySuffix, AssumeSorted, CloneContainer(OrderBy),
1897-
SafeClone(Having), newSpecs, SafeClone(LegacyHoppingWindowSpec),
1893+
SafeClone(Having), CloneContainer(WinSpecs), SafeClone(LegacyHoppingWindowSpec),
18981894
CloneContainer(Terms), Distinct, Without, SelectStream, Settings, TColumnsSets(UniqueSets), TColumnsSets(DistinctSets));
18991895
}
19001896

@@ -2706,7 +2702,7 @@ TSourcePtr DoBuildSelectCore(
27062702
}
27072703
totalGroups += contentPtr->size();
27082704
TSelectCore* selectCore = new TSelectCore(pos, std::move(proxySource), CloneContainer(groupByExpr),
2709-
CloneContainer(*contentPtr), compactGroupBy, groupBySuffix, assumeSorted, orderBy, SafeClone(having), winSpecs,
2705+
CloneContainer(*contentPtr), compactGroupBy, groupBySuffix, assumeSorted, orderBy, SafeClone(having), CloneContainer(winSpecs),
27102706
legacyHoppingWindowSpec, terms, distinct, without, selectStream, settings, TColumnsSets(uniqueSets), TColumnsSets(distinctSets));
27112707
subselects.emplace_back(selectCore);
27122708
}

ydb/library/yql/tests/sql/dq_file/part2/canondata/result.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,28 @@
266266
}
267267
],
268268
"test.test[aggregate-group_by_rollup_column_ref--Results]": [],
269+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Analyze]": [
270+
{
271+
"checksum": "627c0892224045a615f6196a4a3a11c9",
272+
"size": 9009,
273+
"uri": "https://{canondata_backend}/1937367/6af906d8e8515951055311e09244912c4095ac7f/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Analyze_/plan.txt"
274+
}
275+
],
276+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Debug]": [
277+
{
278+
"checksum": "ed88dd60c2213f296962c78fc79f8176",
279+
"size": 7933,
280+
"uri": "https://{canondata_backend}/1937367/6af906d8e8515951055311e09244912c4095ac7f/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Debug_/opt.yql_patched"
281+
}
282+
],
283+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Plan]": [
284+
{
285+
"checksum": "627c0892224045a615f6196a4a3a11c9",
286+
"size": 9009,
287+
"uri": "https://{canondata_backend}/1937367/6af906d8e8515951055311e09244912c4095ac7f/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Plan_/plan.txt"
288+
}
289+
],
290+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Results]": [],
269291
"test.test[aggregate-group_compact_sorted--Analyze]": [
270292
{
271293
"checksum": "683fe495c075d2b1f1efcc8737139f4c",

ydb/library/yql/tests/sql/hybrid_file/part7/canondata/result.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,20 @@
391391
"uri": "https://{canondata_backend}/212715/61f0c59354c0aee96d5e21e3fd5f5993b2817ac3/resource.tar.gz#test.test_aggregate-group_by_ru_join_qualified-default.txt-Plan_/plan.txt"
392392
}
393393
],
394+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Debug]": [
395+
{
396+
"checksum": "de316c64468c3faa986ec5c488025497",
397+
"size": 15078,
398+
"uri": "https://{canondata_backend}/1942415/e4ebd91d76d6ca7ef12656b64e915b90972caa6e/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Debug_/opt.yql_patched"
399+
}
400+
],
401+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Plan]": [
402+
{
403+
"checksum": "6c542e611ec25311658464187b4e0271",
404+
"size": 17625,
405+
"uri": "https://{canondata_backend}/1942415/e4ebd91d76d6ca7ef12656b64e915b90972caa6e/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Plan_/plan.txt"
406+
}
407+
],
394408
"test.test[aggregate-group_by_session_only_distinct--Debug]": [
395409
{
396410
"checksum": "892425a7698d17f84c4b404604e8f1b7",

ydb/library/yql/tests/sql/sql2yql/canondata/result.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,6 +2351,13 @@
23512351
"uri": "https://{canondata_backend}/1942278/beab6e829114ea03a5df7881bc0d363cdf567406/resource.tar.gz#test_sql2yql.test_aggregate-group_by_ru_join_star_/sql.yql"
23522352
}
23532353
],
2354+
"test_sql2yql.test[aggregate-group_by_ru_partition_by_grouping]": [
2355+
{
2356+
"checksum": "006a167731e643e993f975e4904366fd",
2357+
"size": 5896,
2358+
"uri": "https://{canondata_backend}/1781765/275eb46642921957e733909d887afbe95f1f2061/resource.tar.gz#test_sql2yql.test_aggregate-group_by_ru_partition_by_grouping_/sql.yql"
2359+
}
2360+
],
23542361
"test_sql2yql.test[aggregate-group_by_ru_with_select_distinct]": [
23552362
{
23562363
"checksum": "66b8b1eea14cf9658a7e60294b73ffef",
@@ -20950,6 +20957,13 @@
2095020957
"uri": "https://{canondata_backend}/1880306/64654158d6bfb1289c66c626a8162239289559d0/resource.tar.gz#test_sql_format.test_aggregate-group_by_ru_join_star_/formatted.sql"
2095120958
}
2095220959
],
20960+
"test_sql_format.test[aggregate-group_by_ru_partition_by_grouping]": [
20961+
{
20962+
"checksum": "8d25349881c2bfebab70dadc86107a43",
20963+
"size": 328,
20964+
"uri": "https://{canondata_backend}/1781765/275eb46642921957e733909d887afbe95f1f2061/resource.tar.gz#test_sql_format.test_aggregate-group_by_ru_partition_by_grouping_/formatted.sql"
20965+
}
20966+
],
2095320967
"test_sql_format.test[aggregate-group_by_ru_with_select_distinct]": [
2095420968
{
2095520969
"checksum": "6561aa13b2247a3ee4f4aa906e01496f",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use plato;
2+
3+
select
4+
key,
5+
subkey,
6+
min(value) as mv,
7+
grouping(key) + grouping(subkey) as gsum,
8+
rank() over (
9+
partition by grouping(key) + grouping(subkey)
10+
order by key, subkey, min(value)
11+
) as rk,
12+
from Input
13+
group by rollup(key, subkey);

ydb/library/yql/tests/sql/yt_native_file/part2/canondata/result.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,27 @@
251251
"uri": "https://{canondata_backend}/1946324/7d1d6b1f697cbe9fb62c81047eb61d3fa72baf62/resource.tar.gz#test.test_aggregate-group_by_rollup_column_ref--Results_/results.txt"
252252
}
253253
],
254+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Debug]": [
255+
{
256+
"checksum": "2ba53271e7f3d6434d915d08223df413",
257+
"size": 11839,
258+
"uri": "https://{canondata_backend}/1937367/76b40260a60b6f101f72f6207cb4023d8d41c952/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Debug_/opt.yql"
259+
}
260+
],
261+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Plan]": [
262+
{
263+
"checksum": "666bf6f47c41401bb4181c6cab01fd4f",
264+
"size": 13259,
265+
"uri": "https://{canondata_backend}/1937367/76b40260a60b6f101f72f6207cb4023d8d41c952/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Plan_/plan.txt"
266+
}
267+
],
268+
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Results]": [
269+
{
270+
"checksum": "896d06698c8b40b5e6ad0811ae10aec0",
271+
"size": 4968,
272+
"uri": "https://{canondata_backend}/1937367/76b40260a60b6f101f72f6207cb4023d8d41c952/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Results_/results.txt"
273+
}
274+
],
254275
"test.test[aggregate-group_compact_sorted--Debug]": [
255276
{
256277
"checksum": "4975fb4bab70a1ef061dacf3c63c08a2",

0 commit comments

Comments
 (0)