Skip to content

Commit

Permalink
[YQL-18456] Fix partition by grouping() (merge to stable) (ydb-platfo…
Browse files Browse the repository at this point in the history
  • Loading branch information
nepal authored May 28, 2024
1 parent f56741f commit ce0c215
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 7 deletions.
8 changes: 8 additions & 0 deletions ydb/library/yql/sql/v1/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,14 @@ TWindowSpecificationPtr TWindowSpecification::Clone() const {
return res;
}

TWinSpecs CloneContainer(const TWinSpecs& specs) {
TWinSpecs newSpecs;
for (auto cur: specs) {
newSpecs.emplace(cur.first, cur.second->Clone());
}
return newSpecs;
}

TLegacyHoppingWindowSpecPtr TLegacyHoppingWindowSpec::Clone() const {
auto res = MakeIntrusive<TLegacyHoppingWindowSpec>();
res->TimeExtractor = TimeExtractor->Clone();
Expand Down
2 changes: 2 additions & 0 deletions ydb/library/yql/sql/v1/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,8 @@ namespace NSQLTranslationV1 {
typedef TIntrusivePtr<TWindowSpecification> TWindowSpecificationPtr;
typedef TMap<TString, TWindowSpecificationPtr> TWinSpecs;

TWinSpecs CloneContainer(const TWinSpecs& specs);

void WarnIfAliasFromSelectIsUsedInGroupBy(TContext& ctx, const TVector<TNodePtr>& selectTerms, const TVector<TNodePtr>& groupByTerms,
const TVector<TNodePtr>& groupByExprTerms);
bool ValidateAllNodesForAggregation(TContext& ctx, const TVector<TNodePtr>& nodes);
Expand Down
10 changes: 3 additions & 7 deletions ydb/library/yql/sql/v1/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ class TSelectCore: public IRealSource, public IComposableSource {
bool assumeSorted,
const TVector<TSortSpecificationPtr>& orderBy,
TNodePtr having,
TWinSpecs& winSpecs,
const TWinSpecs& winSpecs,
TLegacyHoppingWindowSpecPtr legacyHoppingWindowSpec,
const TVector<TNodePtr>& terms,
bool distinct,
Expand Down Expand Up @@ -1886,13 +1886,9 @@ class TSelectCore: public IRealSource, public IComposableSource {
}

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

Expand Down Expand Up @@ -2704,7 +2700,7 @@ TSourcePtr DoBuildSelectCore(
}
totalGroups += contentPtr->size();
TSelectCore* selectCore = new TSelectCore(pos, std::move(proxySource), CloneContainer(groupByExpr),
CloneContainer(*contentPtr), compactGroupBy, groupBySuffix, assumeSorted, orderBy, SafeClone(having), winSpecs,
CloneContainer(*contentPtr), compactGroupBy, groupBySuffix, assumeSorted, orderBy, SafeClone(having), CloneContainer(winSpecs),
legacyHoppingWindowSpec, terms, distinct, without, selectStream, settings, TColumnsSets(uniqueSets), TColumnsSets(distinctSets));
subselects.emplace_back(selectCore);
}
Expand Down
22 changes: 22 additions & 0 deletions ydb/library/yql/tests/sql/dq_file/part2/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,28 @@
}
],
"test.test[aggregate-group_by_rollup_column_ref--Results]": [],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Analyze]": [
{
"checksum": "627c0892224045a615f6196a4a3a11c9",
"size": 9009,
"uri": "https://{canondata_backend}/1937367/6af906d8e8515951055311e09244912c4095ac7f/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Analyze_/plan.txt"
}
],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Debug]": [
{
"checksum": "ed88dd60c2213f296962c78fc79f8176",
"size": 7933,
"uri": "https://{canondata_backend}/1937367/6af906d8e8515951055311e09244912c4095ac7f/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Plan]": [
{
"checksum": "627c0892224045a615f6196a4a3a11c9",
"size": 9009,
"uri": "https://{canondata_backend}/1937367/6af906d8e8515951055311e09244912c4095ac7f/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Plan_/plan.txt"
}
],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Results]": [],
"test.test[aggregate-group_compact_sorted--Analyze]": [
{
"checksum": "683fe495c075d2b1f1efcc8737139f4c",
Expand Down
14 changes: 14 additions & 0 deletions ydb/library/yql/tests/sql/hybrid_file/part7/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,20 @@
"uri": "https://{canondata_backend}/212715/61f0c59354c0aee96d5e21e3fd5f5993b2817ac3/resource.tar.gz#test.test_aggregate-group_by_ru_join_qualified-default.txt-Plan_/plan.txt"
}
],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Debug]": [
{
"checksum": "de316c64468c3faa986ec5c488025497",
"size": 15078,
"uri": "https://{canondata_backend}/1942415/e4ebd91d76d6ca7ef12656b64e915b90972caa6e/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Debug_/opt.yql_patched"
}
],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Plan]": [
{
"checksum": "6c542e611ec25311658464187b4e0271",
"size": 17625,
"uri": "https://{canondata_backend}/1942415/e4ebd91d76d6ca7ef12656b64e915b90972caa6e/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Plan_/plan.txt"
}
],
"test.test[aggregate-group_by_session_only_distinct--Debug]": [
{
"checksum": "892425a7698d17f84c4b404604e8f1b7",
Expand Down
14 changes: 14 additions & 0 deletions ydb/library/yql/tests/sql/sql2yql/canondata/result.json
Original file line number Diff line number Diff line change
Expand Up @@ -2330,6 +2330,13 @@
"uri": "https://{canondata_backend}/1942278/beab6e829114ea03a5df7881bc0d363cdf567406/resource.tar.gz#test_sql2yql.test_aggregate-group_by_ru_join_star_/sql.yql"
}
],
"test_sql2yql.test[aggregate-group_by_ru_partition_by_grouping]": [
{
"checksum": "006a167731e643e993f975e4904366fd",
"size": 5896,
"uri": "https://{canondata_backend}/1781765/275eb46642921957e733909d887afbe95f1f2061/resource.tar.gz#test_sql2yql.test_aggregate-group_by_ru_partition_by_grouping_/sql.yql"
}
],
"test_sql2yql.test[aggregate-group_by_ru_with_select_distinct]": [
{
"checksum": "66b8b1eea14cf9658a7e60294b73ffef",
Expand Down Expand Up @@ -20789,6 +20796,13 @@
"uri": "https://{canondata_backend}/1880306/64654158d6bfb1289c66c626a8162239289559d0/resource.tar.gz#test_sql_format.test_aggregate-group_by_ru_join_star_/formatted.sql"
}
],
"test_sql_format.test[aggregate-group_by_ru_partition_by_grouping]": [
{
"checksum": "8d25349881c2bfebab70dadc86107a43",
"size": 328,
"uri": "https://{canondata_backend}/1781765/275eb46642921957e733909d887afbe95f1f2061/resource.tar.gz#test_sql_format.test_aggregate-group_by_ru_partition_by_grouping_/formatted.sql"
}
],
"test_sql_format.test[aggregate-group_by_ru_with_select_distinct]": [
{
"checksum": "6561aa13b2247a3ee4f4aa906e01496f",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use plato;

select
key,
subkey,
min(value) as mv,
grouping(key) + grouping(subkey) as gsum,
rank() over (
partition by grouping(key) + grouping(subkey)
order by key, subkey, min(value)
) as rk,
from Input
group by rollup(key, subkey);
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,27 @@
"uri": "https://{canondata_backend}/1946324/7d1d6b1f697cbe9fb62c81047eb61d3fa72baf62/resource.tar.gz#test.test_aggregate-group_by_rollup_column_ref--Results_/results.txt"
}
],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Debug]": [
{
"checksum": "2ba53271e7f3d6434d915d08223df413",
"size": 11839,
"uri": "https://{canondata_backend}/1937367/76b40260a60b6f101f72f6207cb4023d8d41c952/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Debug_/opt.yql"
}
],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Plan]": [
{
"checksum": "666bf6f47c41401bb4181c6cab01fd4f",
"size": 13259,
"uri": "https://{canondata_backend}/1937367/76b40260a60b6f101f72f6207cb4023d8d41c952/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Plan_/plan.txt"
}
],
"test.test[aggregate-group_by_ru_partition_by_grouping-default.txt-Results]": [
{
"checksum": "896d06698c8b40b5e6ad0811ae10aec0",
"size": 4968,
"uri": "https://{canondata_backend}/1937367/76b40260a60b6f101f72f6207cb4023d8d41c952/resource.tar.gz#test.test_aggregate-group_by_ru_partition_by_grouping-default.txt-Results_/results.txt"
}
],
"test.test[aggregate-group_compact_sorted--Debug]": [
{
"checksum": "4975fb4bab70a1ef061dacf3c63c08a2",
Expand Down

0 comments on commit ce0c215

Please sign in to comment.