Skip to content

Commit 5c84ffa

Browse files
committed
YQL-19974 fixed handling error type in UnionAll
commit_hash:9aaecf82f8c99c7576eedbfc43572a8722ea774d
1 parent 0828b5c commit 5c84ffa

File tree

5 files changed

+51
-3
lines changed

5 files changed

+51
-3
lines changed

yql/essentials/core/type_ann/type_ann_list.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2793,15 +2793,17 @@ namespace {
27932793
const auto structType = itemType->Cast<TStructExprType>();
27942794
for (const auto& item: structType->GetItems()) {
27952795
if (const auto res = members.insert({ item->GetName(), { item->GetItemType(), 1U } }); !res.second) {
2796-
if (item->GetItemType()->GetKind() == ETypeAnnotationKind::Error) {
2796+
auto& p = res.first->second;
2797+
if (p.first->GetKind() == ETypeAnnotationKind::Error) {
27972798
continue;
27982799
}
27992800

2800-
auto& p = res.first->second;
2801-
if (p.first->GetKind() == ETypeAnnotationKind::Error) {
2801+
if (item->GetItemType()->GetKind() == ETypeAnnotationKind::Error) {
2802+
p.first = item->GetItemType();
28022803
continue;
28032804
}
28042805

2806+
28052807
if (const auto commonType = CommonType<false, true>(input.Pos(), p.first, item->GetItemType(), ctx.Expr)) {
28062808
p.first = commonType;
28072809
++p.second;

yql/essentials/tests/sql/minirun/part1/canondata/result.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,20 @@
13421342
"uri": "https://{canondata_backend}/995452/57f8b127ed5fa9fae2dd5ebb0f5870d86a7fcd2f/resource.tar.gz#test.test_udf-trivial_udf--Results_/results.txt"
13431343
}
13441344
],
1345+
"test.test[union_all-error_second_field-default.txt-Debug]": [
1346+
{
1347+
"checksum": "0e23b9479096e1474819855af204990f",
1348+
"size": 321,
1349+
"uri": "https://{canondata_backend}/1784117/c1c7de2cd671e324140e51d7eda942f845f3a5be/resource.tar.gz#test.test_union_all-error_second_field-default.txt-Debug_/opt.yql"
1350+
}
1351+
],
1352+
"test.test[union_all-error_second_field-default.txt-Results]": [
1353+
{
1354+
"checksum": "e6fa6c1cd5fcb0365c8d37188d57098a",
1355+
"size": 762,
1356+
"uri": "https://{canondata_backend}/1784117/c1c7de2cd671e324140e51d7eda942f845f3a5be/resource.tar.gz#test.test_union_all-error_second_field-default.txt-Results_/results.txt"
1357+
}
1358+
],
13451359
"test.test[window-null_type-default.txt-Debug]": [
13461360
{
13471361
"checksum": "a9dd7e899e45fb72b95d82be22e38ede",

yql/essentials/tests/sql/sql2yql/canondata/result.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7307,6 +7307,13 @@
73077307
"uri": "https://{canondata_backend}/1942173/99e88108149e222741552e7e6cddef041d6a2846/resource.tar.gz#test_sql2yql.test_union-union_positional_mix_/sql.yql"
73087308
}
73097309
],
7310+
"test_sql2yql.test[union_all-error_second_field]": [
7311+
{
7312+
"checksum": "ee8f002843aa9d876e3e84729b0332b0",
7313+
"size": 2331,
7314+
"uri": "https://{canondata_backend}/1784117/c3b861ffaf877046c3bd4b07e953f45f2a989267/resource.tar.gz#test_sql2yql.test_union_all-error_second_field_/sql.yql"
7315+
}
7316+
],
73107317
"test_sql2yql.test[union_all-union_all_incompatible]": [
73117318
{
73127319
"checksum": "0d3672847d7b84c142611d095eb38cc2",
@@ -11261,6 +11268,11 @@
1126111268
"uri": "file://test_sql_format.test_union-union_positional_mix_/formatted.sql"
1126211269
}
1126311270
],
11271+
"test_sql_format.test[union_all-error_second_field]": [
11272+
{
11273+
"uri": "file://test_sql_format.test_union_all-error_second_field_/formatted.sql"
11274+
}
11275+
],
1126411276
"test_sql_format.test[union_all-union_all_incompatible]": [
1126511277
{
1126611278
"uri": "file://test_sql_format.test_union_all-union_all_incompatible_/formatted.sql"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PRAGMA warning('disable', '4510');
2+
3+
SELECT
4+
y
5+
FROM (
6+
SELECT
7+
0 AS y,
8+
1 AS x
9+
UNION ALL
10+
SELECT
11+
1 AS y,
12+
Yql::Error(Yql::ErrorType(AsAtom('1'), AsAtom('2'), AsAtom(''), AsAtom('foo'))) AS x
13+
);
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
pragma warning("disable","4510");
2+
select y from (
3+
select 0 as y, 1 as x
4+
union all
5+
select 1 as y, Yql::Error(Yql::ErrorType(AsAtom('1'),AsAtom('2'),AsAtom(''),AsAtom('foo'))) as x
6+
)
7+

0 commit comments

Comments
 (0)