diff options
author | a-romanov <[email protected]> | 2023-01-13 14:07:54 +0300 |
---|---|---|
committer | a-romanov <[email protected]> | 2023-01-13 14:07:54 +0300 |
commit | da85f2e9985b3d1b2ac0d793b33fbcfd7d8ae97f (patch) | |
tree | d1f30fa6055a05bc484b8f88a23952de6ece841f | |
parent | 29cc6da1f546541c9ccce57bf06114f2faca8ee8 (diff) |
Drop duplicate GetSeqItemType.
-rw-r--r-- | ydb/library/yql/core/common_opt/yql_co_simple1.cpp | 39 | ||||
-rw-r--r-- | ydb/library/yql/core/type_ann/type_ann_core.cpp | 4 | ||||
-rw-r--r-- | ydb/library/yql/core/yql_expr_constraint.cpp | 27 | ||||
-rw-r--r-- | ydb/library/yql/core/yql_expr_type_annotation.cpp | 2 | ||||
-rw-r--r-- | ydb/library/yql/core/yql_opt_utils.cpp | 2 | ||||
-rw-r--r-- | ydb/library/yql/core/yql_type_helpers.cpp | 20 | ||||
-rw-r--r-- | ydb/library/yql/core/yql_type_helpers.h | 1 | ||||
-rw-r--r-- | ydb/library/yql/dq/opt/dq_opt_phy.cpp | 4 | ||||
-rw-r--r-- | ydb/library/yql/providers/dq/provider/yql_dq_datasource.cpp | 2 |
9 files changed, 42 insertions, 59 deletions
diff --git a/ydb/library/yql/core/common_opt/yql_co_simple1.cpp b/ydb/library/yql/core/common_opt/yql_co_simple1.cpp index bbd19a2ddd7..7f98ac8f2eb 100644 --- a/ydb/library/yql/core/common_opt/yql_co_simple1.cpp +++ b/ydb/library/yql/core/common_opt/yql_co_simple1.cpp @@ -606,7 +606,7 @@ TExprNode::TPtr OptimizeInsert(const TExprNode::TPtr& node, TExprContext& ctx, T template <bool Ordered> TExprNode::TPtr ExpandExtract(const TExprNode::TPtr& node, TExprContext& ctx) { YQL_CLOG(DEBUG, Core) << "Expand " << node->Content(); - const bool isStruct = ETypeAnnotationKind::Struct == GetSeqItemType(node->Head().GetTypeAnn())->GetKind(); + const bool isStruct = ETypeAnnotationKind::Struct == GetSeqItemType(*node->Head().GetTypeAnn()).GetKind(); return ctx.Builder(node->Pos()) .Callable(Ordered ? "OrderedMap" : "Map") .Add(0, node->HeadPtr()) @@ -2236,19 +2236,19 @@ TExprNode::TPtr SimpleFlatMap(const TExprNode::TPtr& node, TExprContext& ctx, TO return expr; } - if (auto just = self.Lambda().Body().Maybe<TCoJust>()) { - if (auto tuple = just.Cast().Input().Maybe<TExprList>()) { + if (const auto just = self.Lambda().Body().Maybe<TCoJust>()) { + if (const auto tuple = just.Cast().Input().Maybe<TExprList>()) { if (tuple.Cast().Size() > 0) { TExprNode::TPtr inner; for (ui32 i = 0; i < tuple.Cast().Size(); ++i) { auto x = tuple.Cast().Item(i).Raw(); - if (!x->IsCallable("Nth") || x->Child(1)->Content() != ToString(i)) { + if (!(x->IsCallable("Nth") && x->Tail().IsAtom(ctx.GetIndexAsString(i)))) { inner = nullptr; break; } - auto current = x->ChildPtr(0); - if (current != self.Lambda().Args().Arg(0).Raw()) { + const auto& current = x->HeadPtr(); + if (current != self.Lambda().Args().Arg(0).Ptr()) { inner = nullptr; break; } @@ -4997,7 +4997,7 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { auto flatMapInput = lambda->Child(1)->Child(0); const TTypeAnnotationNode* castType = nullptr; if (TCoExtractMembers::Match(flatMapInput)) { - castType = GetSeqItemType(flatMapInput->GetTypeAnn()); + castType = &GetSeqItemType(*flatMapInput->GetTypeAnn()); flatMapInput = flatMapInput->Child(0); } @@ -5098,7 +5098,7 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { } } - const auto outVarType = ExpandType(node->Pos(), *GetSeqItemType(node->GetTypeAnn()), ctx); + const auto outVarType = ExpandType(node->Pos(), GetSeqItemType(*node->GetTypeAnn()), ctx); TExprNode::TListType updatedLambdas; for (size_t i = 0; i < lambdas.size(); ++i) { @@ -5212,7 +5212,7 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { } if (indicies.size() < inputVarTupleType->GetSize()) { builder.Callable(indicies.size() * 2 + 1, GetEmptyCollectionName(targetType)) - .Add(0, ExpandType(node->Pos(), *MakeSequenceType(targetType, *GetSeqItemType(node->GetTypeAnn()), ctx), ctx)) + .Add(0, ExpandType(node->Pos(), *MakeSequenceType(targetType, GetSeqItemType(*node->GetTypeAnn()), ctx), ctx)) .Seal(); } return builder; @@ -5264,7 +5264,7 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { .Callable(ETypeAnnotationKind::Flow == node->GetTypeAnn()->GetKind() ? "ToFlow" : "ToStream") .Callable(0, "Just") .Callable(0, "Dict") - .Add(0, ExpandType(node->Pos(), *GetSeqItemType(node->GetTypeAnn()), ctx)) + .Add(0, ExpandType(node->Pos(), GetSeqItemType(*node->GetTypeAnn()), ctx)) .Seal() .Seal() .Seal().Build(); @@ -6333,8 +6333,8 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { map["CountedAggregateAll"] = [](const TExprNode::TPtr& node, TExprContext& ctx, TOptimizeContext& optCtx) { YQL_CLOG(DEBUG, Core) << "Expand " << node->Content(); - auto itemType = GetItemType(*node->Head().GetTypeAnn()); - auto inputTypeNode = ExpandType(node->Pos(), *itemType, ctx); + const auto& itemType = GetSeqItemType(*node->Head().GetTypeAnn()); + auto inputTypeNode = ExpandType(node->Pos(), itemType, ctx); THashSet<TStringBuf> countedColumns; for (const auto& child : node->Tail().Children()) { countedColumns.insert(child->Content()); @@ -6342,7 +6342,7 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { TExprNode::TListType keys; TExprNode::TListType payloads; - for (auto i : itemType->Cast<TStructExprType>()->GetItems()) { + for (auto i : itemType.Cast<TStructExprType>()->GetItems()) { if (!countedColumns.contains(i->GetName())) { keys.push_back(ctx.NewAtom(node->Pos(), i->GetName())); } else { @@ -6425,9 +6425,9 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { if (const auto& joinKind = mapJoin.JoinKind().Value(); joinKind == "Inner" || joinKind == "LeftSemi") return ctx.NewCallable(mapJoin.Pos(), "EmptyIterator", {ExpandType(mapJoin.Pos(), *node->GetTypeAnn(), ctx)}); else if (joinKind == "Left" || joinKind == "LeftOnly") { - switch (const auto itemType = GetSeqItemType(node->GetTypeAnn()); itemType->GetKind()) { + switch (const auto& itemType = GetSeqItemType(*node->GetTypeAnn()); itemType.GetKind()) { case ETypeAnnotationKind::Tuple: { - const auto& items = itemType->Cast<TTupleExprType>()->GetItems(); + const auto& items = itemType.Cast<TTupleExprType>()->GetItems(); auto row = ctx.NewArgument(mapJoin.Pos(), "row"); TExprNode::TListType fields(items.size()); for (auto i = 1U; i < mapJoin.LeftRenames().Size(); ++++i) { @@ -6449,7 +6449,7 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { return ctx.NewCallable(mapJoin.Pos(), "Map", {mapJoin.LeftInput().Ptr(), std::move(lambda)}); } case ETypeAnnotationKind::Struct: { - const auto structType = itemType->Cast<TStructExprType>(); + const auto structType = itemType.Cast<TStructExprType>(); const auto& items = structType->GetItems(); auto row = ctx.NewArgument(mapJoin.Pos(), "row"); TExprNode::TListType fields(items.size()); @@ -6634,16 +6634,15 @@ void RegisterCoSimpleCallables1(TCallableOptimizerMap& map) { // push over sequence-of-structs or tuple(world, sequence-of-structs) if (type->GetKind() == ETypeAnnotationKind::Tuple) { auto tupleType = type->Cast<TTupleExprType>(); - if (tupleType->GetSize() == 2 && tupleType->GetItems()[0]->GetKind() == ETypeAnnotationKind::World) { - type = tupleType->GetItems()[1]; + if (tupleType->GetSize() == 2 && tupleType->GetItems().front()->GetKind() == ETypeAnnotationKind::World) { + type = tupleType->GetItems().back(); } } if (type->GetKind() != ETypeAnnotationKind::Struct) { - type = GetItemType(*type); + type = GetSeqItemType(type); } - auto newChildren = node->ChildrenList(); for (auto& child : newChildren) { if (child->IsCallable("AssumeColumnOrder")) { diff --git a/ydb/library/yql/core/type_ann/type_ann_core.cpp b/ydb/library/yql/core/type_ann/type_ann_core.cpp index eda1c9a7e25..cc41f881441 100644 --- a/ydb/library/yql/core/type_ann/type_ann_core.cpp +++ b/ydb/library/yql/core/type_ann/type_ann_core.cpp @@ -1783,7 +1783,7 @@ namespace NTypeAnnImpl { const TTypeAnnotationNode* resultType = nullptr; bool isSequence = true; - const TTypeAnnotationNode* itemType = GetItemType(*firstChildType); + const TTypeAnnotationNode* itemType = GetSeqItemType(firstChildType); if (!itemType) { itemType = firstChildType; isSequence = false; @@ -1871,7 +1871,7 @@ namespace NTypeAnnImpl { return IGraphTransformer::TStatus::Error; } - const TTypeAnnotationNode* itemType = GetItemType(*firstChildType); + const TTypeAnnotationNode* itemType = GetSeqItemType(firstChildType); if (!itemType) { itemType = firstChildType; } diff --git a/ydb/library/yql/core/yql_expr_constraint.cpp b/ydb/library/yql/core/yql_expr_constraint.cpp index 3795cc98a4c..3fe4032a4d8 100644 --- a/ydb/library/yql/core/yql_expr_constraint.cpp +++ b/ydb/library/yql/core/yql_expr_constraint.cpp @@ -568,7 +568,7 @@ private: } TStatus ExtractMembersWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const { - const auto outItemType = GetItemType(*input->GetTypeAnn())->Cast<TStructExprType>(); + const auto outItemType = GetSeqItemType(*input->GetTypeAnn()).Cast<TStructExprType>(); if (const auto passthrough = input->Head().GetConstraint<TPassthroughConstraintNode>()) { TPassthroughConstraintNode::TMapType filteredMapping; for (const auto& part: passthrough->GetColumnMapping()) { @@ -607,7 +607,7 @@ private: } TStatus RemovePrefixMembersWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const { - const TTypeAnnotationNode* outItemType = GetItemType(*input->GetTypeAnn()); + const TTypeAnnotationNode* outItemType = GetSeqItemType(input->GetTypeAnn()); if (!outItemType) { outItemType = input->GetTypeAnn(); } @@ -729,7 +729,7 @@ private: static TConstraintNode::TListType GetConstraintsForInputArgument(const TExprNode& node, std::unordered_set<const TPassthroughConstraintNode*>& explicitPasstrought, TExprContext& ctx) { TConstraintNode::TListType constraints; - if (const auto inItemType = GetItemType(*node.Head().GetTypeAnn())) { + if (const auto inItemType = GetSeqItemType(node.Head().GetTypeAnn())) { if (inItemType->GetKind() == ETypeAnnotationKind::Variant) { if (inItemType->Cast<TVariantExprType>()->GetUnderlyingType()->GetKind() == ETypeAnnotationKind::Tuple) { const auto tupleType = inItemType->Cast<TVariantExprType>()->GetUnderlyingType()->Cast<TTupleExprType>(); @@ -799,7 +799,7 @@ private: template <bool UseSorted, bool Flat, bool WideInput = false, bool WideOutput = false> TStatus MapWrap(const TExprNode::TPtr& input, TExprNode::TPtr& output, TExprContext& ctx) const { - const auto inItemType = GetItemType(*input->Head().GetTypeAnn()); + const auto inItemType = GetSeqItemType(input->Head().GetTypeAnn()); TSmallVec<TConstraintNode::TListType> argConstraints(input->Tail().Head().ChildrenSize()); std::unordered_set<const TPassthroughConstraintNode*> explicitPasstrought; if constexpr (WideInput) { @@ -1019,10 +1019,11 @@ private: } if (UseSorted && !hasOutSorted && !lambdaPassthrough) { if (const auto sorted = input->Head().GetConstraint<TSortedConstraintNode>()) { - const auto outItemType = GetItemType(*input->GetTypeAnn()); - if (outItemType && outItemType->GetKind() == ETypeAnnotationKind::Struct) { - if (const auto outSorted = TSortedConstraintNode::FilterByType(sorted, outItemType->Cast<TStructExprType>(), ctx)) { - input->AddConstraint(outSorted); + if (const auto outItemType = GetSeqItemType(input->GetTypeAnn())) { + if (outItemType->GetKind() == ETypeAnnotationKind::Struct) { + if (const auto outSorted = TSortedConstraintNode::FilterByType(sorted, outItemType->Cast<TStructExprType>(), ctx)) { + input->AddConstraint(outSorted); + } } } } @@ -1621,7 +1622,7 @@ private: } auto outType = input->GetTypeAnn(); - if (auto t = GetItemType(*outType)) { + if (auto t = GetSeqItemType(outType)) { outType = t; } if (outType->GetKind() == ETypeAnnotationKind::Variant && outType->Cast<TVariantExprType>()->GetUnderlyingType()->GetKind() == ETypeAnnotationKind::Tuple) { @@ -1817,7 +1818,7 @@ private: } TStatus MuxWrap(const TExprNode::TPtr& input, TExprNode::TPtr& /*output*/, TExprContext& ctx) const { - const TTypeAnnotationNode* listItemType = GetItemType(*input->GetTypeAnn()); + const auto listItemType = GetSeqItemType(input->GetTypeAnn()); if (!listItemType) { return TStatus::Ok; } @@ -2222,7 +2223,7 @@ private: } } - const bool multiInput = ETypeAnnotationKind::Variant == GetItemType(*input->Head().GetTypeAnn())->GetKind(); + const bool multiInput = ETypeAnnotationKind::Variant == GetSeqItemType(*input->Head().GetTypeAnn()).GetKind(); const auto lambdaVarIndex = handlerLambda->GetConstraint<TVarIndexConstraintNode>(); const auto multi = input->Head().GetConstraint<TMultiConstraintNode>(); const auto lambdaMulti = handlerLambda->GetConstraint<TMultiConstraintNode>(); @@ -2462,7 +2463,7 @@ private: static std::vector<std::string_view> GetAllItemTypeFields(const TTypeAnnotationNode& type, TExprContext& ctx) { std::vector<std::string_view> fields; - if (const auto itemType = GetItemType(type)) { + if (const auto itemType = GetSeqItemType(&type)) { switch (itemType->GetKind()) { case ETypeAnnotationKind::Struct: if (const auto structType = itemType->Cast<TStructExprType>()) { @@ -2496,7 +2497,7 @@ private: } static const TStructExprType* GetNonEmptyStructItemType(const TTypeAnnotationNode& type) { - const TTypeAnnotationNode* itemType = GetItemType(type); + const auto itemType = GetSeqItemType(&type); if (!itemType || itemType->GetKind() != ETypeAnnotationKind::Struct) { return nullptr; } diff --git a/ydb/library/yql/core/yql_expr_type_annotation.cpp b/ydb/library/yql/core/yql_expr_type_annotation.cpp index c3a4e1e2a7a..e095d950008 100644 --- a/ydb/library/yql/core/yql_expr_type_annotation.cpp +++ b/ydb/library/yql/core/yql_expr_type_annotation.cpp @@ -4857,7 +4857,7 @@ static void PrintTypeDiff(TStringBuilder& res, size_t level, const TIndentPrinte case ETypeAnnotationKind::Flow: res << left.GetKind() << '<'; indent(res, level + 1); - PrintTypeDiff(res, level + 1, indent, *GetItemType(left), *GetItemType(right)); + PrintTypeDiff(res, level + 1, indent, GetSeqItemType(left), GetSeqItemType(right)); indent(res, level); res << '>'; break; diff --git a/ydb/library/yql/core/yql_opt_utils.cpp b/ydb/library/yql/core/yql_opt_utils.cpp index 682d876cfda..12f2193c8b0 100644 --- a/ydb/library/yql/core/yql_opt_utils.cpp +++ b/ydb/library/yql/core/yql_opt_utils.cpp @@ -628,7 +628,7 @@ TExprNode::TPtr ExpandRemoveMembers(const TExprNode::TPtr& node, TExprContext& c TExprNode::TPtr ExpandRemovePrefixMembers(const TExprNode::TPtr& node, TExprContext& ctx) { YQL_CLOG(DEBUG, Core) << "Expand " << node->Content(); - const TTypeAnnotationNode* targetItemType = GetItemType(*node->GetTypeAnn()); + const TTypeAnnotationNode* targetItemType = GetSeqItemType(node->GetTypeAnn()); bool isSequence = true; if (!targetItemType) { targetItemType = node->GetTypeAnn(); diff --git a/ydb/library/yql/core/yql_type_helpers.cpp b/ydb/library/yql/core/yql_type_helpers.cpp index 884c6f29dc6..c54ab651db2 100644 --- a/ydb/library/yql/core/yql_type_helpers.cpp +++ b/ydb/library/yql/core/yql_type_helpers.cpp @@ -5,26 +5,10 @@ namespace NYql { -const TTypeAnnotationNode* GetItemType(const TTypeAnnotationNode& type) { - switch (type.GetKind()) { - case ETypeAnnotationKind::List: - return type.Cast<TListExprType>()->GetItemType(); - case ETypeAnnotationKind::Optional: - return type.Cast<TOptionalExprType>()->GetItemType(); - case ETypeAnnotationKind::Stream: - return type.Cast<TStreamExprType>()->GetItemType(); - case ETypeAnnotationKind::Flow: - return type.Cast<TFlowExprType>()->GetItemType(); - default: - break; - } - return nullptr; -} - TSet<TStringBuf> GetColumnsOfStructOrSequenceOfStruct(const TTypeAnnotationNode& type) { const TTypeAnnotationNode* itemType = nullptr; if (type.GetKind() != ETypeAnnotationKind::Struct) { - itemType = GetItemType(type); + itemType = GetSeqItemType(&type); YQL_ENSURE(itemType); } else { itemType = &type; @@ -44,7 +28,7 @@ bool SilentGetSequenceItemType(TPosition pos, const TTypeAnnotationNode& inputTy const TTypeAnnotationNode*& result, TIssue& error) { result = nullptr; - const TTypeAnnotationNode* itemType = GetItemType(inputType); + const auto itemType = GetSeqItemType(&inputType); if (!itemType) { error = TIssue(pos, TStringBuilder() << "Expected list, stream, flow or optional, but got: " << inputType); return false; diff --git a/ydb/library/yql/core/yql_type_helpers.h b/ydb/library/yql/core/yql_type_helpers.h index 593c77592b7..93b1c722696 100644 --- a/ydb/library/yql/core/yql_type_helpers.h +++ b/ydb/library/yql/core/yql_type_helpers.h @@ -7,7 +7,6 @@ namespace NYql { -const TTypeAnnotationNode* GetItemType(const TTypeAnnotationNode& type); TSet<TStringBuf> GetColumnsOfStructOrSequenceOfStruct(const TTypeAnnotationNode& type); const TTypeAnnotationNode* GetSequenceItemType(NNodes::TExprBase listNode, bool allowMultiIO); diff --git a/ydb/library/yql/dq/opt/dq_opt_phy.cpp b/ydb/library/yql/dq/opt/dq_opt_phy.cpp index bc4a7406dff..37a087f3766 100644 --- a/ydb/library/yql/dq/opt/dq_opt_phy.cpp +++ b/ydb/library/yql/dq/opt/dq_opt_phy.cpp @@ -94,7 +94,7 @@ TExprBase DqBuildPartitionsStageStub(TExprBase node, TExprContext& ctx, const TP // dq splits this type of lambda output into separate stage outputs // thus it's impossible to maintain 'node' typing (muxing them ain't an option, // cause the only purpose of this optimizer is to push original Mux to the stage) - if (const auto listItemType = GetItemType(*node.Ref().GetTypeAnn()); + if (const auto listItemType = GetSeqItemType(node.Ref().GetTypeAnn()); !listItemType || listItemType->GetKind() == ETypeAnnotationKind::Variant) { return node; } @@ -752,7 +752,7 @@ TExprBase DqBuildLMapOverMuxStageStub(TExprBase node, TExprContext& ctx, NYql::I return node; } auto mux = maybeMux.Cast(); - const TTypeAnnotationNode* listItemType = GetItemType(*node.Ref().GetTypeAnn()); + const TTypeAnnotationNode* listItemType = GetSeqItemType(node.Ref().GetTypeAnn()); if (!listItemType) { return node; } diff --git a/ydb/library/yql/providers/dq/provider/yql_dq_datasource.cpp b/ydb/library/yql/providers/dq/provider/yql_dq_datasource.cpp index c7c26aad026..6cd00b8871f 100644 --- a/ydb/library/yql/providers/dq/provider/yql_dq_datasource.cpp +++ b/ydb/library/yql/providers/dq/provider/yql_dq_datasource.cpp @@ -169,7 +169,7 @@ public: return false; } - if (auto type = GetItemType(*node.GetTypeAnn()); !type || type->GetKind() != ETypeAnnotationKind::Struct) { + if (auto type = GetSeqItemType(node.GetTypeAnn()); !type || type->GetKind() != ETypeAnnotationKind::Struct) { return false; } |