aboutsummaryrefslogtreecommitdiffstats
path: root/yql
diff options
context:
space:
mode:
authoraneporada <aneporada@yandex-team.com>2024-11-12 21:55:29 +0300
committeraneporada <aneporada@yandex-team.com>2024-11-12 22:09:36 +0300
commit69da9e3488a1cfc2ae8b472f64858770c23264aa (patch)
treede09336329d3a5a1d9fc0f7b99fee4a984758dc5 /yql
parent1ed1edde33071bf0e3a542053192705592144393 (diff)
downloadydb-69da9e3488a1cfc2ae8b472f64858770c23264aa.tar.gz
Merge PR #10944: Fix ExtractMembers constraints for sorted tuple
commit_hash:3cbeb92e6a5008fdda11519d1b9fa5381af3a61f
Diffstat (limited to 'yql')
-rw-r--r--yql/essentials/core/ut/yql_expr_constraint_ut.cpp22
-rw-r--r--yql/essentials/core/yql_expr_constraint.cpp10
2 files changed, 27 insertions, 5 deletions
diff --git a/yql/essentials/core/ut/yql_expr_constraint_ut.cpp b/yql/essentials/core/ut/yql_expr_constraint_ut.cpp
index 9b679ae50f..e860d506c5 100644
--- a/yql/essentials/core/ut/yql_expr_constraint_ut.cpp
+++ b/yql/essentials/core/ut/yql_expr_constraint_ut.cpp
@@ -441,6 +441,28 @@ Y_UNIT_TEST_SUITE(TYqlExprConstraints) {
CheckConstraint<TSortedConstraintNode>(exprRoot, "LazyList", "Sorted(x[asc];z[asc])");
}
+ Y_UNIT_TEST(ExtractSortedTuple) {
+ const auto s = R"((
+ (let mr_sink (DataSink 'yt (quote plato)))
+ (let list (AsList
+ (AsStruct '('a (String '4)) '('b (String 'c)) '('c (String 'x)))
+ (AsStruct '('a (String '1)) '('b (String 'd)) '('c (String 'y)))
+ (AsStruct '('a (String '3)) '('b (String 'b)) '('c (String 'z)))
+ ))
+ (let sorted (Sort list '((Bool 'True) (Bool 'True)) (lambda '(item) '((Member item 'a) (Member item 'b)))))
+ (let map (OrderedFlatMap sorted (lambda '(item) (OptionalIf (== (Member item 'a) (String '1)) (AddMember item 'x '((Member item 'a) (Member item 'b)))))))
+ (let extract (ExtractMembers map '('x)))
+ (let world (Write! world mr_sink (Key '('table (String 'Output))) extract '('('mode 'renew))))
+ (let world (Commit! world mr_sink))
+ (return world)
+ ))";
+
+ TExprContext exprCtx;
+ const auto exprRoot = ParseAndAnnotate(s, exprCtx);
+ CheckConstraint<TSortedConstraintNode>(exprRoot, "OrderedFlatMap", "Sorted(a,x/0[asc];b,x/1[asc])");
+ CheckConstraint<TSortedConstraintNode>(exprRoot, "ExtractMembers", "Sorted(x[asc])");
+ }
+
Y_UNIT_TEST(TopSort) {
const auto s = R"((
(let mr_sink (DataSink 'yt (quote plato)))
diff --git a/yql/essentials/core/yql_expr_constraint.cpp b/yql/essentials/core/yql_expr_constraint.cpp
index 9cb20a8f7e..aa57aecb71 100644
--- a/yql/essentials/core/yql_expr_constraint.cpp
+++ b/yql/essentials/core/yql_expr_constraint.cpp
@@ -688,10 +688,10 @@ private:
TStatus ExtractMembersWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const {
const auto outItemType = GetSeqItemType(*input->GetTypeAnn()).Cast<TStructExprType>();
const auto filter = [outItemType](const TPartOfConstraintBase::TPathType& path) { return !path.empty() && outItemType->FindItem(path.front()); };
- FilterFromHead<TSortedConstraintNode>(input, filter, ctx);
- FilterFromHead<TChoppedConstraintNode>(input, filter, ctx);
- FilterFromHead<TUniqueConstraintNode>(input, filter, ctx);
- FilterFromHead<TDistinctConstraintNode>(input, filter, ctx);
+ FilterFromHead<TSortedConstraintNode, true>(input, filter, ctx);
+ FilterFromHead<TChoppedConstraintNode, true>(input, filter, ctx);
+ FilterFromHead<TUniqueConstraintNode, true>(input, filter, ctx);
+ FilterFromHead<TDistinctConstraintNode, true>(input, filter, ctx);
FilterFromHead<TPartOfSortedConstraintNode>(input, filter, ctx);
FilterFromHead<TPartOfChoppedConstraintNode>(input, filter, ctx);
FilterFromHead<TPartOfUniqueConstraintNode>(input, filter, ctx);
@@ -2943,7 +2943,7 @@ private:
input->AddConstraint(ctx.MakeConstraint<TUniqueConstraintNode>(columns));
input->AddConstraint(ctx.MakeConstraint<TDistinctConstraintNode>(columns));
}
-
+
return TStatus::Ok;
}