diff options
| author | vvvv <[email protected]> | 2025-04-11 12:43:25 +0300 |
|---|---|---|
| committer | vvvv <[email protected]> | 2025-04-11 13:06:45 +0300 |
| commit | 2d1a7b6b3b9b3e7e70aace2c33caf5cb965e9c66 (patch) | |
| tree | f71d55ff17394e613a7c2bbd16784ca73cd6d9b1 | |
| parent | 60f4418667ea2f14124a22f7e4d9d5bcf5eabce4 (diff) | |
YQL-19808 Union typecheck fixed
commit_hash:ae4906152eff58ea40b78325ebbfe04c5685e991
5 files changed, 36 insertions, 0 deletions
diff --git a/yql/essentials/core/type_ann/type_ann_list.cpp b/yql/essentials/core/type_ann/type_ann_list.cpp index 8601c606501..e7f6c81ba6d 100644 --- a/yql/essentials/core/type_ann/type_ann_list.cpp +++ b/yql/essentials/core/type_ann/type_ann_list.cpp @@ -2760,6 +2760,7 @@ namespace { } IGraphTransformer::TStatus UnionAllWrapper(const TExprNode::TPtr& input, TExprNode::TPtr& output, TContext& ctx) { + const bool checkHashes = input->IsCallable("Union"); switch (input->ChildrenSize()) { case 0U: output = ctx.Expr.NewCallable(input->Pos(), "EmptyList", {}); @@ -2857,6 +2858,16 @@ namespace { addResultItems(structType); } + if (checkHashes) { + for (const auto& r : resultItems) { + if (!r->GetItemType()->IsHashable() || !r->GetItemType()->IsEquatable()) { + ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Pos()), TStringBuilder() << "Expected hashable and equatable type for column: " << + r->GetName() << ", but got: " << *r->GetItemType())); + return IGraphTransformer::TStatus::Error; + } + } + } + auto structType = ctx.Expr.MakeType<TStructExprType>(resultItems); if (!structType->Validate(input->Pos(), ctx.Expr)) { return IGraphTransformer::TStatus::Error; diff --git a/yql/essentials/tests/sql/sql2yql/canondata/result.json b/yql/essentials/tests/sql/sql2yql/canondata/result.json index af6432ae7a2..4cb7e6cc7af 100644 --- a/yql/essentials/tests/sql/sql2yql/canondata/result.json +++ b/yql/essentials/tests/sql/sql2yql/canondata/result.json @@ -7209,6 +7209,13 @@ "uri": "https://{canondata_backend}/1775319/f1fa0c55bf9f13cff57cf1c990c2330caed8eb1b/resource.tar.gz#test_sql2yql.test_udf-wrong_args_fail_/sql.yql" } ], + "test_sql2yql.test[union-unhashed_column]": [ + { + "checksum": "7518a24843443901f9727c734bb16e91", + "size": 1407, + "uri": "https://{canondata_backend}/1936273/63195eda4f72befa869aaf8010fe57be8318f0a0/resource.tar.gz#test_sql2yql.test_union-unhashed_column_/sql.yql" + } + ], "test_sql2yql.test[union-union_column_extention]": [ { "checksum": "75294382d48ff3801b42ef1c8bb26dbd", @@ -11121,6 +11128,11 @@ "uri": "file://test_sql_format.test_udf-wrong_args_fail_/formatted.sql" } ], + "test_sql_format.test[union-unhashed_column]": [ + { + "uri": "file://test_sql_format.test_union-unhashed_column_/formatted.sql" + } + ], "test_sql_format.test[union-union_column_extention]": [ { "uri": "file://test_sql_format.test_union-union_column_extention_/formatted.sql" diff --git a/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_union-unhashed_column_/formatted.sql b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_union-unhashed_column_/formatted.sql new file mode 100644 index 00000000000..a900f6eb987 --- /dev/null +++ b/yql/essentials/tests/sql/sql2yql/canondata/test_sql_format.test_union-unhashed_column_/formatted.sql @@ -0,0 +1,7 @@ +/* custom error: Expected hashable and equatable type for column: x, but got: Yson */ +SELECT + "1"y AS x +UNION +SELECT + "2"y AS x +; diff --git a/yql/essentials/tests/sql/suites/union/unhashed_column.cfg b/yql/essentials/tests/sql/suites/union/unhashed_column.cfg new file mode 100644 index 00000000000..5dae597903c --- /dev/null +++ b/yql/essentials/tests/sql/suites/union/unhashed_column.cfg @@ -0,0 +1 @@ +xfail diff --git a/yql/essentials/tests/sql/suites/union/unhashed_column.sql b/yql/essentials/tests/sql/suites/union/unhashed_column.sql new file mode 100644 index 00000000000..400e8ac84cf --- /dev/null +++ b/yql/essentials/tests/sql/suites/union/unhashed_column.sql @@ -0,0 +1,5 @@ +/* custom error: Expected hashable and equatable type for column: x, but got: Yson */ +select "1"y as x +union +select "2"y as x + |
