diff options
author | Andrey Neporada <neporada@gmail.com> | 2022-06-09 14:23:54 +0300 |
---|---|---|
committer | Andrey Neporada <neporada@gmail.com> | 2022-06-09 14:23:54 +0300 |
commit | 0d55ca22c507d18c2f35718687e0b06d9915397b (patch) | |
tree | 811b4afa6e62a2baa44e4539da892ed825266bb2 | |
parent | 1a0a79084f0aa2254c3eeb466e47596b9c258140 (diff) | |
download | ydb-0d55ca22c507d18c2f35718687e0b06d9915397b.tar.gz |
[YQL-14872] Properly init second arg of AggregationFactory("max_by", x)
ref:98434811bd7cc6167924a77eceeabee8b0c3a6f7
-rw-r--r-- | ydb/library/yql/sql/v1/aggregation.cpp | 13 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/sql_ut.cpp | 7 |
2 files changed, 15 insertions, 5 deletions
diff --git a/ydb/library/yql/sql/v1/aggregation.cpp b/ydb/library/yql/sql/v1/aggregation.cpp index a00d082885..c59f39d3df 100644 --- a/ydb/library/yql/sql/v1/aggregation.cpp +++ b/ydb/library/yql/sql/v1/aggregation.cpp @@ -210,6 +210,7 @@ class TKeyPayloadAggregationFactory final : public TAggregationFactory { public: TKeyPayloadAggregationFactory(TPosition pos, const TString& name, const TString& factory, EAggregateMode aggMode) : TAggregationFactory(pos, name, factory, aggMode) + , FakeSource(BuildFakeSource(pos)) {} private: @@ -279,6 +280,12 @@ private: } bool DoInit(TContext& ctx, ISource* src) final { + if (Limit) { + if (!Limit->Init(ctx, FakeSource.Get())) { + return false; + } + } + if (!Key) { return true; } @@ -289,11 +296,6 @@ private: if (!Payload->Init(ctx, src)) { return false; } - if (Limit) { - if (!Limit->Init(ctx, src)) { - return false; - } - } if (Key->IsAggregated()) { ctx.Error(Pos) << "Aggregation of aggregated values is forbidden"; @@ -302,6 +304,7 @@ private: return true; } + TSourcePtr FakeSource; TNodePtr Key, Payload, Limit; }; diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index 1a2acb110b..986daff1d5 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -3281,6 +3281,13 @@ select FormatType($f()); UNIT_ASSERT(res.Root); UNIT_ASSERT_NO_DIFF(Err2Str(res), "<main>:1:48: Warning: Deprecated syntax for positional schema: please use 'column type' instead of 'type AS column', code: 4535\n"); } + + Y_UNIT_TEST(ErrorOnColumnNameInMaxByLimit) { + ExpectFailWithError( + "SELECT AGGREGATE_BY(AsTuple(value, key), AggregationFactory(\"MAX_BY\", subkey)) FROM plato.Input;", + "<main>:1:42: Error: Source does not allow column references\n" + "<main>:1:71: Error: Column reference 'subkey'\n"); + } } void CheckUnused(const TString& req, const TString& symbol, unsigned row, unsigned col) { |