Skip to content

Commit

Permalink
[YQL-18511] Detect GROUPING() column count mismatch (merge to stable) (
Browse files Browse the repository at this point in the history
  • Loading branch information
nepal authored Jun 4, 2024
1 parent 7c04f77 commit 9d294e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
22 changes: 22 additions & 0 deletions ydb/library/yql/sql/v1/select.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1316,6 +1316,20 @@ class TCompositeSelect: public IRealSource {
return false;
}
}

TMaybe<size_t> groupingColumnsCount;
size_t idx = 0;
for (const auto& select : Subselects) {
size_t count = select->GetGroupingColumnsCount();
if (!groupingColumnsCount.Defined()) {
groupingColumnsCount = count;
} else if (*groupingColumnsCount != count) {
ctx.Error(select->GetPos()) << TStringBuilder() << "Mismatch GROUPING() column count in composite select input #"
<< idx << ": expected " << *groupingColumnsCount << ", got: " << count << ". Please submit bug report";
return false;
}
++idx;
}
return true;
}

Expand Down Expand Up @@ -1494,6 +1508,10 @@ class TSelectCore: public IRealSource, public IComposableSource {
ISource::GetInputTables(tableList);
}

size_t GetGroupingColumnsCount() const override {
return Source->GetGroupingColumnsCount();
}

bool DoInit(TContext& ctx, ISource* initSrc) override {
if (AsInner) {
Source->UseAsInner();
Expand Down Expand Up @@ -2598,6 +2616,10 @@ class TNestedProxySource: public IProxySource {
return true;
}

size_t GetGroupingColumnsCount() const override {
return Hints.size();
}

TNodePtr BuildGroupingColumns(const TString& label) override {
if (Hints.empty()) {
return nullptr;
Expand Down
4 changes: 4 additions & 0 deletions ydb/library/yql/sql/v1/source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ bool ISource::AddGrouping(TContext& ctx, const TVector<TString>& columns, TStrin
return false;
}

size_t ISource::GetGroupingColumnsCount() const {
return 0;
}

TNodePtr ISource::BuildFilter(TContext& ctx, const TString& label) {
return Filters.empty() ? nullptr : Y(ctx.UseUnordered(*this) ? "OrderedFilter" : "Filter", label, BuildFilterLambda());
}
Expand Down
1 change: 1 addition & 0 deletions ydb/library/yql/sql/v1/source.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace NSQLTranslationV1 {
virtual bool SetSamplingOptions(TContext& ctx, TPosition pos, ESampleClause clause, ESampleMode mode, TNodePtr samplingRate, TNodePtr samplingSeed);
virtual bool SetTableHints(TContext& ctx, TPosition pos, const TTableHints& hints, const TTableHints& contextHints);
virtual bool AddGrouping(TContext& ctx, const TVector<TString>& columns, TString& groupingColumn);
virtual size_t GetGroupingColumnsCount() const;
virtual TNodePtr BuildFilter(TContext& ctx, const TString& label);
virtual TNodePtr BuildFilterLambda();
virtual TNodePtr BuildFlattenByColumns(const TString& label);
Expand Down

0 comments on commit 9d294e9

Please sign in to comment.