@@ -753,38 +753,6 @@ class TCallableConstraintTransformer : public TCallableTransformerBase<TCallable
753
753
return std::nullopt;
754
754
}
755
755
756
- static std::optional<TPartOfConstraintBase::TPathType> GetPathToKey (const TExprNode& body, const TExprNode& arg) {
757
- if (&body == &arg)
758
- return TPartOfConstraintBase::TPathType ();
759
-
760
- if (body.IsCallable ({" Member" ," Nth" })) {
761
- if (auto path = GetPathToKey (body.Head (), arg)) {
762
- path->emplace_back (body.Tail ().Content ());
763
- return path;
764
- }
765
- }
766
-
767
- if (body.IsCallable ({" CastStruct" ," FilterMembers" ," Just" ," Unwrap" }))
768
- return GetPathToKey (body.Head (), arg);
769
- if (body.IsCallable (" Member" ) && body.Head ().IsCallable (" AsStruct" ))
770
- return GetPathToKey (GetLiteralStructMember (body.Head (), body.Tail ()), arg);
771
- if (body.IsCallable (" Nth" ) && body.Head ().IsList ())
772
- return GetPathToKey (*body.Head ().Child (FromString<ui32>(body.Tail ().Content ())), arg);
773
- if (body.IsList () && 1U == body.ChildrenSize () && body.Head ().IsCallable (" Nth" ) && body.Head ().Tail ().IsAtom (" 0" ) &&
774
- 1U == RemoveOptionality (*body.Head ().Head ().GetTypeAnn ()).Cast <TTupleExprType>()->GetSize ())
775
- // Especialy for "Extract single item tuple from Condense1" optimizer.
776
- return GetPathToKey (body.Head ().Head (), arg);
777
- if (body.IsCallable (" AsStruct" ) && 1U == body.ChildrenSize () && body.Head ().Tail ().IsCallable (" Member" ) &&
778
- body.Head ().Head ().Content () == body.Head ().Tail ().Tail ().Content () &&
779
- 1U == RemoveOptionality (*body.Head ().Tail ().Head ().GetTypeAnn ()).Cast <TStructExprType>()->GetSize ())
780
- // Especialy for "Extract single item struct from Condense1" optimizer.
781
- return GetPathToKey (body.Head ().Tail ().Head (), arg);
782
- if (IsTransparentIfPresent (body) && &body.Head () == &arg)
783
- return GetPathToKey (body.Child (1 )->Tail ().Head (), body.Child (1 )->Head ().Head ());
784
-
785
- return std::nullopt;
786
- }
787
-
788
756
static std::vector<std::pair<TPartOfConstraintBase::TPathType, bool >>
789
757
ExtractSimpleSortTraits (const TExprNode& sortDirections, const TExprNode& keySelectorLambda) {
790
758
const auto & keySelectorBody = keySelectorLambda.Tail ();
@@ -2684,34 +2652,6 @@ class TCallableConstraintTransformer : public TCallableTransformerBase<TCallable
2684
2652
.Combine (UpdateLambdaConstraints (input->ChildRef (TCoIsKeySwitch::idx_StateKeyExtractor), ctx, stateConstraints));
2685
2653
}
2686
2654
2687
- static const TExprNode& GetLiteralStructMember (const TExprNode& literal, const TExprNode& member) {
2688
- for (const auto & child : literal.Children ())
2689
- if (&child->Head () == &member || child->Head ().Content () == member.Content ())
2690
- return child->Tail ();
2691
- ythrow yexception () << " Member '" << member.Content () << " ' not found in literal struct." ;
2692
- }
2693
-
2694
- static std::optional<std::pair<TPartOfConstraintBase::TPathType, ui32>> GetPathToKey (const TExprNode& body, const TExprNode::TChildrenType& args) {
2695
- if (body.IsArgument ()) {
2696
- for (auto i = 0U ; i < args.size (); ++i)
2697
- if (&body == args[i].Get ())
2698
- return std::make_pair (TPartOfConstraintBase::TPathType (), i);
2699
- } else if (body.IsCallable ({" Member" ," Nth" })) {
2700
- if (auto path = GetPathToKey (body.Head (), args)) {
2701
- path->first .emplace_back (body.Tail ().Content ());
2702
- return path;
2703
- } else if (const auto & head = SkipCallables (body.Head (), {" CastStruct" ," FilterMembers" }); head.IsCallable (" AsStruct" ) && body.IsCallable (" Member" )) {
2704
- return GetPathToKey (GetLiteralStructMember (head, body.Tail ()), args);
2705
- } else if (body.IsCallable (" Nth" ) && body.Head ().IsList ()) {
2706
- return GetPathToKey (*body.Head ().Child (FromString<ui32>(body.Tail ().Content ())), args);
2707
- } else if (body.IsCallable ({" CastStruct" ," FilterMembers" })) {
2708
- return GetPathToKey (body.Head (), args);
2709
- }
2710
- }
2711
-
2712
- return std::nullopt;
2713
- }
2714
-
2715
2655
template <bool Wide>
2716
2656
static TPartOfConstraintBase::TSetType GetSimpleKeys (const TExprNode& body, const TExprNode::TChildrenType& args, TExprContext& ctx) {
2717
2657
TPartOfConstraintBase::TSetType keys;
@@ -2749,33 +2689,15 @@ class TCallableConstraintTransformer : public TCallableTransformerBase<TCallable
2749
2689
return keys;
2750
2690
}
2751
2691
2752
- static TPartOfConstraintBase::TSetType GetSimpleKeys (const TExprNode& body, const TExprNode& arg) {
2753
- TPartOfConstraintBase::TSetType keys;
2754
- if (body.IsList ()) {
2755
- if (const auto size = body.ChildrenSize ()) {
2756
- keys.reserve (size);
2757
- for (auto i = 0U ; i < size; ++i)
2758
- if (auto path = GetPathToKey (*body.Child (i), arg))
2759
- keys.insert_unique (std::move (*path));
2760
- }
2761
- } else if (body.IsCallable (" StablePickle" )) {
2762
- return GetSimpleKeys (body.Head (), arg);
2763
- } else if (auto path = GetPathToKey (body, arg)) {
2764
- keys.insert_unique (std::move (*path));
2765
- }
2766
-
2767
- return keys;
2768
- }
2769
-
2770
2692
template <bool Wide>
2771
2693
static TPartOfConstraintBase::TSetType GetSimpleKeys (const TExprNode& selector, TExprContext& ctx) {
2772
2694
YQL_ENSURE (selector.IsLambda () && 2U == selector.ChildrenSize ());
2773
2695
const auto & body = selector.Tail ();
2774
2696
if constexpr (!Wide) {
2775
2697
if (TCoIsKeySwitch::Match (&body)) {
2776
2698
const TCoIsKeySwitch keySwitch (&body);
2777
- const auto & i = GetSimpleKeys (*ctx.ReplaceNode (keySwitch.ItemKeyExtractor ().Body ().Ptr (), keySwitch.ItemKeyExtractor ().Args ().Arg (0 ).Ref (), keySwitch.Item ().Ptr ()), keySwitch.Item ().Ref ());
2778
- const auto & s = GetSimpleKeys (*ctx.ReplaceNode (keySwitch.StateKeyExtractor ().Body ().Ptr (), keySwitch.StateKeyExtractor ().Args ().Arg (0 ).Ref (), keySwitch.State ().Ptr ()), keySwitch.Item ().Ref ());
2699
+ const auto & i = GetPathsToKeys (*ctx.ReplaceNode (keySwitch.ItemKeyExtractor ().Body ().Ptr (), keySwitch.ItemKeyExtractor ().Args ().Arg (0 ).Ref (), keySwitch.Item ().Ptr ()), keySwitch.Item ().Ref ());
2700
+ const auto & s = GetPathsToKeys (*ctx.ReplaceNode (keySwitch.StateKeyExtractor ().Body ().Ptr (), keySwitch.StateKeyExtractor ().Args ().Arg (0 ).Ref (), keySwitch.State ().Ptr ()), keySwitch.Item ().Ref ());
2779
2701
return i == s ? i : TPartOfConstraintBase::TSetType ();
2780
2702
}
2781
2703
}
@@ -3005,13 +2927,13 @@ class TCallableConstraintTransformer : public TCallableTransformerBase<TCallable
3005
2927
3006
2928
TPartOfConstraintBase::TSetType keys;
3007
2929
if constexpr (Partitions) {
3008
- keys = GetSimpleKeys (input->Child (TCoBase::idx_KeySelectorLambda)->Tail (), input->Child (TCoBase::idx_KeySelectorLambda)->Head ().Head ());
2930
+ keys = GetPathsToKeys (input->Child (TCoBase::idx_KeySelectorLambda)->Tail (), input->Child (TCoBase::idx_KeySelectorLambda)->Head ().Head ());
3009
2931
if (const auto sortKeySelector = input->Child (TCoBase::idx_SortKeySelectorLambda); sortKeySelector->IsLambda ()) {
3010
2932
if (const auto status = UpdateLambdaConstraints (*sortKeySelector); status != TStatus::Ok) {
3011
2933
return status;
3012
2934
}
3013
2935
3014
- auto sortKeys = GetSimpleKeys (sortKeySelector->Tail (), sortKeySelector->Head ().Head ());
2936
+ auto sortKeys = GetPathsToKeys (sortKeySelector->Tail (), sortKeySelector->Head ().Head ());
3015
2937
std::move (sortKeys.begin (), sortKeys.end (), std::back_inserter (keys));
3016
2938
std::sort (keys.begin (), keys.end ());
3017
2939
}
0 commit comments