diff --git a/ydb/core/kqp/ut/opt/kqp_agg_ut.cpp b/ydb/core/kqp/ut/opt/kqp_agg_ut.cpp index 2000c73ad025..516192e1e19d 100644 --- a/ydb/core/kqp/ut/opt/kqp_agg_ut.cpp +++ b/ydb/core/kqp/ut/opt/kqp_agg_ut.cpp @@ -89,6 +89,84 @@ Y_UNIT_TEST_SUITE(KqpAgg) { [["Value3"];[1]] ])", FormatResultSetYson(result.GetResultSet(0))); } + + Y_UNIT_TEST(GroupByLimit) { + TKikimrRunner kikimr; + auto db = kikimr.GetTableClient(); + auto session = db.CreateSession().GetValueSync().GetSession(); + + AssertSuccessResult(session.ExecuteSchemeQuery(R"( + --!syntax_v1 + + CREATE TABLE `TestTable` ( + a Uint64, + b Uint64, + c Uint64, + d Uint64, + e Uint64, + PRIMARY KEY (a, b, c) + ); + )").GetValueSync()); + + AssertSuccessResult(session.ExecuteDataQuery(R"( + REPLACE INTO `TestTable` (a, b, c, d, e) VALUES + (1, 11, 21, 31, 41), + (2, 12, 22, 32, 42), + (3, 13, 23, 33, 43); + )", TTxControl::BeginTx(TTxSettings::SerializableRW()).CommitTx()).GetValueSync()); + + + { // query with 36 groups and limit 32 + auto result = session.ExecuteDataQuery(R"( + --!syntax_v1 + + PRAGMA GroupByLimit = '32'; + + SELECT a, b, c, d, SUM(e) Data FROM TestTable + GROUP BY ROLLUP(a, b, c, d, a * b AS ab, b * c AS bc, c * d AS cd, a + b AS sum) + ORDER BY a, b, c, d; + )", TTxControl::BeginTx().CommitTx()).ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL(result.GetStatus(), EStatus::GENERIC_ERROR); + } + + { // query with 36 groups (without explicit limit) + auto result = session.ExecuteDataQuery(R"( + --!syntax_v1 + + SELECT a, b, c, d, SUM(e) Data FROM TestTable + GROUP BY ROLLUP(a, b, c, d, a * b AS ab, b * c AS bc, c * d AS cd, a + b AS sum) + ORDER BY a, b, c, d; + )", TTxControl::BeginTx().CommitTx()).ExtractValueSync(); + UNIT_ASSERT_VALUES_EQUAL_C(result.GetStatus(), EStatus::SUCCESS, result.GetIssues().ToString()); + CompareYson(R"([ + [#;#;#;#;[126u]]; + [[1u];#;#;#;[41u]]; + [[1u];[11u];#;#;[41u]]; + [[1u];[11u];[21u];#;[41u]]; + [[1u];[11u];[21u];[31u];[41u]]; + [[1u];[11u];[21u];[31u];[41u]]; + [[1u];[11u];[21u];[31u];[41u]]; + [[1u];[11u];[21u];[31u];[41u]]; + [[1u];[11u];[21u];[31u];[41u]]; + [[2u];#;#;#;[42u]]; + [[2u];[12u];#;#;[42u]]; + [[2u];[12u];[22u];#;[42u]]; + [[2u];[12u];[22u];[32u];[42u]]; + [[2u];[12u];[22u];[32u];[42u]]; + [[2u];[12u];[22u];[32u];[42u]]; + [[2u];[12u];[22u];[32u];[42u]]; + [[2u];[12u];[22u];[32u];[42u]]; + [[3u];#;#;#;[43u]]; + [[3u];[13u];#;#;[43u]]; + [[3u];[13u];[23u];#;[43u]]; + [[3u];[13u];[23u];[33u];[43u]]; + [[3u];[13u];[23u];[33u];[43u]]; + [[3u];[13u];[23u];[33u];[43u]]; + [[3u];[13u];[23u];[33u];[43u]]; + [[3u];[13u];[23u];[33u];[43u]] + ])", FormatResultSetYson(result.GetResultSet(0))); + } + } } } // namespace NKikimr::NKqp diff --git a/ydb/library/yql/sql/v0/context.h b/ydb/library/yql/sql/v0/context.h index 45f40fae61c9..b8d8e4bd11d5 100644 --- a/ydb/library/yql/sql/v0/context.h +++ b/ydb/library/yql/sql/v0/context.h @@ -152,7 +152,7 @@ namespace NSQLTranslationV0 { bool EnableSystemColumns = true; ui32 ResultRowsLimit = 0; ui64 ResultSizeLimit = 0; - ui32 PragmaGroupByLimit = 1 << 5; + ui32 PragmaGroupByLimit = 1 << 6; ui32 PragmaGroupByCubeLimit = 5; THashSet Libraries; NYql::TWarningPolicy WarningPolicy; diff --git a/ydb/library/yql/sql/v0/sql_ut.cpp b/ydb/library/yql/sql/v0/sql_ut.cpp index 3a70aef93cc3..6ef5cfa5c9ab 100644 --- a/ydb/library/yql/sql/v0/sql_ut.cpp +++ b/ydb/library/yql/sql/v0/sql_ut.cpp @@ -1563,7 +1563,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) { Y_UNIT_TEST(GroupByFewBigCubes) { NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE(key, subkey, key + subkey as sum), CUBE(value, value + key + subkey as total);"); UNIT_ASSERT(!res.Root); - UNIT_ASSERT_NO_DIFF(Err2Str(res), "
:1:1: Error: Unable to GROUP BY more than 32 groups, you try use 80 groups\n"); + UNIT_ASSERT_NO_DIFF(Err2Str(res), "
:1:1: Error: Unable to GROUP BY more than 64 groups, you try use 80 groups\n"); } Y_UNIT_TEST(GroupByFewBigCubesWithPragmaLimit) { diff --git a/ydb/library/yql/sql/v1/context.h b/ydb/library/yql/sql/v1/context.h index 26a09ed5dbfc..3afa2f1bebfe 100644 --- a/ydb/library/yql/sql/v1/context.h +++ b/ydb/library/yql/sql/v1/context.h @@ -281,7 +281,7 @@ namespace NSQLTranslationV1 { bool WarnOnAnsiAliasShadowing = true; ui32 ResultRowsLimit = 0; ui64 ResultSizeLimit = 0; - ui32 PragmaGroupByLimit = 1 << 5; + ui32 PragmaGroupByLimit = 1 << 6; ui32 PragmaGroupByCubeLimit = 5; // if FlexibleTypes=true, emit TypeOrMember callable and resolve Type/Column uncertainty on type annotation stage, otherwise always emit Type bool FlexibleTypes = false; diff --git a/ydb/library/yql/sql/v1/sql_ut.cpp b/ydb/library/yql/sql/v1/sql_ut.cpp index d640235bf2ed..9d3ecbf6aa62 100644 --- a/ydb/library/yql/sql/v1/sql_ut.cpp +++ b/ydb/library/yql/sql/v1/sql_ut.cpp @@ -3428,7 +3428,7 @@ Y_UNIT_TEST_SUITE(SqlToYQLErrors) { Y_UNIT_TEST(GroupByFewBigCubes) { NYql::TAstParseResult res = SqlToYql("SELECT key FROM plato.Input GROUP BY CUBE(key, subkey, key + subkey as sum), CUBE(value, value + key + subkey as total);"); UNIT_ASSERT(!res.Root); - UNIT_ASSERT_NO_DIFF(Err2Str(res), "
:1:1: Error: Unable to GROUP BY more than 32 groups, you try use 80 groups\n"); + UNIT_ASSERT_NO_DIFF(Err2Str(res), "
:1:1: Error: Unable to GROUP BY more than 64 groups, you try use 80 groups\n"); } Y_UNIT_TEST(GroupByFewBigCubesWithPragmaLimit) {