summaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/aggregation.cpp
diff options
context:
space:
mode:
authorvitya-smirnov <[email protected]>2025-07-15 17:01:51 +0300
committervitya-smirnov <[email protected]>2025-07-15 17:19:51 +0300
commit64137fb0cbe9afe92dca8efc335ef9ff16b78926 (patch)
tree1f35ca0b330569f9725b3cfc2971a894b65b25f7 /yql/essentials/sql/v1/aggregation.cpp
parent6fb5119e5d0aee18cf78fb28d7f71c9539cca6dc (diff)
YQL-20171: Fix aggregation joining key
There was a bug with a aggregation deduplication by a column at the translator. For a single column the system joining all aggregations using the generic key. The generic key was just a column name without source name what leads to collision when aggregating multiple different sources with same column names. This patch fixes the generic key by adding a data source name there. Also tests are added. commit_hash:1c0a9da512f68c58d2830e096de76b769b733cb2
Diffstat (limited to 'yql/essentials/sql/v1/aggregation.cpp')
-rw-r--r--yql/essentials/sql/v1/aggregation.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/yql/essentials/sql/v1/aggregation.cpp b/yql/essentials/sql/v1/aggregation.cpp
index 130ec26d5f7..d7324012c13 100644
--- a/yql/essentials/sql/v1/aggregation.cpp
+++ b/yql/essentials/sql/v1/aggregation.cpp
@@ -714,8 +714,16 @@ public:
{}
private:
- const TString* GetGenericKey() const final {
- return Column_;
+ TMaybe<TString> GetGenericKey() const final {
+ if (!Column_) {
+ return Nothing();
+ }
+
+ TStringBuilder key;
+ if (Source_) {
+ key << *Source_ << ".";
+ }
+ return key << *Column_;
}
void Join(IAggregation* aggr) final {
@@ -736,7 +744,16 @@ private:
}
if (!isFactory) {
- Column_ = exprs.front()->GetColumnName();
+ Source_ = Nothing();
+ Column_ = Nothing();
+
+ const auto& expr = exprs.front();
+ if (const TString* source = expr->GetSourceName()) {
+ Source_ = *source;
+ }
+ if (const TString* column = expr->GetColumnName()) {
+ Column_ = *column;
+ }
}
if (!TAggregationFactory::InitAggr(ctx, isFactory, src, node, isFactory ? TVector<TNodePtr>() : TVector<TNodePtr>(1, exprs.front())))
@@ -828,7 +845,8 @@ private:
TSourcePtr FakeSource_;
std::multimap<TString, TNodePtr> Percentiles_;
TNodePtr FactoryPercentile_;
- const TString* Column_ = nullptr;
+ TMaybe<TString> Source_;
+ TMaybe<TString> Column_;
};
TAggregationPtr BuildPercentileFactoryAggregation(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode) {