@@ -221,7 +221,7 @@ class TYtDataSinkExecTransformer : public TExecTransformerBase {
221
221
}
222
222
223
223
bool hasNonDeterministicFunctions = false ;
224
- if (const auto status = PeepHoleOptimizeBeforeExec< true > (optimizedNode, optimizedNode, State_, hasNonDeterministicFunctions, ctx); status.Level != TStatus::Ok) {
224
+ if (const auto status = PeepHoleOptimizeBeforeExec (optimizedNode, optimizedNode, State_, hasNonDeterministicFunctions, ctx); status.Level != TStatus::Ok) {
225
225
return SyncStatus (status);
226
226
}
227
227
@@ -628,7 +628,7 @@ class TYtDataSinkExecTransformer : public TExecTransformerBase {
628
628
}
629
629
630
630
bool hasNonDeterministicFunctions = false ;
631
- if (const auto status = PeepHoleOptimizeBeforeExec< false > (optimizedNode, optimizedNode, State_, hasNonDeterministicFunctions, ctx); status.Level != TStatus::Ok) {
631
+ if (const auto status = PeepHoleOptimizeBeforeExec (optimizedNode, optimizedNode, State_, hasNonDeterministicFunctions, ctx); status.Level != TStatus::Ok) {
632
632
return SyncStatus (status);
633
633
}
634
634
@@ -685,50 +685,100 @@ class TYtDataSinkExecTransformer : public TExecTransformerBase {
685
685
auto clusterStr = TString{cluster.Value ()};
686
686
687
687
delegatedNode = input->ChildPtr (TYtDqProcessWrite::idx_Input);
688
- if (const auto status = SubstTables (delegatedNode, State_, false , ctx); status.Level == TStatus::Error) {
689
- return SyncStatus (status);
688
+
689
+ auto server = State_->Gateway ->GetClusterServer (clusterStr);
690
+ YQL_ENSURE (server, " Invalid YT cluster: " << clusterStr);
691
+
692
+ NYT::TRichYPath realTable = State_->Gateway ->GetWriteTable (State_->SessionId , clusterStr, tmpTable.Name ().StringValue (), tmpFolder);
693
+ realTable.Append (true );
694
+ YQL_ENSURE (realTable.TransactionId_ .Defined (), " Expected TransactionId" );
695
+
696
+ NYT::TNode writerOptions = NYT::TNode::CreateMap ();
697
+ if (auto maxRowWeight = config->MaxRowWeight .Get (clusterStr)) {
698
+ writerOptions[" max_row_weight" ] = static_cast <i64>(maxRowWeight->GetValue ());
699
+ }
700
+
701
+ NYT::TNode outSpec;
702
+ NYT::TNode type;
703
+ {
704
+ auto rowSpec = TYqlRowSpecInfo (tmpTable.RowSpec ());
705
+ NYT::TNode spec;
706
+ rowSpec.FillCodecNode (spec[YqlRowSpecAttribute]);
707
+ outSpec = NYT::TNode::CreateMap ()(TString{YqlIOSpecTables}, NYT::TNode::CreateList ().Add (spec));
708
+ type = rowSpec.GetTypeNode ();
690
709
}
691
- bool hasNonDeterministicFunctions = false ;
692
- TYtExtraPeepHoleSettings settings;
693
- settings.CurrentCluster = clusterStr;
694
- settings.TmpTable = &tmpTable;
695
- settings.TmpFolder = tmpFolder;
696
- settings.Config = config;
697
- if (const auto status = PeepHoleOptimizeBeforeExec<false >(delegatedNode, delegatedNode, State_,
698
- hasNonDeterministicFunctions, ctx, settings); status.Level == TStatus::Error) {
699
- return SyncStatus (status);
710
+
711
+ // These settings will be passed to YT peephole callback from DQ
712
+ auto settings = Build<TCoNameValueTupleList>(ctx, delegatedNode->Pos ())
713
+ .Add ()
714
+ .Name ().Value (" yt_cluster" , TNodeFlags::Default).Build ()
715
+ .Value <TCoAtom>().Value (clusterStr).Build ()
716
+ .Build ()
717
+ .Add ()
718
+ .Name ().Value (" yt_server" , TNodeFlags::Default).Build ()
719
+ .Value <TCoAtom>().Value (server).Build ()
720
+ .Build ()
721
+ .Add ()
722
+ .Name ().Value (" yt_table" , TNodeFlags::Default).Build ()
723
+ .Value <TCoAtom>().Value (NYT::NodeToYsonString (NYT::PathToNode (realTable))).Build ()
724
+ .Build ()
725
+ .Add ()
726
+ .Name ().Value (" yt_tableName" , TNodeFlags::Default).Build ()
727
+ .Value <TCoAtom>().Value (tmpTable.Name ().Value ()).Build ()
728
+ .Build ()
729
+ .Add ()
730
+ .Name ().Value (" yt_tableType" , TNodeFlags::Default).Build ()
731
+ .Value <TCoAtom>().Value (NYT::NodeToYsonString (type)).Build ()
732
+ .Build ()
733
+ .Add ()
734
+ .Name ().Value (" yt_writeOptions" , TNodeFlags::Default).Build ()
735
+ .Value <TCoAtom>().Value (NYT::NodeToYsonString (writerOptions)).Build ()
736
+ .Build ()
737
+ .Add ()
738
+ .Name ().Value (" yt_outSpec" , TNodeFlags::Default).Build ()
739
+ .Value <TCoAtom>().Value (NYT::NodeToYsonString (outSpec)).Build ()
740
+ .Build ()
741
+ .Add ()
742
+ .Name ().Value (" yt_tx" , TNodeFlags::Default).Build ()
743
+ .Value <TCoAtom>().Value (GetGuidAsString (*realTable.TransactionId_ ), TNodeFlags::Default).Build ()
744
+ .Build ()
745
+ .Done ().Ptr ();
746
+
747
+ auto atomType = ctx.MakeType <TUnitExprType>();
748
+
749
+ for (auto child: settings->Children ()) {
750
+ child->Child (0 )->SetTypeAnn (atomType);
751
+ child->Child (0 )->SetState (TExprNode::EState::ConstrComplete);
752
+ child->Child (1 )->SetTypeAnn (atomType);
753
+ child->Child (1 )->SetState (TExprNode::EState::ConstrComplete);
700
754
}
701
755
702
756
delegatedNode = Build<TPull>(ctx, delegatedNode->Pos ())
703
757
.Input (std::move (delegatedNode))
704
758
.BytesLimit ()
705
759
.Value (TString ())
706
- .Build ()
760
+ .Build ()
707
761
.RowsLimit ()
708
762
.Value (0U )
709
- .Build ()
763
+ .Build ()
710
764
.FormatDetails ()
711
765
.Value (ui32 (NYson::EYsonFormat::Binary))
712
- .Build ()
713
- .Settings ()
714
- .Build ()
766
+ .Build ()
767
+ .Settings (settings)
715
768
.Format ()
716
769
.Value (0U )
717
- .Build ()
770
+ .Build ()
718
771
.PublicId ()
719
772
.Value (ToString (State_->Types ->TranslateOperationId (input->UniqueId ())))
720
- .Build ()
773
+ .Build ()
721
774
.Discard ()
722
775
.Value (ToString (true ), TNodeFlags::Default)
723
- .Build ()
776
+ .Build ()
724
777
.Origin (input)
725
- .Done ()
726
- .Ptr ();
727
-
728
- auto atomType = ctx.MakeType <TUnitExprType>();
778
+ .Done ().Ptr ();
729
779
730
780
for (auto idx: {TResOrPullBase::idx_BytesLimit, TResOrPullBase::idx_RowsLimit, TResOrPullBase::idx_FormatDetails,
731
- TResOrPullBase::idx_Format, TResOrPullBase::idx_PublicId, TResOrPullBase::idx_Discard }) {
781
+ TResOrPullBase::idx_Settings, TResOrPullBase:: idx_Format, TResOrPullBase::idx_PublicId, TResOrPullBase::idx_Discard }) {
732
782
delegatedNode->Child (idx)->SetTypeAnn (atomType);
733
783
delegatedNode->Child (idx)->SetState (TExprNode::EState::ConstrComplete);
734
784
}
0 commit comments