@@ -1024,10 +1024,11 @@ namespace NTypeAnnImpl {
10241024 sourceNameNode = input->ChildPtr(2);
10251025 }
10261026
1027- if (!EnsureStructOrOptionalStructType(*rowNode, ctx.Expr)) {
1027+ bool isOptionalStruct = false;
1028+ const TStructExprType* structType = nullptr;
1029+ if (!EnsureStructOrOptionalStructType(*rowNode, isOptionalStruct, structType, ctx.Expr)) {
10281030 return IGraphTransformer::TStatus::Error;
10291031 }
1030- const TStructExprType* structType = RemoveAllOptionals(rowNode->GetTypeAnn())->Cast<TStructExprType>();
10311032
10321033 if (!EnsureAtom(*columnNameNode, ctx.Expr)) {
10331034 return IGraphTransformer::TStatus::Error;
@@ -1109,7 +1110,9 @@ namespace NTypeAnnImpl {
11091110 return IGraphTransformer::TStatus::Error;
11101111 }
11111112
1112- if (!EnsureStructOrOptionalStructType(input->Head(), ctx.Expr)) {
1113+ bool isOptional = false;
1114+ const TStructExprType* structType = nullptr;
1115+ if (!EnsureStructOrOptionalStructType(input->Head(), isOptional, structType, ctx.Expr)) {
11131116 return IGraphTransformer::TStatus::Error;
11141117 }
11151118
@@ -1123,15 +1126,12 @@ namespace NTypeAnnImpl {
11231126 return IGraphTransformer::TStatus::Error;
11241127 }
11251128
1126- bool isOptional = input->Head().GetTypeAnn()->GetKind() == ETypeAnnotationKind::Optional;
1127- const TStructExprType& structType = *RemoveAllOptionals(input->Head().GetTypeAnn())->Cast<TStructExprType>();
1128-
1129- auto pos = FindOrReportMissingMember(columnNameNode->Content(), input->Pos(), structType, ctx.Expr);
1129+ auto pos = FindOrReportMissingMember(columnNameNode->Content(), input->Pos(), *structType, ctx.Expr);
11301130 if (!pos) {
11311131 return IGraphTransformer::TStatus::Error;
11321132 }
11331133
1134- const TTypeAnnotationNode* resultType = structType. GetItems()[*pos]->GetItemType();
1134+ const TTypeAnnotationNode* resultType = structType-> GetItems()[*pos]->GetItemType();
11351135 if (isOptional && resultType->GetKind() != ETypeAnnotationKind::Optional && resultType->GetKind() != ETypeAnnotationKind::Null) {
11361136 resultType = ctx.Expr.MakeType<TOptionalExprType>(input->GetTypeAnn());
11371137 }
@@ -1150,7 +1150,9 @@ namespace NTypeAnnImpl {
11501150 return IGraphTransformer::TStatus::Repeat;
11511151 }
11521152
1153- if (!EnsureStructOrOptionalStructType(input->Head(), ctx.Expr)) {
1153+ const TStructExprType* structType = nullptr;
1154+ bool isStructOptional = false;
1155+ if (!EnsureStructOrOptionalStructType(input->Head(), isStructOptional, structType, ctx.Expr)) {
11541156 return IGraphTransformer::TStatus::Error;
11551157 }
11561158
@@ -1162,15 +1164,6 @@ namespace NTypeAnnImpl {
11621164 return IGraphTransformer::TStatus::Error;
11631165 }
11641166
1165- const TStructExprType* structType = nullptr;
1166- bool isStructOptional = false;
1167- if (input->Head().GetTypeAnn()->GetKind() == ETypeAnnotationKind::Optional) {
1168- isStructOptional = true;
1169- structType = input->Head().GetTypeAnn()->Cast<TOptionalExprType>()->GetItemType()->Cast<TStructExprType>();
1170- } else {
1171- structType = input->Head().GetTypeAnn()->Cast<TStructExprType>();
1172- }
1173-
11741167 auto otherType = input->Child(2)->GetTypeAnn();
11751168 const bool isOptional = otherType->IsOptionalOrNull();
11761169 auto memberName = input->Child(1)->Content();
@@ -1231,16 +1224,13 @@ namespace NTypeAnnImpl {
12311224 }
12321225
12331226 auto structObj = child->Child(1);
1234- if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
1227+ bool optional = false;
1228+ const TStructExprType* structType = nullptr;
1229+ if (!EnsureStructOrOptionalStructType(*structObj, optional, structType, ctx.Expr)) {
12351230 return IGraphTransformer::TStatus::Error;
12361231 }
12371232
1238- auto type = structObj->GetTypeAnn();
1239- const bool optional = type->GetKind() == ETypeAnnotationKind::Optional;
1240- if (optional) {
1241- type = type->Cast<TOptionalExprType>()->GetItemType();
1242- }
1243- for (auto& field: type->Cast<TStructExprType>()->GetItems()) {
1233+ for (auto& field: structType->GetItems()) {
12441234 auto itemType = field->GetItemType();
12451235 if (optional && !itemType->IsOptionalOrNull()) {
12461236 itemType = ctx.Expr.MakeType<TOptionalExprType>(itemType);
@@ -1351,7 +1341,9 @@ namespace NTypeAnnImpl {
13511341 }
13521342
13531343 auto structObj = input->Child(0);
1354- if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
1344+ bool optional = false;
1345+ const TStructExprType* structExprType = nullptr;
1346+ if (!EnsureStructOrOptionalStructType(*structObj, optional, structExprType, ctx.Expr)) {
13551347 return IGraphTransformer::TStatus::Error;
13561348 }
13571349
@@ -1360,13 +1352,7 @@ namespace NTypeAnnImpl {
13601352 return status;
13611353 }
13621354
1363- auto type = structObj->GetTypeAnn();
1364- const bool optional = type->GetKind() == ETypeAnnotationKind::Optional;
1365- if (optional) {
1366- type = type->Cast<TOptionalExprType>()->GetItemType();
1367- }
13681355 TVector<const TItemExprType*> allItems;
1369- auto structExprType = type->Cast<TStructExprType>();
13701356 for (auto& field: structExprType->GetItems()) {
13711357 const auto& fieldName = field->GetName();
13721358 auto prefixes = input->Child(1);
@@ -1397,7 +1383,9 @@ namespace NTypeAnnImpl {
13971383 }
13981384
13991385 auto structObj = input->Child(0);
1400- if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
1386+ bool optional = false;
1387+ const TStructExprType* structExprType = nullptr;
1388+ if (!EnsureStructOrOptionalStructType(*structObj, optional, structExprType, ctx.Expr)) {
14011389 return IGraphTransformer::TStatus::Error;
14021390 }
14031391
@@ -1406,13 +1394,7 @@ namespace NTypeAnnImpl {
14061394 return status;
14071395 }
14081396
1409- auto type = structObj->GetTypeAnn();
1410- const bool optional = type->GetKind() == ETypeAnnotationKind::Optional;
1411- if (optional) {
1412- type = type->Cast<TOptionalExprType>()->GetItemType();
1413- }
14141397 TVector<const TItemExprType*> allItems;
1415- auto structExprType = type->Cast<TStructExprType>();
14161398 for (auto& field: structExprType->GetItems()) {
14171399 const auto& fieldName = field->GetName();
14181400 auto prefixes = input->Child(1);
@@ -1460,7 +1442,9 @@ namespace NTypeAnnImpl {
14601442 }
14611443
14621444 auto structObj = *iter;
1463- if (!EnsureStructOrOptionalStructType(*structObj, ctx.Expr)) {
1445+ bool isOptionalStruct = false;
1446+ const TStructExprType* structExprType = nullptr;
1447+ if (!EnsureStructOrOptionalStructType(*structObj, isOptionalStruct, structExprType, ctx.Expr)) {
14641448 return IGraphTransformer::TStatus::Error;
14651449 }
14661450 TSet<TString> aliases;
@@ -11877,16 +11861,13 @@ template <NKikimr::NUdf::EDataSlot DataSlot>
1187711861 return IGraphTransformer::TStatus::Error;
1187811862 }
1187911863
11880- if (!EnsureStructOrOptionalStructType(input->Head(), ctx.Expr)) {
11864+ bool isOptional = false;
11865+ const TStructExprType* structType = nullptr;
11866+ if (!EnsureStructOrOptionalStructType(input->Head(), isOptional, structType, ctx.Expr)) {
1188111867 return IGraphTransformer::TStatus::Error;
1188211868 }
1188311869
11884- const TTypeAnnotationNode* itemType = input->Head().GetTypeAnn();
11885- if (itemType->GetKind() == ETypeAnnotationKind::Optional) {
11886- itemType = itemType->Cast<TOptionalExprType>()->GetItemType();
11887- }
11888-
11889- for (const auto& x : itemType->Cast<TStructExprType>()->GetItems()) {
11870+ for (const auto& x : structType->GetItems()) {
1189011871 if (!x->GetItemType()->IsOptionalOrNull()) {
1189111872 ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(input->Head().Pos()), TStringBuilder() << "Expected all columns to be optional. Non optional column: " << x->GetName()));
1189211873 return IGraphTransformer::TStatus::Error;
0 commit comments