Skip to content

Commit 3ecb4ff

Browse files
authored
YQL: Fix crash in lineage (#8070)
1 parent 56dc3b5 commit 3ecb4ff

File tree

9 files changed

+115
-14
lines changed

9 files changed

+115
-14
lines changed

ydb/library/yql/core/services/yql_lineage.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -651,28 +651,30 @@ class TLineageScanner {
651651
auto& res = (*lineage.Fields)[x.first];
652652
TMaybe<bool> hasStructItems;
653653
for (const auto& i : inners) {
654-
auto f = (*i.Fields).FindPtr(x.first);
655-
for (const auto& x : f->Items) {
656-
res.Items.insert(x);
657-
}
654+
if (auto f = (*i.Fields).FindPtr(x.first)) {
655+
for (const auto& x : f->Items) {
656+
res.Items.insert(x);
657+
}
658658

659-
if (f->StructItems || f->Items.empty()) {
660-
if (!hasStructItems) {
661-
hasStructItems = true;
659+
if (f->StructItems || f->Items.empty()) {
660+
if (!hasStructItems) {
661+
hasStructItems = true;
662+
}
663+
} else {
664+
hasStructItems = false;
662665
}
663-
} else {
664-
hasStructItems = false;
665666
}
666667
}
667668

668669
if (hasStructItems && *hasStructItems) {
669670
res.StructItems.ConstructInPlace();
670671
for (const auto& i : inners) {
671-
auto f = (*i.Fields).FindPtr(x.first);
672-
if (f->StructItems) {
673-
for (const auto& si : *f->StructItems) {
674-
for (const auto& x : si.second) {
675-
(*res.StructItems)[si.first].insert(x);
672+
if (auto f = (*i.Fields).FindPtr(x.first)) {
673+
if (f->StructItems) {
674+
for (const auto& si : *f->StructItems) {
675+
for (const auto& x : si.second) {
676+
(*res.StructItems)[si.first].insert(x);
677+
}
676678
}
677679
}
678680
}

ydb/library/yql/tests/sql/dq_file/part15/canondata/result.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1564,6 +1564,28 @@
15641564
}
15651565
],
15661566
"test.test[limit-limit_over_sort_desc_in_subquery--Results]": [],
1567+
"test.test[lineage-grouping_sets--Analyze]": [
1568+
{
1569+
"checksum": "ee99aa53db458c422309608d038b21b2",
1570+
"size": 8305,
1571+
"uri": "https://{canondata_backend}/1130705/0ef38e114204c1ac6d0d5ad14792a285fb1413c8/resource.tar.gz#test.test_lineage-grouping_sets--Analyze_/plan.txt"
1572+
}
1573+
],
1574+
"test.test[lineage-grouping_sets--Debug]": [
1575+
{
1576+
"checksum": "e8e65c2d3c076aec649b104e3ecfe944",
1577+
"size": 4039,
1578+
"uri": "https://{canondata_backend}/1130705/0ef38e114204c1ac6d0d5ad14792a285fb1413c8/resource.tar.gz#test.test_lineage-grouping_sets--Debug_/opt.yql_patched"
1579+
}
1580+
],
1581+
"test.test[lineage-grouping_sets--Plan]": [
1582+
{
1583+
"checksum": "ee99aa53db458c422309608d038b21b2",
1584+
"size": 8305,
1585+
"uri": "https://{canondata_backend}/1130705/0ef38e114204c1ac6d0d5ad14792a285fb1413c8/resource.tar.gz#test.test_lineage-grouping_sets--Plan_/plan.txt"
1586+
}
1587+
],
1588+
"test.test[lineage-grouping_sets--Results]": [],
15671589
"test.test[optimizers-aggregate_over_aggregate--Analyze]": [
15681590
{
15691591
"checksum": "3446b4cc5f51a2503e749ebbd8230bfd",

ydb/library/yql/tests/sql/hybrid_file/part0/canondata/result.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1651,6 +1651,20 @@
16511651
"uri": "https://{canondata_backend}/1924537/7199a3a7eba1a101a7ecd6552b3df25cb9a6ef2b/resource.tar.gz#test.test_limit-empty_read_after_limit-default.txt-Plan_/plan.txt"
16521652
}
16531653
],
1654+
"test.test[lineage-grouping_sets--Debug]": [
1655+
{
1656+
"checksum": "fa1003bed584f483404d70a523c1f9b9",
1657+
"size": 8168,
1658+
"uri": "https://{canondata_backend}/1942671/a089042abddfd51839b75278c8f86236a82e2fbd/resource.tar.gz#test.test_lineage-grouping_sets--Debug_/opt.yql_patched"
1659+
}
1660+
],
1661+
"test.test[lineage-grouping_sets--Plan]": [
1662+
{
1663+
"checksum": "0af9a91ec025f87c1ec526f00c82a8ce",
1664+
"size": 14693,
1665+
"uri": "https://{canondata_backend}/1942671/a089042abddfd51839b75278c8f86236a82e2fbd/resource.tar.gz#test.test_lineage-grouping_sets--Plan_/plan.txt"
1666+
}
1667+
],
16541668
"test.test[match_recognize-alerts-default.txt-Debug]": [
16551669
{
16561670
"checksum": "902f8b167c5875200480d237a6493bb7",

ydb/library/yql/tests/sql/sql2yql/canondata/result.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10590,6 +10590,13 @@
1059010590
"uri": "https://{canondata_backend}/1871002/ba7501739621731b8f5b85f57d8e4868dadf87e3/resource.tar.gz#test_sql2yql.test_lineage-group_by_asstruct_key_/sql.yql"
1059110591
}
1059210592
],
10593+
"test_sql2yql.test[lineage-grouping_sets]": [
10594+
{
10595+
"checksum": "bc9f636e423a6c856a4ff05a6b5c3a82",
10596+
"size": 3196,
10597+
"uri": "https://{canondata_backend}/1781765/5483cde59b65341125b67709093030a3d2bd1b0e/resource.tar.gz#test_sql2yql.test_lineage-grouping_sets_/sql.yql"
10598+
}
10599+
],
1059310600
"test_sql2yql.test[lineage-if_struct]": [
1059410601
{
1059510602
"checksum": "aafa05e38853f6b86488a387b26f7ec0",
@@ -30148,6 +30155,13 @@
3014830155
"uri": "https://{canondata_backend}/1880306/64654158d6bfb1289c66c626a8162239289559d0/resource.tar.gz#test_sql_format.test_lineage-group_by_asstruct_key_/formatted.sql"
3014930156
}
3015030157
],
30158+
"test_sql_format.test[lineage-grouping_sets]": [
30159+
{
30160+
"checksum": "7e57dcc9ca531cfa66e69bd7f1460ad2",
30161+
"size": 296,
30162+
"uri": "https://{canondata_backend}/1781765/5483cde59b65341125b67709093030a3d2bd1b0e/resource.tar.gz#test_sql_format.test_lineage-grouping_sets_/formatted.sql"
30163+
}
30164+
],
3015130165
"test_sql_format.test[lineage-if_struct]": [
3015230166
{
3015330167
"checksum": "36232c04d90172af80321e69783af38f",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
in Input input_optional.txt
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
USE plato;
2+
3+
$data = select
4+
key, subkey, value
5+
from Input
6+
group by GROUPING SETS (
7+
(key, subkey),
8+
(subkey, value)
9+
);
10+
11+
INSERT INTO @tmp WITH TRUNCATE
12+
SELECT
13+
b.value
14+
FROM $data AS a
15+
LEFT JOIN Input AS b
16+
USING (key)
17+
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{"key"="075";"subkey"="1";"value"=1};
2+
{"key"="800";"subkey"="2";"value"=2};
3+
{"key"="020";"subkey"="3";"value"=3};
4+
{"key"="150";"subkey"="4";"value"=4};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"_yql_row_spec"={
3+
"Type"=["StructType";[["key";["OptionalType";["DataType";"String"]]];["subkey";["OptionalType";["DataType";"String"]]];["value";["OptionalType";["DataType";"Int64"];];];];];
4+
}
5+
}

ydb/library/yql/tests/sql/yt_native_file/part15/canondata/result.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,28 @@
14321432
"uri": "https://{canondata_backend}/1903280/4c77300cd3fef018d27d7f75b6ff956e63258b21/resource.tar.gz#test.test_limit-limit_over_sort_desc_in_subquery--Results_/results.txt"
14331433
}
14341434
],
1435+
"test.test[lineage-grouping_sets--Debug]": [
1436+
{
1437+
"checksum": "9d2798e2536159bea2cb8dc1a8089078",
1438+
"size": 7296,
1439+
"uri": "https://{canondata_backend}/1775319/aecc6e3ae91d93c26e7063f6d946a08835835da0/resource.tar.gz#test.test_lineage-grouping_sets--Debug_/opt.yql"
1440+
}
1441+
],
1442+
"test.test[lineage-grouping_sets--Lineage]": [
1443+
{
1444+
"checksum": "4e5a26084952308cda7be7008d40b234",
1445+
"size": 1120,
1446+
"uri": "https://{canondata_backend}/1775319/aecc6e3ae91d93c26e7063f6d946a08835835da0/resource.tar.gz#test.test_lineage-grouping_sets--Lineage_/results.txt"
1447+
}
1448+
],
1449+
"test.test[lineage-grouping_sets--Plan]": [
1450+
{
1451+
"checksum": "9027e176da83bb029fbe250f66b43333",
1452+
"size": 13407,
1453+
"uri": "https://{canondata_backend}/1775319/aecc6e3ae91d93c26e7063f6d946a08835835da0/resource.tar.gz#test.test_lineage-grouping_sets--Plan_/plan.txt"
1454+
}
1455+
],
1456+
"test.test[lineage-grouping_sets--Results]": [],
14351457
"test.test[lineage-union_all_tablerow-default.txt-Debug]": [
14361458
{
14371459
"checksum": "2714ab7621308c8eb706e51f237548dd",

0 commit comments

Comments
 (0)