aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authora-romanov <Anton.Romanov@ydb.tech>2023-07-26 12:43:26 +0300
committera-romanov <Anton.Romanov@ydb.tech>2023-07-26 12:43:26 +0300
commit2ccacfcb71600c3a39b95a255753c0335dbfc95d (patch)
tree4ed450a3d212b4cdedcca8f1af50e77fc499f817
parente0cab1bab710af9eba68da1d0e063854b936bb28 (diff)
downloadydb-2ccacfcb71600c3a39b95a255753c0335dbfc95d.tar.gz
YQL-13180 Don`t use SilentInferCommonType.
-rw-r--r--ydb/library/yql/core/type_ann/type_ann_list.cpp51
1 files changed, 17 insertions, 34 deletions
diff --git a/ydb/library/yql/core/type_ann/type_ann_list.cpp b/ydb/library/yql/core/type_ann/type_ann_list.cpp
index a80439da5f..1d152333c6 100644
--- a/ydb/library/yql/core/type_ann/type_ann_list.cpp
+++ b/ydb/library/yql/core/type_ann/type_ann_list.cpp
@@ -2535,50 +2535,42 @@ namespace {
return IGraphTransformer::TStatus::Repeat;
}
- auto tmpArg1 = ctx.Expr.NewArgument(input->Pos(), "tmp1");
- auto tmpArg2 = ctx.Expr.NewArgument(input->Pos(), "tmp2");
- THashMap<TStringBuf, std::pair<const TTypeAnnotationNode*, ui32>> members;
- ui32 inputsCount = input->ChildrenSize();
- auto checkStructType = [&members, &ctx, tmpArg1, tmpArg2, inputsCount, pos = input->Pos()](TExprNode& input) -> const TStructExprType* {
+ std::unordered_map<std::string_view, std::pair<const TTypeAnnotationNode*, ui32>> members;
+ const auto inputsCount = input->ChildrenSize();
+ const auto checkStructType = [&members, &ctx, inputsCount, pos = input->Pos()](TExprNode& input) -> const TStructExprType* {
if (!EnsureListType(input, ctx.Expr)) {
return nullptr;
}
- auto itemType = input.GetTypeAnn()->Cast<TListExprType>()->GetItemType();
+ const auto itemType = input.GetTypeAnn()->Cast<TListExprType>()->GetItemType();
if (!EnsureStructType(input.Pos(), *itemType, ctx.Expr)) {
return nullptr;
}
- auto structType = itemType->Cast<TStructExprType>();
- for (auto item: structType->GetItems()) {
- auto res = members.insert({ item->GetName(), { item->GetItemType(), 1 } });
- if (!res.second) {
+ const auto structType = itemType->Cast<TStructExprType>();
+ for (const auto& item: structType->GetItems()) {
+ if (const auto res = members.insert({ item->GetName(), { item->GetItemType(), 1U } }); !res.second) {
if (item->GetItemType()->GetKind() == ETypeAnnotationKind::Error) {
continue;
}
auto& p = res.first->second;
if (p.first->GetKind() == ETypeAnnotationKind::Error) {
- members[item->GetName()] = { p.first, inputsCount };
continue;
}
- ++p.second;
- const TTypeAnnotationNode* commonType = nullptr;
- auto arg1 = tmpArg1;
- auto arg2 = tmpArg2;
- if (SilentInferCommonType(arg1, *p.first, arg2, *item->GetItemType(), ctx.Expr, commonType)
- != IGraphTransformer::TStatus::Error) {
+ if (const auto commonType = CommonType<false>(input.Pos(), p.first, item->GetItemType(), ctx.Expr)) {
p.first = commonType;
+ ++p.second;
continue;
}
- auto err = TIssue(
+ const TIssue err(
ctx.Expr.GetPosition(pos),
TStringBuilder()
<< "Uncompatible member " << item->GetName() << " types: "
<< *p.first << " and " << *item->GetItemType()
);
- members[item->GetName()] = { ctx.Expr.MakeType<TErrorExprType>(err), inputsCount };
+ p = { ctx.Expr.MakeType<TErrorExprType>(err), inputsCount };
}
}
return structType;
@@ -2655,7 +2647,7 @@ namespace {
IGraphTransformer::TStatus InferPositionalUnionType(TPositionHandle pos, const TExprNode::TListType& children,
TColumnOrder& resultColumnOrder, const TStructExprType*& resultStructType, TExtContext& ctx) {
- TVector<const TTypeAnnotationNode*> resultTypes;
+ TTypeAnnotationNode::TListType resultTypes;
size_t idx = 0;
for (const auto& child : children) {
if (!EnsureListType(*child, ctx.Expr)) {
@@ -2675,8 +2667,8 @@ namespace {
return IGraphTransformer::TStatus::Error;
}
- TVector<const TTypeAnnotationNode*> childTypes;
- auto structType = itemType->Cast<TStructExprType>();
+ TTypeAnnotationNode::TListType childTypes;
+ const auto structType = itemType->Cast<TStructExprType>();
for (const auto& col : *childColumnOrder) {
auto itemIdx = structType->FindItem(col);
YQL_ENSURE(itemIdx);
@@ -2694,19 +2686,10 @@ namespace {
return IGraphTransformer::TStatus::Error;
}
for (size_t i = 0; i < childTypes.size(); ++i) {
- auto arg1 = ctx.Expr.NewArgument(child->Pos(), "arg1");
- auto arg2 = ctx.Expr.NewArgument(child ->Pos(), "arg2");
- const TTypeAnnotationNode* commonType = nullptr;
- auto status = SilentInferCommonType(arg1, *resultTypes[i], arg2, *childTypes[i], ctx.Expr, commonType);
- if (status == IGraphTransformer::TStatus::Error) {
- ctx.Expr.AddError(TIssue(ctx.Expr.GetPosition(child->Pos()), TStringBuilder()
- << "Can not infer common type for result column " << resultColumnOrder[i]
- << ": no common type for " << *resultTypes[i] << " and column " << (*childColumnOrder)[i]
- << " type " << *childTypes[i]));
+ if (const auto commonType = CommonType<false>(child->Pos(), resultTypes[i], childTypes[i], ctx.Expr))
+ resultTypes[i] = commonType;
+ else
return IGraphTransformer::TStatus::Error;
- }
- YQL_ENSURE(commonType);
- resultTypes[i] = commonType;
}
}
idx++;