@@ -2694,15 +2694,44 @@ TNodePtr BuildWriteResult(TPosition pos, const TString& label, TNodePtr settings
26942694
26952695class TYqlProgramNode : public TAstListNode {
26962696public:
2697- TYqlProgramNode (TPosition pos, const TVector<TNodePtr>& blocks, bool topLevel, TScopedStatePtr scoped)
2697+ TYqlProgramNode (TPosition pos, const TVector<TNodePtr>& blocks, bool topLevel, TScopedStatePtr scoped, bool useSeq )
26982698 : TAstListNode(pos)
26992699 , Blocks(blocks)
27002700 , TopLevel(topLevel)
27012701 , Scoped(scoped)
2702+ , UseSeq(useSeq)
27022703 {}
27032704
27042705 bool DoInit (TContext& ctx, ISource* src) override {
27052706 bool hasError = false ;
2707+ INode::TPtr currentWorldsHolder;
2708+ INode::TPtr seqNode;
2709+ if (UseSeq) {
2710+ currentWorldsHolder = new TAstListNodeImpl (GetPos ());
2711+ seqNode = new TAstListNodeImpl (GetPos ());
2712+ seqNode->Add (" Seq!" ," world" );
2713+ }
2714+
2715+ INode* currentWorlds = UseSeq ? currentWorldsHolder.Get () : this ;
2716+ auto flushCurrentWorlds = [&](bool changeSeq, bool finish) {
2717+ currentWorldsHolder->Add (Y (" return" ," world" ));
2718+ auto lambda = BuildLambda (GetPos (), Y (" world" ), Y (" block" , Q (currentWorldsHolder)));
2719+ seqNode->Add (lambda);
2720+
2721+ if (finish) {
2722+ Add (Y (" let" , " world" , seqNode));
2723+ } else {
2724+ currentWorldsHolder = new TAstListNodeImpl (GetPos ());
2725+ currentWorlds = currentWorldsHolder.Get ();
2726+ }
2727+
2728+ if (changeSeq) {
2729+ Add (Y (" let" , " world" , seqNode));
2730+ seqNode = new TAstListNodeImpl (GetPos ());
2731+ seqNode->Add (" Seq!" ," world" );
2732+ }
2733+ };
2734+
27062735 if (TopLevel) {
27072736 for (auto & var: ctx.Variables ) {
27082737 if (!var.second .second ->Init (ctx, src)) {
@@ -2799,33 +2828,33 @@ class TYqlProgramNode: public TAstListNode {
27992828 auto resultSink = Y (" DataSink" , BuildQuotedAtom (Pos, TString (ResultProviderName)));
28002829
28012830 for (const auto & warningPragma : ctx.WarningPolicy .GetRules ()) {
2802- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2831+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28032832 BuildQuotedAtom (Pos, " Warning" ), BuildQuotedAtom (Pos, warningPragma.GetPattern ()),
28042833 BuildQuotedAtom (Pos, to_lower (ToString (warningPragma.GetAction ()))))));
28052834 }
28062835
28072836 if (ctx.ResultSizeLimit > 0 ) {
2808- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , resultSink,
2837+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , resultSink,
28092838 BuildQuotedAtom (Pos, " SizeLimit" ), BuildQuotedAtom (Pos, ToString (ctx.ResultSizeLimit )))));
28102839 }
28112840
28122841 if (!ctx.PragmaPullUpFlatMapOverJoin ) {
2813- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2842+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28142843 BuildQuotedAtom (Pos, " DisablePullUpFlatMapOverJoin" ))));
28152844 }
28162845
28172846 if (ctx.FilterPushdownOverJoinOptionalSide ) {
2818- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2847+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28192848 BuildQuotedAtom (Pos, " FilterPushdownOverJoinOptionalSide" ))));
28202849 }
28212850
28222851 if (!ctx.RotateJoinTree ) {
2823- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2852+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28242853 BuildQuotedAtom (Pos, " RotateJoinTree" ), BuildQuotedAtom (Pos, " false" ))));
28252854 }
28262855
28272856 if (ctx.DiscoveryMode ) {
2828- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2857+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28292858 BuildQuotedAtom (Pos, " DiscoveryMode" ))));
28302859 }
28312860
@@ -2836,12 +2865,12 @@ class TYqlProgramNode: public TAstListNode {
28362865 } else if (ctx.DqEngineForce ) {
28372866 mode = " force" ;
28382867 }
2839- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2868+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28402869 BuildQuotedAtom (Pos, " DqEngine" ), BuildQuotedAtom (Pos, mode))));
28412870 }
28422871
28432872 if (ctx.CostBasedOptimizer ) {
2844- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2873+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28452874 BuildQuotedAtom (Pos, " CostBasedOptimizer" ), BuildQuotedAtom (Pos, ctx.CostBasedOptimizer ))));
28462875 }
28472876
@@ -2851,43 +2880,43 @@ class TYqlProgramNode: public TAstListNode {
28512880 pragmaName = " JsonQueryReturnsJsonDocument" ;
28522881 }
28532882
2854- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource, BuildQuotedAtom (Pos, pragmaName))));
2883+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource, BuildQuotedAtom (Pos, pragmaName))));
28552884 }
28562885
28572886 if (ctx.OrderedColumns ) {
2858- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2887+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28592888 BuildQuotedAtom (Pos, " OrderedColumns" ))));
28602889 }
28612890
28622891 if (ctx.PqReadByRtmrCluster ) {
28632892 auto pqSourceAll = Y (" DataSource" , BuildQuotedAtom (Pos, TString (PqProviderName)), BuildQuotedAtom (Pos, " $all" ));
2864- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , pqSourceAll,
2893+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , pqSourceAll,
28652894 BuildQuotedAtom (Pos, " Attr" ), BuildQuotedAtom (Pos, " PqReadByRtmrCluster_" ), BuildQuotedAtom (Pos, ctx.PqReadByRtmrCluster ))));
28662895
28672896 auto rtmrSourceAll = Y (" DataSource" , BuildQuotedAtom (Pos, TString (RtmrProviderName)), BuildQuotedAtom (Pos, " $all" ));
2868- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , rtmrSourceAll,
2897+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , rtmrSourceAll,
28692898 BuildQuotedAtom (Pos, " Attr" ), BuildQuotedAtom (Pos, " PqReadByRtmrCluster_" ), BuildQuotedAtom (Pos, ctx.PqReadByRtmrCluster ))));
28702899
28712900 if (ctx.PqReadByRtmrCluster != " dq" ) {
28722901 // set any dynamic settings for particular RTMR cluster for CommitAll!
28732902 auto rtmrSource = Y (" DataSource" , BuildQuotedAtom (Pos, TString (RtmrProviderName)), BuildQuotedAtom (Pos, ctx.PqReadByRtmrCluster ));
2874- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , rtmrSource,
2903+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , rtmrSource,
28752904 BuildQuotedAtom (Pos, " Attr" ), BuildQuotedAtom (Pos, " Dummy_" ), BuildQuotedAtom (Pos, " 1" ))));
28762905 }
28772906 }
28782907
28792908 if (ctx.YsonCastToString .Defined ()) {
28802909 const TString pragmaName = *ctx.YsonCastToString ? " YsonCastToString" : " DisableYsonCastToString" ;
2881- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource, BuildQuotedAtom (Pos, pragmaName))));
2910+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource, BuildQuotedAtom (Pos, pragmaName))));
28822911 }
28832912
28842913 if (ctx.UseBlocks ) {
2885- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource, BuildQuotedAtom (Pos, " UseBlocks" ))));
2914+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource, BuildQuotedAtom (Pos, " UseBlocks" ))));
28862915 }
28872916
28882917 if (ctx.BlockEngineEnable ) {
28892918 TString mode = ctx.BlockEngineForce ? " force" : " auto" ;
2890- Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
2919+ currentWorlds-> Add (Y (" let" , " world" , Y (TString (ConfigureName), " world" , configSource,
28912920 BuildQuotedAtom (Pos, " BlockEngine" ), BuildQuotedAtom (Pos, mode))));
28922921 }
28932922 }
@@ -2915,22 +2944,41 @@ class TYqlProgramNode: public TAstListNode {
29152944 Add (Y (" let" , data.first , node));
29162945 }
29172946
2947+ if (UseSeq) {
2948+ flushCurrentWorlds (false , false );
2949+ }
2950+
29182951 for (auto & block: Blocks) {
29192952 const auto subqueryAliasPtr = block->SubqueryAlias ();
29202953 if (subqueryAliasPtr) {
29212954 if (block->UsedSubquery ()) {
2955+ if (UseSeq) {
2956+ flushCurrentWorlds (true , false );
2957+ }
2958+
29222959 const auto & ref = block->GetLabel ();
29232960 YQL_ENSURE (!ref.empty ());
29242961 Add (block);
2925- Add (Y (" let" , " world" , Y (" Nth" , *subqueryAliasPtr, Q (" 0" ))));
2962+ currentWorlds-> Add (Y (" let" , " world" , Y (" Nth" , *subqueryAliasPtr, Q (" 0" ))));
29262963 Add (Y (" let" , ref, Y (" Nth" , *subqueryAliasPtr, Q (" 1" ))));
29272964 }
29282965 } else {
29292966 const auto & ref = block->GetLabel ();
2930- Add (Y (" let" , ref ? ref : " world" , block));
2967+ if (ref) {
2968+ Add (Y (" let" , ref, block));
2969+ } else {
2970+ currentWorlds->Add (Y (" let" , " world" , block));
2971+ if (UseSeq) {
2972+ flushCurrentWorlds (false , false );
2973+ }
2974+ }
29312975 }
29322976 }
29332977
2978+ if (UseSeq) {
2979+ flushCurrentWorlds (false , true );
2980+ }
2981+
29342982 if (TopLevel) {
29352983 if (ctx.UniversalAliases ) {
29362984 decltype (Nodes) preparedNodes;
@@ -2975,10 +3023,11 @@ class TYqlProgramNode: public TAstListNode {
29753023 TVector<TNodePtr> Blocks;
29763024 const bool TopLevel;
29773025 TScopedStatePtr Scoped;
3026+ const bool UseSeq;
29783027};
29793028
2980- TNodePtr BuildQuery (TPosition pos, const TVector<TNodePtr>& blocks, bool topLevel, TScopedStatePtr scoped) {
2981- return new TYqlProgramNode (pos, blocks, topLevel, scoped);
3029+ TNodePtr BuildQuery (TPosition pos, const TVector<TNodePtr>& blocks, bool topLevel, TScopedStatePtr scoped, bool useSeq ) {
3030+ return new TYqlProgramNode (pos, blocks, topLevel, scoped, useSeq );
29823031}
29833032
29843033class TPragmaNode final : public INode {
0 commit comments