diff options
author | aidarsamer <aidarsamer@ydb.tech> | 2022-11-25 14:10:00 +0300 |
---|---|---|
committer | aidarsamer <aidarsamer@ydb.tech> | 2022-11-25 14:10:00 +0300 |
commit | dcb3b598eb86254b71ba0570d645ddd2310d1922 (patch) | |
tree | 7229b1c1c69752e604434faff081e96add445d44 | |
parent | 5d91a6b12a8b3391f1465f7421529958f0d01f9b (diff) | |
download | ydb-dcb3b598eb86254b71ba0570d645ddd2310d1922.tar.gz |
Add min/max aggregate pushdown to column shard
Add min/max aggregate pushdown to column shard
-rw-r--r-- | ydb/core/kqp/host/kqp_type_ann.cpp | 3 | ||||
-rw-r--r-- | ydb/core/kqp/opt/physical/kqp_opt_phy_olap_agg.cpp | 4 | ||||
-rw-r--r-- | ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp | 2 | ||||
-rw-r--r-- | ydb/core/kqp/ut/kqp_olap_ut.cpp | 56 |
4 files changed, 64 insertions, 1 deletions
diff --git a/ydb/core/kqp/host/kqp_type_ann.cpp b/ydb/core/kqp/host/kqp_type_ann.cpp index 6c8f2374957..2ef9fe597a1 100644 --- a/ydb/core/kqp/host/kqp_type_ann.cpp +++ b/ydb/core/kqp/host/kqp_type_ann.cpp @@ -924,6 +924,9 @@ TStatus AnnotateOlapAgg(const TExprNode::TPtr& node, TExprContext& ctx) { return TStatus::Error; } aggTypes.push_back(ctx.MakeType<TItemExprType>(aggName->Content(), resultType)); + } else if (opType->Content() == "min" || opType->Content() == "max") { + auto colType = structType->FindItemType(colName->Content()); + aggTypes.push_back(ctx.MakeType<TItemExprType>(aggName->Content(), colType)); } else { ctx.AddError(TIssue( ctx.GetPosition(node->Pos()), diff --git a/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_agg.cpp b/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_agg.cpp index 9e1f4fe418a..8c1c7d3330d 100644 --- a/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_agg.cpp +++ b/ydb/core/kqp/opt/physical/kqp_opt_phy_olap_agg.cpp @@ -41,7 +41,9 @@ bool CanBePushedDown(const TExprBase& trait, TExprContext& ctx) } auto aggApply = trait.Cast<TCoAggApply>(); auto aggName = aggApply.Name(); - if (aggName == "count" || aggName == "count_all" || aggName == "sum") { + if (aggName == "count" || aggName == "count_all" || aggName == "sum" + || aggName == "min" || aggName == "max") + { return true; } YQL_CLOG(DEBUG, ProviderKqp) << "Unsupported type of aggregation: " << aggName.StringValue(); diff --git a/ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp b/ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp index 4074ba6888e..bdbb5617b27 100644 --- a/ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp +++ b/ydb/core/kqp/query_compiler/kqp_olap_compiler.cpp @@ -105,6 +105,8 @@ std::unordered_map<std::string, EAggFunctionType> TKqpOlapCompileContext::AggFun { "count", TProgram::TAggregateAssignment::AGG_COUNT }, { "sum", TProgram::TAggregateAssignment::AGG_SUM }, { "some", TProgram::TAggregateAssignment::AGG_SOME }, + { "min", TProgram::TAggregateAssignment::AGG_MIN }, + { "max", TProgram::TAggregateAssignment::AGG_MAX }, }; TProgram::TAssignment* CompileCondition(const TExprBase& condition, TKqpOlapCompileContext& ctx); diff --git a/ydb/core/kqp/ut/kqp_olap_ut.cpp b/ydb/core/kqp/ut/kqp_olap_ut.cpp index 6b52ed7a6e6..023aba83412 100644 --- a/ydb/core/kqp/ut/kqp_olap_ut.cpp +++ b/ydb/core/kqp/ut/kqp_olap_ut.cpp @@ -1767,6 +1767,62 @@ Y_UNIT_TEST_SUITE(KqpOlap) { TestAggregations({ testCase }); } + Y_UNIT_TEST(Aggregation_MinL) { + TAggregationTestCase testCase; + testCase.SetQuery(R"( + SELECT + MIN(level) + FROM `/Root/olapStore/olapTable` + )") + .SetExpectedReply("[[[0]]]") + .AddExpectedPlanOptions("TKqpOlapAgg"); + + TestAggregations({ testCase }); + } + + Y_UNIT_TEST(Aggregation_MaxL) { + TAggregationTestCase testCase; + testCase.SetQuery(R"( + SELECT + MAX(level) + FROM `/Root/olapStore/olapTable` + )") + .SetExpectedReply("[[[4]]]") + .AddExpectedPlanOptions("TKqpOlapAgg"); + + TestAggregations({ testCase }); + } + + Y_UNIT_TEST(Aggregation_MinR_GroupL_OrderL) { + TAggregationTestCase testCase; + testCase.SetQuery(R"( + SELECT + level, MIN(resource_id) + FROM `/Root/olapStore/olapTable` + GROUP BY level + ORDER BY level + )") + .SetExpectedReply("[[[0];[\"10000\"]];[[1];[\"10001\"]];[[2];[\"10002\"]];[[3];[\"10003\"]];[[4];[\"10004\"]]]") + .AddExpectedPlanOptions("TKqpOlapAgg"); + + TestAggregations({ testCase }); + } + + Y_UNIT_TEST(Aggregation_MaxR_GroupL_OrderL) { + TAggregationTestCase testCase; + testCase.SetQuery(R"( + SELECT + level, MAX(resource_id) + FROM `/Root/olapStore/olapTable` + GROUP BY level + ORDER BY level + )") + .SetExpectedReply("[[[0];[\"40995\"]];[[1];[\"40996\"]];[[2];[\"40997\"]];[[3];[\"40998\"]];[[4];[\"40999\"]]]") + .AddExpectedPlanOptions("TKqpOlapAgg"); + + TestAggregations({ testCase }); + } + Y_UNIT_TEST(StatsSysView) { auto settings = TKikimrSettings() .SetWithSampleTables(false); |