diff options
author | aneporada <aneporada@ydb.tech> | 2023-05-03 12:02:44 +0300 |
---|---|---|
committer | aneporada <aneporada@ydb.tech> | 2023-05-03 12:02:44 +0300 |
commit | f6a12447ecba795d28300e7f709c1abc9acad0cf (patch) | |
tree | 2a3e6d0e60eb63d436517772eb71af0ed2e394ee | |
parent | 1033b838cd60505f8e2f24d182915d2330f358cb (diff) | |
download | ydb-f6a12447ecba795d28300e7f709c1abc9acad0cf.tar.gz |
[parser] Detect invalid aggregation in select distinct
initial
-rw-r--r-- | ydb/library/yql/sql/v1/select.cpp | 2 | ||||
-rw-r--r-- | ydb/library/yql/sql/v1/sql_ut.cpp | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/ydb/library/yql/sql/v1/select.cpp b/ydb/library/yql/sql/v1/select.cpp index c3fa583668..65d7a3624c 100644 --- a/ydb/library/yql/sql/v1/select.cpp +++ b/ydb/library/yql/sql/v1/select.cpp @@ -1923,7 +1923,7 @@ private: if (Having && !Having->Init(ctx, src)) { hasError = true; } - if (!src->IsCompositeSource() && !Distinct && !Columns.All && src->HasAggregations()) { + if (!src->IsCompositeSource() && !Columns.All && src->HasAggregations()) { WarnIfAliasFromSelectIsUsedInGroupBy(ctx, Terms, GroupBy, GroupByExpr); /// verify select aggregation compatibility diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index d6775fb53b..8b8f58b58f 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -2306,6 +2306,13 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) { "<main>:1:17: Error: Column `subkey` must either be a key column in GROUP BY or it should be used in aggregation function\n"); } + Y_UNIT_TEST(SelectDistinctWithBadAggregation) { + ExpectFailWithError("select distinct count(*), 1 + key from plato.Input", + "<main>:1:31: Error: Column `key` must either be a key column in GROUP BY or it should be used in aggregation function\n"); + ExpectFailWithError("select distinct key, 2 * subkey from plato.Input group by key", + "<main>:1:26: Error: Column `subkey` must either be a key column in GROUP BY or it should be used in aggregation function\n"); + } + Y_UNIT_TEST(SelectWithBadAggregationInHaving) { ExpectFailWithError("select key from plato.Input group by key\n" "having \"f\" || value == \"foo\"", |