aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraneporada <aneporada@yandex-team.ru>2022-02-18 11:15:12 +0300
committeraneporada <aneporada@yandex-team.ru>2022-02-18 11:15:12 +0300
commit15fad050aa910af2ecc47bdf779222886eb0d29e (patch)
treef4c83334e803aa59231263cf08b162a70787a406
parent523174fbd5a4be63d8b01076b7faa6a104110198 (diff)
downloadydb-15fad050aa910af2ecc47bdf779222886eb0d29e.tar.gz
[YQL-14412] Fix MaxRanges handling in presence of duplicates
ref:0cb4da66fd8f0cd75c6f74590887421b24279482
-rw-r--r--ydb/library/yql/core/extract_predicate/extract_predicate_impl.cpp63
1 files changed, 35 insertions, 28 deletions
diff --git a/ydb/library/yql/core/extract_predicate/extract_predicate_impl.cpp b/ydb/library/yql/core/extract_predicate/extract_predicate_impl.cpp
index e2c16395b7..ffa37ea263 100644
--- a/ydb/library/yql/core/extract_predicate/extract_predicate_impl.cpp
+++ b/ydb/library/yql/core/extract_predicate/extract_predicate_impl.cpp
@@ -759,6 +759,30 @@ TCoLambda OptimizeLambdaForRangeExtraction(const TExprNode::TPtr& filterLambdaNo
return TCoLambda(output);
}
+TExprNode::TPtr BuildFullRange(TPositionHandle pos, const TStructExprType& rowType, const TVector<TString>& indexKeys, TExprContext& ctx) {
+ YQL_ENSURE(!indexKeys.empty());
+ TExprNodeList components;
+ for (auto key : indexKeys) {
+ auto idx = rowType.FindItem(key);
+ YQL_ENSURE(idx);
+ const TTypeAnnotationNode* optKeyType = ctx.MakeType<TOptionalExprType>(rowType.GetItems()[*idx]->GetItemType());
+ auto nullNode = ctx.NewCallable(pos, "Nothing", { ExpandType(pos, *optKeyType, ctx) });
+
+ components.push_back(nullNode);
+ }
+
+ components.push_back(ctx.NewCallable(pos, "Int32", { ctx.NewAtom(pos, "0", TNodeFlags::Default) }));
+ auto boundary = ctx.NewList(pos, std::move(components));
+ return ctx.Builder(pos)
+ .Callable("AsRange")
+ .List(0)
+ .Add(0, boundary)
+ .Add(1, boundary)
+ .Seal()
+ .Seal()
+ .Build();
+}
+
TExprNode::TPtr BuildSingleComputeRange(const TStructExprType& rowType,
const TExprNode& range, const THashMap<TString, size_t>& indexKeysOrder,
const TPredicateExtractorSettings& settings, const TString& lastKey, TExprContext& ctx)
@@ -922,13 +946,20 @@ TExprNode::TPtr BuildSingleComputeRange(const TStructExprType& rowType,
.Seal()
.Seal()
.Build();
+ body = ctx.NewCallable(pos, "Collect", { body });
body = ctx.Builder(pos)
- .Callable("RangeUnion")
- .Callable(0, "RangeMultiply")
- .Callable(0, "Uint64")
+ .Callable("IfStrict")
+ .Callable(0, ">")
+ .Callable(0, "Length")
+ .Add(0, body)
+ .Seal()
+ .Callable(1, "Uint64")
.Atom(0, ToString(settings.MaxRanges), TNodeFlags::Default)
.Seal()
- .Add(1, body)
+ .Seal()
+ .Add(1, BuildFullRange(pos, rowType, keys, ctx))
+ .Callable(2, "RangeUnion")
+ .Add(0, body)
.Seal()
.Seal()
.Build();
@@ -966,30 +997,6 @@ TExprNode::TPtr BuildSingleComputeRange(const TStructExprType& rowType,
.Build();
}
-TExprNode::TPtr BuildFullRange(TPositionHandle pos, const TStructExprType& rowType, const TVector<TString>& indexKeys, TExprContext& ctx) {
- YQL_ENSURE(!indexKeys.empty());
- TExprNodeList components;
- for (auto key : indexKeys) {
- auto idx = rowType.FindItem(key);
- YQL_ENSURE(idx);
- const TTypeAnnotationNode* optKeyType = ctx.MakeType<TOptionalExprType>(rowType.GetItems()[*idx]->GetItemType());
- auto nullNode = ctx.NewCallable(pos, "Nothing", { ExpandType(pos, *optKeyType, ctx) });
-
- components.push_back(nullNode);
- }
-
- components.push_back(ctx.NewCallable(pos, "Int32", { ctx.NewAtom(pos, "0", TNodeFlags::Default) }));
- auto boundary = ctx.NewList(pos, std::move(components));
- return ctx.Builder(pos)
- .Callable("AsRange")
- .List(0)
- .Add(0, boundary)
- .Add(1, boundary)
- .Seal()
- .Seal()
- .Build();
-}
-
TExprNode::TPtr RebuildAsRangeRest(const TStructExprType& rowType, const TExprNode& range, TExprContext& ctx) {
if (range.IsCallable({"RangeRest", "Range"})) {
return ctx.RenameNode(range, "RangeRest");