@@ -753,38 +753,6 @@ class TCallableConstraintTransformer : public TCallableTransformerBase<TCallable
753753 return std::nullopt ;
754754 }
755755
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-
788756 static std::vector<std::pair<TPartOfConstraintBase::TPathType, bool >>
789757 ExtractSimpleSortTraits (const TExprNode& sortDirections, const TExprNode& keySelectorLambda) {
790758 const auto & keySelectorBody = keySelectorLambda.Tail ();
@@ -2684,34 +2652,6 @@ class TCallableConstraintTransformer : public TCallableTransformerBase<TCallable
26842652 .Combine (UpdateLambdaConstraints (input->ChildRef (TCoIsKeySwitch::idx_StateKeyExtractor), ctx, stateConstraints));
26852653 }
26862654
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-
27152655 template <bool Wide>
27162656 static TPartOfConstraintBase::TSetType GetSimpleKeys (const TExprNode& body, const TExprNode::TChildrenType& args, TExprContext& ctx) {
27172657 TPartOfConstraintBase::TSetType keys;
@@ -2749,33 +2689,15 @@ class TCallableConstraintTransformer : public TCallableTransformerBase<TCallable
27492689 return keys;
27502690 }
27512691
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-
27702692 template <bool Wide>
27712693 static TPartOfConstraintBase::TSetType GetSimpleKeys (const TExprNode& selector, TExprContext& ctx) {
27722694 YQL_ENSURE (selector.IsLambda () && 2U == selector.ChildrenSize ());
27732695 const auto & body = selector.Tail ();
27742696 if constexpr (!Wide) {
27752697 if (TCoIsKeySwitch::Match (&body)) {
27762698 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 ());
27792701 return i == s ? i : TPartOfConstraintBase::TSetType ();
27802702 }
27812703 }
@@ -3005,13 +2927,13 @@ class TCallableConstraintTransformer : public TCallableTransformerBase<TCallable
30052927
30062928 TPartOfConstraintBase::TSetType keys;
30072929 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 ());
30092931 if (const auto sortKeySelector = input->Child (TCoBase::idx_SortKeySelectorLambda); sortKeySelector->IsLambda ()) {
30102932 if (const auto status = UpdateLambdaConstraints (*sortKeySelector); status != TStatus::Ok) {
30112933 return status;
30122934 }
30132935
3014- auto sortKeys = GetSimpleKeys (sortKeySelector->Tail (), sortKeySelector->Head ().Head ());
2936+ auto sortKeys = GetPathsToKeys (sortKeySelector->Tail (), sortKeySelector->Head ().Head ());
30152937 std::move (sortKeys.begin (), sortKeys.end (), std::back_inserter (keys));
30162938 std::sort (keys.begin (), keys.end ());
30172939 }
0 commit comments