aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorudovichenko-r <udovichenko-r@yandex-team.com>2025-04-15 17:28:58 +0300
committerudovichenko-r <udovichenko-r@yandex-team.com>2025-04-15 17:45:25 +0300
commit218ec6a31e4d1f39811692f17f54a77a5755ee4c (patch)
tree88ee82921c61e9cc2a15d0e4d0040b446113715e
parenta004c2e3c2279e8f31e98d74ed3b7773a34a9557 (diff)
downloadydb-218ec6a31e4d1f39811692f17f54a77a5755ee4c.tar.gz
Check missing fields in Cast constraints calculation
commit_hash:80d14b9a81504ea3fcb8d6fa89a2472f700c0f0e
-rw-r--r--yql/essentials/core/ut/yql_expr_constraint_ut.cpp22
-rw-r--r--yql/essentials/core/yql_expr_constraint.cpp12
2 files changed, 31 insertions, 3 deletions
diff --git a/yql/essentials/core/ut/yql_expr_constraint_ut.cpp b/yql/essentials/core/ut/yql_expr_constraint_ut.cpp
index 45d9f6285de..a4145b9c5a8 100644
--- a/yql/essentials/core/ut/yql_expr_constraint_ut.cpp
+++ b/yql/essentials/core/ut/yql_expr_constraint_ut.cpp
@@ -1124,6 +1124,28 @@ Y_UNIT_TEST_SUITE(TYqlExprConstraints) {
CheckConstraint<TUniqueConstraintNode>(exprRoot, "LazyList", "Unique((one,{two,xxx},yyy))");
}
+ Y_UNIT_TEST(UniqueNarrowCast) {
+ const auto s = R"((
+ (let res (DataSink 'result))
+ (let list (AsList
+ (AsStruct '('key (String '4)) '('subkey (String 'c)) '('value (String 'x)))
+ (AsStruct '('key (String '1)) '('subkey (String 'b)) '('value (String 'y)))
+ (AsStruct '('key (String '4)) '('subkey (String 'b)) '('value (String 'z)))
+ ))
+ (let list (AssumeUnique list '('key 'subkey)))
+ (let list (Map list (lambda '(item)
+ (SafeCast item (StructType '('key (DataType 'String)) '('value (DataType 'String))))
+ )))
+ (let world (Write! world res (Key) list '()))
+ (let world (Commit! world res))
+ (return world)
+ ))";
+
+ TExprContext exprCtx;
+ const auto exprRoot = ParseAndAnnotate(s, exprCtx);
+ CheckConstraint<TUniqueConstraintNode>(exprRoot, "Map", "");
+ }
+
Y_UNIT_TEST(Distinct) {
const auto s = R"((
(let res (DataSink 'result))
diff --git a/yql/essentials/core/yql_expr_constraint.cpp b/yql/essentials/core/yql_expr_constraint.cpp
index fdfc21946be..e67557d9645 100644
--- a/yql/essentials/core/yql_expr_constraint.cpp
+++ b/yql/essentials/core/yql_expr_constraint.cpp
@@ -665,12 +665,18 @@ private:
};
const auto filterForUnique = [inItemType, outItemType](const TPartOfConstraintBase::TPathType& path) {
- const auto castResult = CastResult<Strict>(TPartOfConstraintBase::GetSubTypeByPath(path, *inItemType), TPartOfConstraintBase::GetSubTypeByPath(path, *outItemType));
- return NUdf::ECastOptions::Complete == castResult || NUdf::ECastOptions::MayFail == castResult;
+ if (const auto outType = TPartOfConstraintBase::GetSubTypeByPath(path, *outItemType)) {
+ const auto castResult = CastResult<Strict>(TPartOfConstraintBase::GetSubTypeByPath(path, *inItemType), outType);
+ return NUdf::ECastOptions::Complete == castResult || NUdf::ECastOptions::MayFail == castResult;
+ }
+ return false;
};
const auto filterForDistinct = [inItemType, outItemType](const TPartOfConstraintBase::TPathType& path) {
- return NUdf::ECastOptions::Complete == CastResult<Strict>(TPartOfConstraintBase::GetSubTypeByPath(path, *inItemType), TPartOfConstraintBase::GetSubTypeByPath(path, *outItemType));
+ if (const auto outType = TPartOfConstraintBase::GetSubTypeByPath(path, *outItemType)) {
+ return NUdf::ECastOptions::Complete == CastResult<Strict>(TPartOfConstraintBase::GetSubTypeByPath(path, *inItemType), outType);
+ }
+ return false;
};
FilterFromHead<TSortedConstraintNode>(input, filter, ctx);