operation.h 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672
  1. #pragma once
  2. ///
  3. /// @file yt/cpp/mapreduce/interface/operation.h
  4. ///
  5. /// Header containing interface to run operations in YT
  6. /// and retrieve information about them.
  7. /// @see [the doc](https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/map_reduce_overview.html).
  8. #include "client_method_options.h"
  9. #include "errors.h"
  10. #include "io.h"
  11. #include "job_statistics.h"
  12. #include "job_counters.h"
  13. #include <library/cpp/threading/future/future.h>
  14. #include <library/cpp/type_info/type_info.h>
  15. #include <util/datetime/base.h>
  16. #include <util/generic/vector.h>
  17. #include <util/generic/maybe.h>
  18. #include <util/system/file.h>
  19. #include <util/system/types.h>
  20. #include <variant>
  21. namespace NYT {
  22. ////////////////////////////////////////////////////////////////////////////////
  23. /// Tag class marking that the row type for table is not specified.
  24. struct TUnspecifiedTableStructure
  25. { };
  26. /// Tag class marking that table rows have protobuf type.
  27. struct TProtobufTableStructure
  28. {
  29. /// @brief Descriptor of the protobuf type of table rows.
  30. ///
  31. /// @note If table is tagged with @ref ::google::protobuf::Message instead of real proto class
  32. /// this descriptor might be null.
  33. const ::google::protobuf::Descriptor* Descriptor = nullptr;
  34. };
  35. /// Tag class to specify table row type.
  36. using TTableStructure = std::variant<
  37. TUnspecifiedTableStructure,
  38. TProtobufTableStructure
  39. >;
  40. bool operator==(const TUnspecifiedTableStructure&, const TUnspecifiedTableStructure&);
  41. bool operator==(const TProtobufTableStructure& lhs, const TProtobufTableStructure& rhs);
  42. /// Table path marked with @ref NYT::TTableStructure tag.
  43. struct TStructuredTablePath
  44. {
  45. TStructuredTablePath(TRichYPath richYPath = TRichYPath(), TTableStructure description = TUnspecifiedTableStructure())
  46. : RichYPath(std::move(richYPath))
  47. , Description(std::move(description))
  48. { }
  49. TStructuredTablePath(TRichYPath richYPath, const ::google::protobuf::Descriptor* descriptor)
  50. : RichYPath(std::move(richYPath))
  51. , Description(TProtobufTableStructure({descriptor}))
  52. { }
  53. TStructuredTablePath(TYPath path)
  54. : RichYPath(std::move(path))
  55. , Description(TUnspecifiedTableStructure())
  56. { }
  57. TStructuredTablePath(const char* path)
  58. : RichYPath(path)
  59. , Description(TUnspecifiedTableStructure())
  60. { }
  61. TRichYPath RichYPath;
  62. TTableStructure Description;
  63. };
  64. /// Create marked table path from row type.
  65. template <typename TRow>
  66. TStructuredTablePath Structured(TRichYPath richYPath);
  67. /// Create tag class from row type.
  68. template <typename TRow>
  69. TTableStructure StructuredTableDescription();
  70. ////////////////////////////////////////////////////////////////////////////////
  71. /// Tag class marking that row stream is empty.
  72. struct TVoidStructuredRowStream
  73. { };
  74. /// Tag class marking that row stream consists of `NYT::TNode`.
  75. struct TTNodeStructuredRowStream
  76. { };
  77. /// Tag class marking that row stream consists of @ref NYT::TYaMRRow.
  78. struct TTYaMRRowStructuredRowStream
  79. { };
  80. /// Tag class marking that row stream consists of protobuf rows of given type.
  81. struct TProtobufStructuredRowStream
  82. {
  83. /// @brief Descriptor of the protobuf type of table rows.
  84. ///
  85. /// @note If `Descriptor` is nullptr, then row stream consists of multiple message types.
  86. const ::google::protobuf::Descriptor* Descriptor = nullptr;
  87. };
  88. /// Tag class to specify type of rows in an operation row stream
  89. using TStructuredRowStreamDescription = std::variant<
  90. TVoidStructuredRowStream,
  91. TTNodeStructuredRowStream,
  92. TTYaMRRowStructuredRowStream,
  93. TProtobufStructuredRowStream
  94. >;
  95. ////////////////////////////////////////////////////////////////////////////////
  96. /// Tag class marking that current binary should be used in operation.
  97. struct TJobBinaryDefault
  98. { };
  99. /// Tag class marking that binary from specified local path should be used in operation.
  100. struct TJobBinaryLocalPath
  101. {
  102. TString Path;
  103. TMaybe<TString> MD5CheckSum;
  104. };
  105. /// Tag class marking that binary from specified Cypress path should be used in operation.
  106. struct TJobBinaryCypressPath
  107. {
  108. TYPath Path;
  109. TMaybe<TTransactionId> TransactionId;
  110. };
  111. ////////////////////////////////////////////////////////////////////////////////
  112. /// @cond Doxygen_Suppress
  113. namespace NDetail {
  114. extern i64 OutputTableCount;
  115. } // namespace NDetail
  116. /// @endcond
  117. ////////////////////////////////////////////////////////////////////////////////
  118. ///
  119. /// @brief Auto merge mode.
  120. ///
  121. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/automerge
  122. enum class EAutoMergeMode
  123. {
  124. /// Auto merge is disabled.
  125. Disabled /* "disabled" */,
  126. /// Mode that tries to achieve good chunk sizes and doesn't limit usage of chunk quota for intermediate chunks.
  127. Relaxed /* "relaxed" */,
  128. /// Mode that tries to optimize usage of chunk quota for intermediate chunks, operation might run slower.
  129. Economy /* "economy" */,
  130. ///
  131. /// @brief Manual configuration of automerge parameters.
  132. ///
  133. /// @ref TAutoMergeSpec
  134. Manual /* "manual" */,
  135. };
  136. ///
  137. /// @brief Options for auto merge operation stage.
  138. ///
  139. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/automerge
  140. class TAutoMergeSpec
  141. {
  142. public:
  143. /// @cond Doxygen_Suppress
  144. using TSelf = TAutoMergeSpec;
  145. /// @endcond
  146. /// Mode of the auto merge.
  147. FLUENT_FIELD_OPTION(EAutoMergeMode, Mode);
  148. /// @brief Upper limit for number of intermediate chunks.
  149. ///
  150. /// Works only for Manual mode.
  151. FLUENT_FIELD_OPTION(i64, MaxIntermediateChunkCount);
  152. /// @brief Number of chunks limit to merge in one job.
  153. ///
  154. /// Works only for Manual mode.
  155. FLUENT_FIELD_OPTION(i64, ChunkCountPerMergeJob);
  156. /// @brief Automerge will not merge chunks that are larger than `DesiredChunkSize * (ChunkSizeThreshold / 100.)`
  157. ///
  158. /// Works only for Manual mode.
  159. FLUENT_FIELD_OPTION(i64, ChunkSizeThreshold);
  160. };
  161. /// Base for operations with auto merge options.
  162. template <class TDerived>
  163. class TWithAutoMergeSpec
  164. {
  165. public:
  166. /// @cond Doxygen_Suppress
  167. using TSelf = TDerived;
  168. /// @endcond
  169. /// @brief Options for auto merge operation stage.
  170. ///
  171. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/automerge
  172. FLUENT_FIELD_OPTION(TAutoMergeSpec, AutoMerge);
  173. };
  174. ///
  175. /// @brief Resources controlled by scheduler and used by running operations.
  176. ///
  177. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/scheduler/scheduler-and-pools#resources
  178. class TSchedulerResources
  179. {
  180. public:
  181. /// @cond Doxygen_Suppress
  182. using TSelf = TSchedulerResources;
  183. /// @endcond
  184. /// Each job consumes exactly one user slot.
  185. FLUENT_FIELD_OPTION_ENCAPSULATED(i64, UserSlots);
  186. /// Number of (virtual) cpu cores consumed by all jobs.
  187. FLUENT_FIELD_OPTION_ENCAPSULATED(i64, Cpu);
  188. /// Amount of memory in bytes.
  189. FLUENT_FIELD_OPTION_ENCAPSULATED(i64, Memory);
  190. };
  191. /// Base for input format hints of a user job.
  192. template <class TDerived>
  193. class TUserJobInputFormatHintsBase
  194. {
  195. public:
  196. /// @cond Doxygen_Suppress
  197. using TSelf = TDerived;
  198. /// @endcond
  199. /// @brief Fine tune input format of the job.
  200. FLUENT_FIELD_OPTION(TFormatHints, InputFormatHints);
  201. };
  202. /// Base for output format hints of a user job.
  203. template <class TDerived>
  204. class TUserJobOutputFormatHintsBase
  205. {
  206. public:
  207. /// @cond Doxygen_Suppress
  208. using TSelf = TDerived;
  209. /// @endcond
  210. /// @brief Fine tune output format of the job.
  211. FLUENT_FIELD_OPTION(TFormatHints, OutputFormatHints);
  212. };
  213. /// Base for format hints of a user job.
  214. template <class TDerived>
  215. class TUserJobFormatHintsBase
  216. : public TUserJobInputFormatHintsBase<TDerived>
  217. , public TUserJobOutputFormatHintsBase<TDerived>
  218. {
  219. public:
  220. /// @cond Doxygen_Suppress
  221. using TSelf = TDerived;
  222. /// @endcond
  223. };
  224. /// User job format hints.
  225. class TUserJobFormatHints
  226. : public TUserJobFormatHintsBase<TUserJobFormatHints>
  227. { };
  228. /// Spec of input and output tables of a raw operation.
  229. template <class TDerived>
  230. class TRawOperationIoTableSpec
  231. {
  232. public:
  233. /// @cond Doxygen_Suppress
  234. using TSelf = TDerived;
  235. /// @endcond
  236. /// Add input table path to input path list.
  237. TDerived& AddInput(const TRichYPath& path);
  238. /// Set input table path no. `tableIndex`.
  239. TDerived& SetInput(size_t tableIndex, const TRichYPath& path);
  240. /// Add output table path to output path list.
  241. TDerived& AddOutput(const TRichYPath& path);
  242. /// Set output table path no. `tableIndex`.
  243. TDerived& SetOutput(size_t tableIndex, const TRichYPath& path);
  244. /// Get all input table paths.
  245. const TVector<TRichYPath>& GetInputs() const;
  246. /// Get all output table paths.
  247. const TVector<TRichYPath>& GetOutputs() const;
  248. private:
  249. TVector<TRichYPath> Inputs_;
  250. TVector<TRichYPath> Outputs_;
  251. };
  252. /// Base spec for IO in "simple" raw operations (Map, Reduce etc.).
  253. template <class TDerived>
  254. struct TSimpleRawOperationIoSpec
  255. : public TRawOperationIoTableSpec<TDerived>
  256. {
  257. /// @cond Doxygen_Suppress
  258. using TSelf = TDerived;
  259. /// @endcond
  260. /// @brief Describes format for both input and output.
  261. ///
  262. /// @note `Format' is overridden by `InputFormat' and `OutputFormat'.
  263. FLUENT_FIELD_OPTION(TFormat, Format);
  264. /// Describes input format.
  265. FLUENT_FIELD_OPTION(TFormat, InputFormat);
  266. /// Describes output format.
  267. FLUENT_FIELD_OPTION(TFormat, OutputFormat);
  268. };
  269. /// Spec for IO in MapReduce operation.
  270. template <class TDerived>
  271. class TRawMapReduceOperationIoSpec
  272. : public TRawOperationIoTableSpec<TDerived>
  273. {
  274. public:
  275. /// @cond Doxygen_Suppress
  276. using TSelf = TDerived;
  277. /// @endcond
  278. /// @brief Describes format for both input and output of mapper.
  279. ///
  280. /// @note `MapperFormat' is overridden by `MapperInputFormat' and `MapperOutputFormat'.
  281. FLUENT_FIELD_OPTION(TFormat, MapperFormat);
  282. /// Describes mapper input format.
  283. FLUENT_FIELD_OPTION(TFormat, MapperInputFormat);
  284. /// Describes mapper output format.
  285. FLUENT_FIELD_OPTION(TFormat, MapperOutputFormat);
  286. /// @brief Describes format for both input and output of reduce combiner.
  287. ///
  288. /// @note `ReduceCombinerFormat' is overridden by `ReduceCombinerInputFormat' and `ReduceCombinerOutputFormat'.
  289. FLUENT_FIELD_OPTION(TFormat, ReduceCombinerFormat);
  290. /// Describes reduce combiner input format.
  291. FLUENT_FIELD_OPTION(TFormat, ReduceCombinerInputFormat);
  292. /// Describes reduce combiner output format.
  293. FLUENT_FIELD_OPTION(TFormat, ReduceCombinerOutputFormat);
  294. /// @brief Describes format for both input and output of reducer.
  295. ///
  296. /// @note `ReducerFormat' is overridden by `ReducerInputFormat' and `ReducerOutputFormat'.
  297. FLUENT_FIELD_OPTION(TFormat, ReducerFormat);
  298. /// Describes reducer input format.
  299. FLUENT_FIELD_OPTION(TFormat, ReducerInputFormat);
  300. /// Describes reducer output format.
  301. FLUENT_FIELD_OPTION(TFormat, ReducerOutputFormat);
  302. /// Add direct map output table path.
  303. TDerived& AddMapOutput(const TRichYPath& path);
  304. /// Set direct map output table path no. `tableIndex`.
  305. TDerived& SetMapOutput(size_t tableIndex, const TRichYPath& path);
  306. /// Get all direct map output table paths
  307. const TVector<TRichYPath>& GetMapOutputs() const;
  308. private:
  309. TVector<TRichYPath> MapOutputs_;
  310. };
  311. ///
  312. /// @brief Base spec of operations with input tables.
  313. class TOperationInputSpecBase
  314. {
  315. public:
  316. template <class T, class = void>
  317. struct TFormatAdder;
  318. ///
  319. /// @brief Add input table path to input path list and specify type of rows.
  320. template <class T>
  321. void AddInput(const TRichYPath& path);
  322. ///
  323. /// @brief Add input table path as structured paths.
  324. void AddStructuredInput(TStructuredTablePath path);
  325. ///
  326. /// @brief Set input table path and type.
  327. template <class T>
  328. void SetInput(size_t tableIndex, const TRichYPath& path);
  329. ///
  330. /// @brief All input paths.
  331. TVector<TRichYPath> Inputs_;
  332. ///
  333. /// @brief Get all input structured paths.
  334. const TVector<TStructuredTablePath>& GetStructuredInputs() const;
  335. private:
  336. TVector<TStructuredTablePath> StructuredInputs_;
  337. friend struct TOperationIOSpecBase;
  338. template <class T>
  339. friend struct TOperationIOSpec;
  340. };
  341. ///
  342. /// @brief Base spec of operations with output tables.
  343. class TOperationOutputSpecBase
  344. {
  345. public:
  346. template <class T, class = void>
  347. struct TFormatAdder;
  348. ///
  349. /// @brief Add output table path to output path list and specify type of rows.
  350. template <class T>
  351. void AddOutput(const TRichYPath& path);
  352. ///
  353. /// @brief Add output table path as structured paths.
  354. void AddStructuredOutput(TStructuredTablePath path);
  355. ///
  356. /// @brief Set output table path and type.
  357. template <class T>
  358. void SetOutput(size_t tableIndex, const TRichYPath& path);
  359. ///
  360. /// @brief All output paths.
  361. TVector<TRichYPath> Outputs_;
  362. ///
  363. /// @brief Get all output structured paths.
  364. const TVector<TStructuredTablePath>& GetStructuredOutputs() const;
  365. private:
  366. TVector<TStructuredTablePath> StructuredOutputs_;
  367. friend struct TOperationIOSpecBase;
  368. template <class T>
  369. friend struct TOperationIOSpec;
  370. };
  371. ///
  372. /// @brief Base spec for operations with inputs and outputs.
  373. struct TOperationIOSpecBase
  374. : public TOperationInputSpecBase
  375. , public TOperationOutputSpecBase
  376. { };
  377. ///
  378. /// @brief Base spec for operations with inputs and outputs.
  379. template <class TDerived>
  380. struct TOperationIOSpec
  381. : public TOperationIOSpecBase
  382. {
  383. /// @cond Doxygen_Suppress
  384. using TSelf = TDerived;
  385. /// @endcond
  386. template <class T>
  387. TDerived& AddInput(const TRichYPath& path);
  388. TDerived& AddStructuredInput(TStructuredTablePath path);
  389. template <class T>
  390. TDerived& SetInput(size_t tableIndex, const TRichYPath& path);
  391. template <class T>
  392. TDerived& AddOutput(const TRichYPath& path);
  393. TDerived& AddStructuredOutput(TStructuredTablePath path);
  394. template <class T>
  395. TDerived& SetOutput(size_t tableIndex, const TRichYPath& path);
  396. // DON'T USE THESE METHODS! They are left solely for backward compatibility.
  397. // These methods are the only way to do equivalent of (Add/Set)(Input/Output)<Message>
  398. // but please consider using (Add/Set)(Input/Output)<TConcreteMessage>
  399. // (where TConcreteMessage is some descendant of Message)
  400. // because they are faster and better (see https://st.yandex-team.ru/YT-6967)
  401. TDerived& AddProtobufInput_VerySlow_Deprecated(const TRichYPath& path);
  402. TDerived& AddProtobufOutput_VerySlow_Deprecated(const TRichYPath& path);
  403. };
  404. ///
  405. /// @brief Base spec for all operations.
  406. ///
  407. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/operations_options
  408. template <class TDerived>
  409. struct TOperationSpecBase
  410. {
  411. /// @cond Doxygen_Suppress
  412. using TSelf = TDerived;
  413. /// @endcond
  414. ///
  415. /// @brief Limit on operation execution time.
  416. ///
  417. /// If operation doesn't finish in time it will be aborted.
  418. FLUENT_FIELD_OPTION(TDuration, TimeLimit);
  419. /// @brief Title to be shown in web interface.
  420. FLUENT_FIELD_OPTION(TString, Title);
  421. /// @brief Pool to be used for this operation.
  422. FLUENT_FIELD_OPTION(TString, Pool);
  423. /// @brief Weight of operation.
  424. ///
  425. /// Coefficient defining how much resources operation gets relative to its siblings in the same pool.
  426. FLUENT_FIELD_OPTION(double, Weight);
  427. /// @brief Pool tree list that operation will use.
  428. FLUENT_OPTIONAL_VECTOR_FIELD_ENCAPSULATED(TString, PoolTree);
  429. /// How much resources can be consumed by operation.
  430. FLUENT_FIELD_OPTION_ENCAPSULATED(TSchedulerResources, ResourceLimits);
  431. /// How many jobs can fail before operation is failed.
  432. FLUENT_FIELD_OPTION(ui64, MaxFailedJobCount);
  433. // Arbitrary structured information related to the operation.
  434. FLUENT_FIELD_OPTION(TNode, Annotations);
  435. // Similar to Annotations, shown on the operation page. Recommends concise, human-readable entries to prevent clutter.
  436. FLUENT_FIELD_OPTION(TNode, Description);
  437. };
  438. ///
  439. /// @brief Base spec for all operations with user jobs.
  440. template <class TDerived>
  441. struct TUserOperationSpecBase
  442. : TOperationSpecBase<TDerived>
  443. {
  444. /// @cond Doxygen_Suppress
  445. using TSelf = TDerived;
  446. /// @endcond
  447. /// On any unsuccessful job completion (i.e. abortion or failure) force the whole operation to fail.
  448. FLUENT_FIELD_OPTION(bool, FailOnJobRestart);
  449. ///
  450. /// @brief Table to save whole stderr of operation.
  451. ///
  452. /// @see https://clubs.at.yandex-team.ru/yt/1045
  453. FLUENT_FIELD_OPTION(TYPath, StderrTablePath);
  454. ///
  455. /// @brief Table to save coredumps of operation.
  456. ///
  457. /// @see https://clubs.at.yandex-team.ru/yt/1045
  458. FLUENT_FIELD_OPTION(TYPath, CoreTablePath);
  459. ///
  460. /// @brief How long should the scheduler wait for the job to be started on a node.
  461. ///
  462. /// When you run huge jobs that require preemption of all the other jobs on
  463. /// a node, the default timeout might be insufficient and your job may be
  464. /// aborted with 'waiting_timeout' reason. This is especially problematic
  465. /// when you are setting 'FailOnJobRestart' option.
  466. ///
  467. /// @note The value must be between 10 seconds and 10 minutes.
  468. FLUENT_FIELD_OPTION(TDuration, WaitingJobTimeout);
  469. };
  470. ///
  471. /// @brief Class to provide information on intermediate mapreduce stream protobuf types.
  472. ///
  473. /// When using protobuf format it is important to know exact types of proto messages
  474. /// that are used in input/output.
  475. ///
  476. /// Sometimes such messages cannot be derived from job class
  477. /// i.e. when job class uses `NYT::TTableReader<::google::protobuf::Message>`
  478. /// or `NYT::TTableWriter<::google::protobuf::Message>`.
  479. ///
  480. /// When using such jobs user can provide exact message type using this class.
  481. ///
  482. /// @note Only input/output that relate to intermediate tables can be hinted.
  483. /// Input to map and output of reduce is derived from `AddInput`/`AddOutput`.
  484. template <class TDerived>
  485. struct TIntermediateTablesHintSpec
  486. {
  487. /// Specify intermediate map output type.
  488. template <class T>
  489. TDerived& HintMapOutput();
  490. /// Specify reduce combiner input.
  491. template <class T>
  492. TDerived& HintReduceCombinerInput();
  493. /// Specify reduce combiner output.
  494. template <class T>
  495. TDerived& HintReduceCombinerOutput();
  496. /// Specify reducer input.
  497. template <class T>
  498. TDerived& HintReduceInput();
  499. ///
  500. /// @brief Add output of map stage.
  501. ///
  502. /// Mapper output table #0 is always intermediate table that is going to be reduced later.
  503. /// Rows that mapper write to tables #1, #2, ... are saved in MapOutput tables.
  504. template <class T>
  505. TDerived& AddMapOutput(const TRichYPath& path);
  506. TVector<TRichYPath> MapOutputs_;
  507. const TVector<TStructuredTablePath>& GetStructuredMapOutputs() const;
  508. const TMaybe<TTableStructure>& GetIntermediateMapOutputDescription() const;
  509. const TMaybe<TTableStructure>& GetIntermediateReduceCombinerInputDescription() const;
  510. const TMaybe<TTableStructure>& GetIntermediateReduceCombinerOutputDescription() const;
  511. const TMaybe<TTableStructure>& GetIntermediateReducerInputDescription() const;
  512. private:
  513. TVector<TStructuredTablePath> StructuredMapOutputs_;
  514. TMaybe<TTableStructure> IntermediateMapOutputDescription_;
  515. TMaybe<TTableStructure> IntermediateReduceCombinerInputDescription_;
  516. TMaybe<TTableStructure> IntermediateReduceCombinerOutputDescription_;
  517. TMaybe<TTableStructure> IntermediateReducerInputDescription_;
  518. };
  519. ////////////////////////////////////////////////////////////////////////////////
  520. struct TAddLocalFileOptions
  521. {
  522. /// @cond Doxygen_Suppress
  523. using TSelf = TAddLocalFileOptions;
  524. /// @endcond
  525. ///
  526. /// @brief Path by which job will see the uploaded file.
  527. ///
  528. /// Defaults to basename of the local path.
  529. FLUENT_FIELD_OPTION(TString, PathInJob);
  530. ///
  531. /// @brief MD5 checksum of uploaded file.
  532. ///
  533. /// If not specified it is computed by this library.
  534. /// If this argument is provided, the user can some cpu and disk IO.
  535. FLUENT_FIELD_OPTION(TString, MD5CheckSum);
  536. ///
  537. /// @brief Do not put file into node cache
  538. ///
  539. /// @see NYT::TRichYPath::BypassArtifactCache
  540. FLUENT_FIELD_OPTION(bool, BypassArtifactCache);
  541. };
  542. ////////////////////////////////////////////////////////////////////////////////
  543. /// @brief Binary to run job profiler on.
  544. enum class EProfilingBinary
  545. {
  546. /// Profile job proxy.
  547. JobProxy /* "job_proxy" */,
  548. /// Profile user job.
  549. UserJob /* "user_job" */,
  550. };
  551. /// @brief Type of job profiler.
  552. enum class EProfilerType
  553. {
  554. /// Profile CPU usage.
  555. Cpu /* "cpu" */,
  556. /// Profile memory usage.
  557. Memory /* "memory" */,
  558. /// Profiler peak memory usage.
  559. PeakMemory /* "peak_memory" */,
  560. };
  561. /// @brief Specifies a job profiler.
  562. struct TJobProfilerSpec
  563. {
  564. /// @cond Doxygen_Suppress
  565. using TSelf = TJobProfilerSpec;
  566. /// @endcond
  567. /// @brief Binary to profile.
  568. FLUENT_FIELD_OPTION(EProfilingBinary, ProfilingBinary);
  569. /// @brief Type of the profiler.
  570. FLUENT_FIELD_OPTION(EProfilerType, ProfilerType);
  571. /// @brief Probability of the job being selected for profiling.
  572. FLUENT_FIELD_OPTION(double, ProfilingProbability);
  573. /// @brief For sampling profilers, sets the number of samples per second.
  574. FLUENT_FIELD_OPTION(int, SamplingFrequency);
  575. };
  576. ////////////////////////////////////////////////////////////////////////////////
  577. /// @brief Specification of a disk that will be available in job.
  578. ///
  579. /// Disk request should be used in case job requires specific requirements for disk (i.e. it requires NVME or SSD).
  580. ///
  581. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/operations-options#disk_request
  582. struct TDiskRequest
  583. {
  584. /// @cond Doxygen_Suppress
  585. using TSelf = TDiskRequest;
  586. /// @endcond
  587. /// Required disk space in bytes.
  588. FLUENT_FIELD_OPTION(i64, DiskSpace);
  589. /// Limit for inodes.
  590. FLUENT_FIELD_OPTION(i64, InodeCount);
  591. /// Account which quota is going to be used.
  592. /// Account must have available quota for the specified medium.
  593. FLUENT_FIELD_OPTION(TString, Account);
  594. /// Name of the medium corresponding to required disk type.
  595. FLUENT_FIELD_OPTION(TString, MediumName);
  596. };
  597. ////////////////////////////////////////////////////////////////////////////////
  598. ///
  599. /// @brief Spec of user job.
  600. ///
  601. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/operations-options#user_script_options
  602. struct TUserJobSpec
  603. {
  604. /// @cond Doxygen_Suppress
  605. using TSelf = TUserJobSpec;
  606. /// @endcond
  607. ///
  608. /// @brief Specify a local file to upload to Cypress and prepare for use in job.
  609. TSelf& AddLocalFile(const TLocalFilePath& path, const TAddLocalFileOptions& options = TAddLocalFileOptions());
  610. ///
  611. /// @brief Get the list of all added local files.
  612. TVector<std::tuple<TLocalFilePath, TAddLocalFileOptions>> GetLocalFiles() const;
  613. /// @brief Paths to files in Cypress to use in job.
  614. FLUENT_VECTOR_FIELD(TRichYPath, File);
  615. /// @brief Porto layers to use in the job. Layers are listed from top to bottom.
  616. FLUENT_VECTOR_FIELD(TYPath, Layer);
  617. /// @brief Docker image to use in the job.
  618. FLUENT_FIELD_OPTION(TString, DockerImage);
  619. ///
  620. /// @brief MemoryLimit specifies how much memory job process can use.
  621. ///
  622. /// @note
  623. /// If job uses tmpfs (check @ref NYT::TOperationOptions::MountSandboxInTmpfs)
  624. /// YT computes its memory usage as total of:
  625. /// - memory usage of job process itself (including mapped files);
  626. /// - total size of tmpfs used by this job.
  627. ///
  628. /// @note
  629. /// When @ref NYT::TOperationOptions::MountSandboxInTmpfs is enabled library will compute
  630. /// total size of all files used by this job and add this total size to MemoryLimit.
  631. /// Thus, you shouldn't include size of your files (e.g. binary file) into MemoryLimit.
  632. ///
  633. /// @note
  634. /// Final memory memory_limit passed to YT is calculated as follows:
  635. ///
  636. /// @note
  637. /// ```
  638. /// memory_limit = MemoryLimit + <total-size-of-used-files> + ExtraTmpfsSize
  639. /// ```
  640. ///
  641. /// @see NYT::TUserJobSpec::ExtraTmpfsSize
  642. FLUENT_FIELD_OPTION(i64, MemoryLimit);
  643. ///
  644. /// @brief Size of data that is going to be written to tmpfs.
  645. ///
  646. /// This option should be used if job writes data to tmpfs.
  647. ///
  648. /// ExtraTmpfsSize should not include size of files specified with
  649. /// @ref NYT::TUserJobSpec::AddLocalFile or @ref NYT::TUserJobSpec::AddFile
  650. /// These files are copied to tmpfs automatically and their total size
  651. /// is computed automatically.
  652. ///
  653. /// @see NYT::TOperationOptions::MountSandboxInTmpfs
  654. /// @see NYT::TUserJobSpec::MemoryLimit
  655. FLUENT_FIELD_OPTION(i64, ExtraTmpfsSize);
  656. ///
  657. /// @brief Maximum number of CPU cores for a single job to use.
  658. FLUENT_FIELD_OPTION(double, CpuLimit);
  659. ///
  660. /// @brief Fraction of @ref NYT::TUserJobSpec::MemoryLimit that job gets at start.
  661. ///
  662. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/operations-options#memory_reserve_factor
  663. FLUENT_FIELD_OPTION(double, MemoryReserveFactor);
  664. ///
  665. /// @brief Local path to executable to be used inside jobs.
  666. ////
  667. /// Provided executable must use C++ YT API library (this library)
  668. /// and implement job class that is going to be used.
  669. ///
  670. /// This option might be useful if we want to start operation from nonlinux machines
  671. /// (in that case we use `JobBinary` to provide path to the same program compiled for linux).
  672. /// Other example of using this option is uploading executable to cypress in advance
  673. /// and save the time required to upload current executable to cache.
  674. /// `md5` argument can be used to save cpu time and disk IO when binary MD5 checksum is known.
  675. /// When argument is not provided library will compute it itself.
  676. TUserJobSpec& JobBinaryLocalPath(TString path, TMaybe<TString> md5 = Nothing());
  677. ///
  678. /// @brief Cypress path to executable to be used inside jobs.
  679. TUserJobSpec& JobBinaryCypressPath(TString path, TMaybe<TTransactionId> transactionId = Nothing());
  680. ///
  681. /// @brief String that will be prepended to the command.
  682. ///
  683. /// This option overrides @ref NYT::TOperationOptions::JobCommandPrefix.
  684. FLUENT_FIELD(TString, JobCommandPrefix);
  685. ///
  686. /// @brief String that will be appended to the command.
  687. ///
  688. /// This option overrides @ref NYT::TOperationOptions::JobCommandSuffix.
  689. FLUENT_FIELD(TString, JobCommandSuffix);
  690. ///
  691. /// @brief Map of environment variables that will be set for jobs.
  692. FLUENT_MAP_FIELD(TString, TString, Environment);
  693. ///
  694. /// @brief Limit for all files inside job sandbox (in bytes).
  695. FLUENT_FIELD_OPTION(ui64, DiskSpaceLimit);
  696. ///
  697. /// @brief Number of ports reserved for the job (passed through environment in YT_PORT_0, YT_PORT_1, ...).
  698. FLUENT_FIELD_OPTION(ui16, PortCount);
  699. ///
  700. /// @brief Network project used to isolate job network.
  701. FLUENT_FIELD_OPTION(TString, NetworkProject);
  702. ///
  703. /// @brief Limit on job execution time.
  704. ///
  705. /// Jobs that exceed this limit will be considered failed.
  706. FLUENT_FIELD_OPTION(TDuration, JobTimeLimit);
  707. ///
  708. /// @brief Get job binary config.
  709. const TJobBinaryConfig& GetJobBinary() const;
  710. ///
  711. /// @brief List of profilers to run.
  712. FLUENT_VECTOR_FIELD(TJobProfilerSpec, JobProfiler);
  713. ///
  714. /// @brief Specification of a disk required for job.
  715. ///
  716. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/operations-options#disk_request
  717. FLUENT_FIELD_OPTION(TDiskRequest, DiskRequest);
  718. private:
  719. TVector<std::tuple<TLocalFilePath, TAddLocalFileOptions>> LocalFiles_;
  720. TJobBinaryConfig JobBinary_;
  721. };
  722. ////////////////////////////////////////////////////////////////////////////////
  723. ///
  724. /// @brief Spec of Map operation.
  725. ///
  726. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/map
  727. template <typename TDerived>
  728. struct TMapOperationSpecBase
  729. : public TUserOperationSpecBase<TDerived>
  730. , public TWithAutoMergeSpec<TDerived>
  731. {
  732. /// @cond Doxygen_Suppress
  733. using TSelf = TDerived;
  734. /// @endcond
  735. ///
  736. /// @brief Spec of mapper job.
  737. FLUENT_FIELD(TUserJobSpec, MapperSpec);
  738. ///
  739. /// @brief Whether to guarantee the order of rows passed to mapper matches the order in the table.
  740. ///
  741. /// When `Ordered' is false (by default), there is no guaranties about order of reading rows.
  742. /// In this case mapper might work slightly faster because row delivered from fast node can be processed YT waits
  743. /// response from slow nodes.
  744. /// When `Ordered' is true, rows will come in order in which they are stored in input tables.
  745. FLUENT_FIELD_OPTION(bool, Ordered);
  746. ///
  747. /// @brief Recommended number of jobs to run.
  748. ///
  749. /// `JobCount' has higher priority than @ref NYT::TMapOperationSpecBase::DataSizePerJob.
  750. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  751. FLUENT_FIELD_OPTION(ui32, JobCount);
  752. ///
  753. /// @brief Recommended of data size for each job.
  754. ///
  755. /// `DataSizePerJob` has lower priority that @ref NYT::TMapOperationSpecBase::JobCount.
  756. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  757. FLUENT_FIELD_OPTION(ui64, DataSizePerJob);
  758. };
  759. ///
  760. /// @brief Spec of Map operation.
  761. ///
  762. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/map
  763. struct TMapOperationSpec
  764. : public TMapOperationSpecBase<TMapOperationSpec>
  765. , public TOperationIOSpec<TMapOperationSpec>
  766. , public TUserJobFormatHintsBase<TMapOperationSpec>
  767. { };
  768. ///
  769. /// @brief Spec of raw Map operation.
  770. ///
  771. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/map
  772. struct TRawMapOperationSpec
  773. : public TMapOperationSpecBase<TRawMapOperationSpec>
  774. , public TSimpleRawOperationIoSpec<TRawMapOperationSpec>
  775. { };
  776. ////////////////////////////////////////////////////////////////////////////////
  777. ///
  778. /// @brief Spec of Reduce operation.
  779. ///
  780. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce
  781. template <typename TDerived>
  782. struct TReduceOperationSpecBase
  783. : public TUserOperationSpecBase<TDerived>
  784. , public TWithAutoMergeSpec<TDerived>
  785. {
  786. /// @cond Doxygen_Suppress
  787. using TSelf = TDerived;
  788. /// @endcond
  789. ///
  790. /// @brief Spec of reduce job.
  791. FLUENT_FIELD(TUserJobSpec, ReducerSpec);
  792. ///
  793. /// @brief Columns to sort rows by (must include `ReduceBy` as prefix).
  794. FLUENT_FIELD(TSortColumns, SortBy);
  795. ///
  796. /// @brief Columns to group rows by.
  797. FLUENT_FIELD(TSortColumns, ReduceBy);
  798. ///
  799. /// @brief Columns to join foreign tables by (must be prefix of `ReduceBy`).
  800. ///
  801. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce#foreign_tables
  802. FLUENT_FIELD_OPTION(TSortColumns, JoinBy);
  803. ///
  804. /// @brief Guarantee to feed all rows with same `ReduceBy` columns to a single job (`true` by default).
  805. FLUENT_FIELD_OPTION(bool, EnableKeyGuarantee);
  806. ///
  807. /// @brief Recommended number of jobs to run.
  808. ///
  809. /// `JobCount' has higher priority than @ref NYT::TReduceOperationSpecBase::DataSizePerJob.
  810. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  811. FLUENT_FIELD_OPTION(ui32, JobCount);
  812. ///
  813. /// @brief Recommended of data size for each job.
  814. ///
  815. /// `DataSizePerJob` has lower priority that @ref NYT::TReduceOperationSpecBase::JobCount.
  816. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  817. FLUENT_FIELD_OPTION(ui64, DataSizePerJob);
  818. };
  819. ///
  820. /// @brief Spec of Reduce operation.
  821. ///
  822. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce
  823. struct TReduceOperationSpec
  824. : public TReduceOperationSpecBase<TReduceOperationSpec>
  825. , public TOperationIOSpec<TReduceOperationSpec>
  826. , public TUserJobFormatHintsBase<TReduceOperationSpec>
  827. { };
  828. ///
  829. /// @brief Spec of raw Reduce operation.
  830. ///
  831. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce
  832. struct TRawReduceOperationSpec
  833. : public TReduceOperationSpecBase<TRawReduceOperationSpec>
  834. , public TSimpleRawOperationIoSpec<TRawReduceOperationSpec>
  835. { };
  836. ////////////////////////////////////////////////////////////////////////////////
  837. ///
  838. /// @brief Spec of JoinReduce operation.
  839. ///
  840. /// @deprecated Instead the user should run a reduce operation
  841. /// with @ref NYT::TReduceOperationSpec::EnableKeyGuarantee set to `false`.
  842. ///
  843. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce#foreign_tables
  844. template <typename TDerived>
  845. struct TJoinReduceOperationSpecBase
  846. : public TUserOperationSpecBase<TDerived>
  847. {
  848. /// @cond Doxygen_Suppress
  849. using TSelf = TDerived;
  850. /// @endcond
  851. ///
  852. /// @brief Spec of reduce job.
  853. FLUENT_FIELD(TUserJobSpec, ReducerSpec);
  854. ///
  855. /// @brief Columns to join foreign tables by (must be prefix of `ReduceBy`).
  856. ///
  857. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce#foreign_tables
  858. FLUENT_FIELD(TSortColumns, JoinBy);
  859. ///
  860. /// @brief Recommended number of jobs to run.
  861. ///
  862. /// `JobCount' has higher priority than @ref NYT::TJoinReduceOperationSpecBase::DataSizePerJob.
  863. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  864. FLUENT_FIELD_OPTION(ui32, JobCount);
  865. ///
  866. /// @brief Recommended of data size for each job.
  867. ///
  868. /// `DataSizePerJob` has lower priority that @ref NYT::TJoinReduceOperationSpecBase::JobCount.
  869. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  870. FLUENT_FIELD_OPTION(ui64, DataSizePerJob);
  871. };
  872. ///
  873. /// @brief Spec of JoinReduce operation.
  874. ///
  875. /// @deprecated Instead the user should run a reduce operation
  876. /// with @ref NYT::TReduceOperationSpec::EnableKeyGuarantee set to `false`.
  877. ///
  878. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce#foreign_tables
  879. struct TJoinReduceOperationSpec
  880. : public TJoinReduceOperationSpecBase<TJoinReduceOperationSpec>
  881. , public TOperationIOSpec<TJoinReduceOperationSpec>
  882. , public TUserJobFormatHintsBase<TJoinReduceOperationSpec>
  883. { };
  884. ///
  885. /// @brief Spec of raw JoinReduce operation.
  886. ///
  887. /// @deprecated Instead the user should run a reduce operation
  888. /// with @ref NYT::TReduceOperationSpec::EnableKeyGuarantee set to `false`.
  889. ///
  890. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce#foreign_tables
  891. struct TRawJoinReduceOperationSpec
  892. : public TJoinReduceOperationSpecBase<TRawJoinReduceOperationSpec>
  893. , public TSimpleRawOperationIoSpec<TRawJoinReduceOperationSpec>
  894. { };
  895. ////////////////////////////////////////////////////////////////////////////////
  896. ///
  897. /// @brief Spec of MapReduce operation.
  898. ///
  899. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/mapreduce
  900. template <typename TDerived>
  901. struct TMapReduceOperationSpecBase
  902. : public TUserOperationSpecBase<TDerived>
  903. {
  904. /// @cond Doxygen_Suppress
  905. using TSelf = TDerived;
  906. /// @endcond
  907. ///
  908. /// @brief Spec of map job.
  909. FLUENT_FIELD(TUserJobSpec, MapperSpec);
  910. ///
  911. /// @brief Spec of reduce job.
  912. FLUENT_FIELD(TUserJobSpec, ReducerSpec);
  913. ///
  914. /// @brief Spec of reduce combiner.
  915. FLUENT_FIELD(TUserJobSpec, ReduceCombinerSpec);
  916. ///
  917. /// @brief Columns to sort rows by (must include `ReduceBy` as prefix).
  918. FLUENT_FIELD(TSortColumns, SortBy);
  919. ///
  920. /// @brief Columns to group rows by.
  921. FLUENT_FIELD(TSortColumns, ReduceBy);
  922. ///
  923. /// @brief Recommended number of map jobs to run.
  924. ///
  925. /// `JobCount' has higher priority than @ref NYT::TMapReduceOperationSpecBase::DataSizePerMapJob.
  926. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  927. FLUENT_FIELD_OPTION(ui32, MapJobCount);
  928. ///
  929. /// @brief Recommended of data size for each map job.
  930. ///
  931. /// `DataSizePerJob` has lower priority that @ref NYT::TMapReduceOperationSpecBase::MapJobCount.
  932. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  933. FLUENT_FIELD_OPTION(ui64, DataSizePerMapJob);
  934. ///
  935. /// @brief Recommended number of intermediate data partitions.
  936. FLUENT_FIELD_OPTION(ui64, PartitionCount);
  937. ///
  938. /// @brief Recommended size of intermediate data partitions.
  939. FLUENT_FIELD_OPTION(ui64, PartitionDataSize);
  940. ///
  941. /// @brief Account to use for intermediate data.
  942. FLUENT_FIELD_OPTION(TString, IntermediateDataAccount);
  943. ///
  944. /// @brief Replication factor for intermediate data (1 by default).
  945. FLUENT_FIELD_OPTION(ui64, IntermediateDataReplicationFactor);
  946. ///
  947. /// @brief Recommended size of data to be passed to a single reduce combiner.
  948. FLUENT_FIELD_OPTION(ui64, DataSizePerSortJob);
  949. ///
  950. /// @brief Whether to guarantee the order of rows passed to mapper matches the order in the table.
  951. ///
  952. /// @see @ref NYT::TMapOperationSpec::Ordered for more info.
  953. FLUENT_FIELD_OPTION(bool, Ordered);
  954. ///
  955. /// @brief Guarantee to run reduce combiner before reducer.
  956. FLUENT_FIELD_OPTION(bool, ForceReduceCombiners);
  957. };
  958. ///
  959. /// @brief Spec of MapReduce operation.
  960. ///
  961. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/mapreduce
  962. struct TMapReduceOperationSpec
  963. : public TMapReduceOperationSpecBase<TMapReduceOperationSpec>
  964. , public TOperationIOSpec<TMapReduceOperationSpec>
  965. , public TIntermediateTablesHintSpec<TMapReduceOperationSpec>
  966. {
  967. /// @cond Doxygen_Suppress
  968. using TSelf = TMapReduceOperationSpec;
  969. /// @endcond
  970. ///
  971. /// @brief Format hints for mapper.
  972. FLUENT_FIELD_DEFAULT(TUserJobFormatHints, MapperFormatHints, TUserJobFormatHints());
  973. ///
  974. /// @brief Format hints for reducer.
  975. FLUENT_FIELD_DEFAULT(TUserJobFormatHints, ReducerFormatHints, TUserJobFormatHints());
  976. ///
  977. /// @brief Format hints for reduce combiner.
  978. FLUENT_FIELD_DEFAULT(TUserJobFormatHints, ReduceCombinerFormatHints, TUserJobFormatHints());
  979. };
  980. ///
  981. /// @brief Spec of raw MapReduce operation.
  982. ///
  983. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/mapreduce
  984. struct TRawMapReduceOperationSpec
  985. : public TMapReduceOperationSpecBase<TRawMapReduceOperationSpec>
  986. , public TRawMapReduceOperationIoSpec<TRawMapReduceOperationSpec>
  987. { };
  988. ////////////////////////////////////////////////////////////////////////////////
  989. ///
  990. /// @brief Schema inference mode.
  991. ///
  992. /// @see https://ytsaurus.tech/docs/en/user-guide/storage/static-schema.html#schema_inference
  993. enum class ESchemaInferenceMode : int
  994. {
  995. FromInput /* "from_input" */,
  996. FromOutput /* "from_output" */,
  997. Auto /* "auto" */,
  998. };
  999. ///
  1000. /// @brief Spec of Sort operation.
  1001. ///
  1002. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/sort
  1003. struct TSortOperationSpec
  1004. : TOperationSpecBase<TSortOperationSpec>
  1005. {
  1006. /// @cond Doxygen_Suppress
  1007. using TSelf = TSortOperationSpec;
  1008. /// @endcond
  1009. ///
  1010. /// @brief Paths to input tables.
  1011. FLUENT_VECTOR_FIELD(TRichYPath, Input);
  1012. ///
  1013. /// @brief Path to output table.
  1014. FLUENT_FIELD(TRichYPath, Output);
  1015. ///
  1016. /// @brief Columns to sort table by.
  1017. FLUENT_FIELD(TSortColumns, SortBy);
  1018. ///
  1019. /// @brief Recommended number of intermediate data partitions.
  1020. FLUENT_FIELD_OPTION(ui64, PartitionCount);
  1021. ///
  1022. /// @brief Recommended size of intermediate data partitions.
  1023. FLUENT_FIELD_OPTION(ui64, PartitionDataSize);
  1024. ///
  1025. /// @brief Recommended number of partition jobs to run.
  1026. ///
  1027. /// `JobCount' has higher priority than @ref NYT::TSortOperationSpec::DataSizePerPartitionJob.
  1028. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  1029. FLUENT_FIELD_OPTION(ui64, PartitionJobCount);
  1030. ///
  1031. /// @brief Recommended of data size for each partition job.
  1032. ///
  1033. /// `DataSizePerJob` has lower priority that @ref NYT::TSortOperationSpec::PartitionJobCount.
  1034. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  1035. FLUENT_FIELD_OPTION(ui64, DataSizePerPartitionJob);
  1036. ///
  1037. /// @brief Inference mode for output table schema.
  1038. ///
  1039. /// @see https://ytsaurus.tech/docs/en/user-guide/storage/static-schema.html#schema_inference
  1040. FLUENT_FIELD_OPTION(ESchemaInferenceMode, SchemaInferenceMode);
  1041. ///
  1042. /// @brief Account to use for intermediate data.
  1043. FLUENT_FIELD_OPTION(TString, IntermediateDataAccount);
  1044. ///
  1045. /// @brief Replication factor for intermediate data (1 by default).
  1046. FLUENT_FIELD_OPTION(ui64, IntermediateDataReplicationFactor);
  1047. };
  1048. ///
  1049. /// @brief Merge mode.
  1050. enum EMergeMode : int
  1051. {
  1052. MM_UNORDERED /* "unordered" */,
  1053. MM_ORDERED /* "ordered" */,
  1054. MM_SORTED /* "sorted" */,
  1055. };
  1056. ///
  1057. /// @brief Spec of Merge operation.
  1058. ///
  1059. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/merge
  1060. struct TMergeOperationSpec
  1061. : TOperationSpecBase<TMergeOperationSpec>
  1062. {
  1063. /// @cond Doxygen_Suppress
  1064. using TSelf = TMergeOperationSpec;
  1065. /// @endcond
  1066. ///
  1067. /// @brief Paths to input tables.
  1068. FLUENT_VECTOR_FIELD(TRichYPath, Input);
  1069. ///
  1070. /// @brief Path to output table.
  1071. FLUENT_FIELD(TRichYPath, Output);
  1072. ///
  1073. /// @brief Columns by which to merge (for @ref NYT::EMergeMode::MM_SORTED).
  1074. FLUENT_FIELD(TSortColumns, MergeBy);
  1075. ///
  1076. /// @brief Merge mode.
  1077. FLUENT_FIELD_DEFAULT(EMergeMode, Mode, MM_UNORDERED);
  1078. ///
  1079. /// @brief Combine output chunks to larger ones.
  1080. FLUENT_FIELD_DEFAULT(bool, CombineChunks, false);
  1081. ///
  1082. /// @brief Guarantee that all input chunks will be read.
  1083. FLUENT_FIELD_DEFAULT(bool, ForceTransform, false);
  1084. ///
  1085. /// @brief Recommended number of jobs to run.
  1086. ///
  1087. /// `JobCount' has higher priority than @ref NYT::TMergeOperationSpec::DataSizePerJob.
  1088. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  1089. FLUENT_FIELD_OPTION(ui32, JobCount);
  1090. ///
  1091. /// @brief Recommended of data size for each job.
  1092. ///
  1093. /// `DataSizePerJob` has lower priority that @ref NYT::TMergeOperationSpec::JobCount.
  1094. /// This option only provide a recommendation and may be ignored if conflicting with YT internal limits.
  1095. FLUENT_FIELD_OPTION(ui64, DataSizePerJob);
  1096. ///
  1097. /// @brief Inference mode for output table schema.
  1098. ///
  1099. /// @see https://ytsaurus.tech/docs/en/user-guide/storage/static-schema.html#schema_inference
  1100. FLUENT_FIELD_OPTION(ESchemaInferenceMode, SchemaInferenceMode);
  1101. };
  1102. ///
  1103. /// @brief Spec of Erase operation.
  1104. ///
  1105. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/erase
  1106. struct TEraseOperationSpec
  1107. : TOperationSpecBase<TEraseOperationSpec>
  1108. {
  1109. /// @cond Doxygen_Suppress
  1110. using TSelf = TEraseOperationSpec;
  1111. /// @endcond
  1112. ///
  1113. /// @brief Which table (or row range) to erase.
  1114. FLUENT_FIELD(TRichYPath, TablePath);
  1115. ///
  1116. /// Combine output chunks to larger ones.
  1117. FLUENT_FIELD_DEFAULT(bool, CombineChunks, false);
  1118. ///
  1119. /// @brief Inference mode for output table schema.
  1120. ///
  1121. /// @see https://ytsaurus.tech/docs/en/user-guide/storage/static-schema.html#schema_inference
  1122. FLUENT_FIELD_OPTION(ESchemaInferenceMode, SchemaInferenceMode);
  1123. };
  1124. ///
  1125. /// @brief Spec of RemoteCopy operation.
  1126. ///
  1127. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/remote_copy
  1128. struct TRemoteCopyOperationSpec
  1129. : TOperationSpecBase<TRemoteCopyOperationSpec>
  1130. {
  1131. /// @cond Doxygen_Suppress
  1132. using TSelf = TRemoteCopyOperationSpec;
  1133. /// @endcond
  1134. ///
  1135. /// @brief Source cluster name.
  1136. FLUENT_FIELD(TString, ClusterName);
  1137. ///
  1138. /// @brief Network to use for copy (all remote cluster nodes must have it configured).
  1139. FLUENT_FIELD_OPTION(TString, NetworkName);
  1140. ///
  1141. /// @brief Paths to input tables.
  1142. FLUENT_VECTOR_FIELD(TRichYPath, Input);
  1143. ///
  1144. /// @brief Path to output table.
  1145. FLUENT_FIELD(TRichYPath, Output);
  1146. ///
  1147. /// @brief Inference mode for output table schema.
  1148. ///
  1149. /// @see https://ytsaurus.tech/docs/en/user-guide/storage/static-schema.html#schema_inference
  1150. FLUENT_FIELD_OPTION(ESchemaInferenceMode, SchemaInferenceMode);
  1151. ///
  1152. /// @brief Copy user attributes from input to output table (allowed only for single input table).
  1153. FLUENT_FIELD_DEFAULT(bool, CopyAttributes, false);
  1154. ///
  1155. /// @brief Names of user attributes to copy from input to output table.
  1156. ///
  1157. /// @note To make this option make sense set @ref NYT::TRemoteCopyOperationSpec::CopyAttributes to `true`.
  1158. FLUENT_VECTOR_FIELD(TString, AttributeKey);
  1159. private:
  1160. ///
  1161. /// @brief Config for remote cluster connection.
  1162. FLUENT_FIELD_OPTION(TNode, ClusterConnection);
  1163. };
  1164. class IVanillaJobBase;
  1165. ///
  1166. /// @brief Task of Vanilla operation.
  1167. ///
  1168. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/vanilla
  1169. struct TVanillaTask
  1170. : public TOperationOutputSpecBase
  1171. , public TUserJobOutputFormatHintsBase<TVanillaTask>
  1172. {
  1173. /// @cond Doxygen_Suppress
  1174. using TSelf = TVanillaTask;
  1175. /// @endcond
  1176. ///
  1177. /// @brief Add output table path and specify the task output type (i.e. TMyProtoMessage).
  1178. template <class T>
  1179. TSelf& AddOutput(const TRichYPath& path);
  1180. ///
  1181. /// @brief Add output table path as structured path.
  1182. TSelf& AddStructuredOutput(TStructuredTablePath path);
  1183. ///
  1184. /// @brief Set output table path and specify the task output type (i.e. TMyProtoMessage).
  1185. template <class T>
  1186. TSelf& SetOutput(size_t tableIndex, const TRichYPath& path);
  1187. ///
  1188. /// @brief Task name.
  1189. FLUENT_FIELD(TString, Name);
  1190. ///
  1191. /// @brief Job to be executed in this task.
  1192. FLUENT_FIELD(::TIntrusivePtr<IVanillaJobBase>, Job);
  1193. ///
  1194. /// @brief User job spec.
  1195. FLUENT_FIELD(TUserJobSpec, Spec);
  1196. ///
  1197. /// @brief Number of jobs to run and wait for successful completion.
  1198. ///
  1199. /// @note If @ref NYT::TUserOperationSpecBase::FailOnJobRestart is `false`, a failed job will be restarted
  1200. /// and will not count in this amount.
  1201. FLUENT_FIELD(ui64, JobCount);
  1202. ///
  1203. /// @brief Network project name.
  1204. FLUENT_FIELD(TMaybe<TString>, NetworkProject);
  1205. };
  1206. ///
  1207. /// @brief Spec of Vanilla operation.
  1208. ///
  1209. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/vanilla
  1210. struct TVanillaOperationSpec
  1211. : TUserOperationSpecBase<TVanillaOperationSpec>
  1212. {
  1213. /// @cond Doxygen_Suppress
  1214. using TSelf = TVanillaOperationSpec;
  1215. /// @endcond
  1216. ///
  1217. /// @brief Description of tasks to run in this operation.
  1218. FLUENT_VECTOR_FIELD(TVanillaTask, Task);
  1219. };
  1220. ////////////////////////////////////////////////////////////////////////////////
  1221. ///
  1222. /// @brief Options for @ref NYT::IOperationClient::Map and other operation start commands.
  1223. struct TOperationOptions
  1224. {
  1225. /// @cond Doxygen_Suppress
  1226. using TSelf = TOperationOptions;
  1227. /// @endcond
  1228. ///
  1229. /// @brief Additional field to put to operation spec.
  1230. FLUENT_FIELD_OPTION(TNode, Spec);
  1231. ///
  1232. /// @brief Start operation mode.
  1233. enum class EStartOperationMode : int
  1234. {
  1235. ///
  1236. /// @brief Prepare operation asynchronously. Call IOperation::Start() to start operation.
  1237. AsyncPrepare,
  1238. ///
  1239. /// @brief Prepare and start operation asynchronously. Don't wait for operation completion.
  1240. AsyncStart,
  1241. ///
  1242. /// @brief Prepare and start operation synchronously. Don't wait for operation completion.
  1243. SyncStart,
  1244. ///
  1245. /// @brief Prepare, start and wait for operation completion synchronously.
  1246. SyncWait,
  1247. };
  1248. ///
  1249. /// @brief Start operation mode.
  1250. FLUENT_FIELD_DEFAULT(EStartOperationMode, StartOperationMode, EStartOperationMode::SyncWait);
  1251. ///
  1252. /// @brief Wait for operation finish synchronously.
  1253. ///
  1254. /// @deprecated Use StartOperationMode() instead.
  1255. TSelf& Wait(bool value) {
  1256. StartOperationMode_ = value ? EStartOperationMode::SyncWait : EStartOperationMode::SyncStart;
  1257. return static_cast<TSelf&>(*this);
  1258. }
  1259. ///
  1260. ///
  1261. /// @brief Use format from table attribute (for YAMR-like format).
  1262. ///
  1263. /// @deprecated
  1264. FLUENT_FIELD_DEFAULT(bool, UseTableFormats, false);
  1265. ///
  1266. /// @brief Prefix for bash command running the jobs.
  1267. ///
  1268. /// Can be overridden for the specific job type in the @ref NYT::TUserJobSpec.
  1269. FLUENT_FIELD(TString, JobCommandPrefix);
  1270. ///
  1271. /// @brief Suffix for bash command running the jobs.
  1272. ///
  1273. /// Can be overridden for the specific job type in the @ref NYT::TUserJobSpec.
  1274. FLUENT_FIELD(TString, JobCommandSuffix);
  1275. ///
  1276. /// @brief Put all files required by the job into tmpfs.
  1277. ///
  1278. /// This option can be set globally using @ref NYT::TConfig::MountSandboxInTmpfs.
  1279. /// @see https://ytsaurus.tech/docs/en/problems/woodpeckers
  1280. FLUENT_FIELD_DEFAULT(bool, MountSandboxInTmpfs, false);
  1281. ///
  1282. /// @brief Path to directory to store temporary files.
  1283. /// Useful if you want to control how lifetime of uploaded files.
  1284. FLUENT_FIELD_OPTION(TString, FileStorage);
  1285. ///
  1286. /// @brief Expiration timeout for uploaded files.
  1287. ///
  1288. /// Set attribute ExpirationTimeout for files being uploaded during operation preparation.
  1289. /// Useful when using custom FileStorage and don't want to create separate cleanup process.
  1290. ///
  1291. /// When using default FileStorage inside //tmp this parameter is almost useless.
  1292. /// //tmp directory is cleaned up by separate process and files can be deleted before FileExpiratoinTimeout is reached.
  1293. FLUENT_FIELD_OPTION(TDuration, FileExpirationTimeout);
  1294. ///
  1295. /// @brief Info to be passed securely to the job.
  1296. FLUENT_FIELD_OPTION(TNode, SecureVault);
  1297. ///
  1298. /// @brief File cache mode.
  1299. enum class EFileCacheMode : int
  1300. {
  1301. ///
  1302. /// @brief Use YT API commands "get_file_from_cache" and "put_file_to_cache".
  1303. ApiCommandBased,
  1304. ///
  1305. /// @brief Upload files to random paths inside @ref NYT::TOperationOptions::FileStorage without caching.
  1306. CachelessRandomPathUpload,
  1307. };
  1308. ///
  1309. /// @brief File cache mode.
  1310. FLUENT_FIELD_DEFAULT(EFileCacheMode, FileCacheMode, EFileCacheMode::ApiCommandBased);
  1311. ///
  1312. /// @brief Id of transaction within which all Cypress file storage entries will be checked/created.
  1313. ///
  1314. /// By default, the root transaction is used.
  1315. ///
  1316. /// @note Set a specific transaction only if you
  1317. /// 1. specify non-default file storage path in @ref NYT::TOperationOptions::FileStorage or in @ref NYT::TConfig::RemoteTempFilesDirectory.
  1318. /// 2. use `CachelessRandomPathUpload` caching mode (@ref NYT::TOperationOptions::FileCacheMode).
  1319. FLUENT_FIELD(TTransactionId, FileStorageTransactionId);
  1320. ///
  1321. /// @brief Ensure stderr and core tables exist before starting operation.
  1322. ///
  1323. /// If set to `false`, it is user's responsibility to ensure these tables exist.
  1324. FLUENT_FIELD_DEFAULT(bool, CreateDebugOutputTables, true);
  1325. ///
  1326. /// @brief Ensure output tables exist before starting operation.
  1327. ///
  1328. /// If set to `false`, it is user's responsibility to ensure output tables exist.
  1329. FLUENT_FIELD_DEFAULT(bool, CreateOutputTables, true);
  1330. ///
  1331. /// @brief Try to infer schema of inexistent table from the type of written rows.
  1332. ///
  1333. /// @note Default values for this option may differ depending on the row type.
  1334. /// For protobuf it's currently `false` by default.
  1335. FLUENT_FIELD_OPTION(bool, InferOutputSchema);
  1336. };
  1337. ////////////////////////////////////////////////////////////////////////////////
  1338. ///
  1339. /// @brief Get operation secure vault (specified in @ref NYT::TOperationOptions::SecureVault) inside a job.
  1340. const TNode& GetJobSecureVault();
  1341. ////////////////////////////////////////////////////////////////////////////////
  1342. ///
  1343. /// @brief Context passed to @ref NYT::IRawJob::Do.
  1344. class TRawJobContext
  1345. {
  1346. public:
  1347. explicit TRawJobContext(size_t outputTableCount);
  1348. ///
  1349. /// @brief Get file corresponding to input stream.
  1350. const TFile& GetInputFile() const;
  1351. ///
  1352. /// @brief Get files corresponding to output streams.
  1353. const TVector<TFile>& GetOutputFileList() const;
  1354. private:
  1355. TFile InputFile_;
  1356. TVector<TFile> OutputFileList_;
  1357. };
  1358. ////////////////////////////////////////////////////////////////////////////////
  1359. ///
  1360. /// @brief Interface for classes that can be Saved/Loaded (to be used with @ref Y_SAVELOAD_JOB).
  1361. class ISerializableForJob
  1362. {
  1363. public:
  1364. virtual ~ISerializableForJob() = default;
  1365. ///
  1366. /// @brief Dump state to output stream to be restored in job.
  1367. virtual void Save(IOutputStream& stream) const = 0;
  1368. ///
  1369. /// @brief Load state from a stream.
  1370. virtual void Load(IInputStream& stream) = 0;
  1371. };
  1372. ////////////////////////////////////////////////////////////////////////////////
  1373. ///
  1374. /// @brief Provider of information about operation inputs/outputs during @ref NYT::IJob::PrepareOperation.
  1375. class IOperationPreparationContext
  1376. {
  1377. public:
  1378. virtual ~IOperationPreparationContext() = default;
  1379. /// @brief Get the number of input tables.
  1380. virtual int GetInputCount() const = 0;
  1381. /// @brief Get the number of output tables.
  1382. virtual int GetOutputCount() const = 0;
  1383. /// @brief Get the schema of input table no. `index`.
  1384. virtual const TTableSchema& GetInputSchema(int index) const = 0;
  1385. /// @brief Get all the input table schemas.
  1386. virtual const TVector<TTableSchema>& GetInputSchemas() const = 0;
  1387. /// @brief Path to the input table if available (`Nothing()` for intermediate tables).
  1388. virtual TMaybe<TYPath> GetInputPath(int index) const = 0;
  1389. /// @brief Path to the output table if available (`Nothing()` for intermediate tables).
  1390. virtual TMaybe<TYPath> GetOutputPath(int index) const = 0;
  1391. };
  1392. ///
  1393. /// @brief Fluent builder class for @ref NYT::IJob::PrepareOperation.
  1394. ///
  1395. /// @note Method calls are supposed to be chained.
  1396. class TJobOperationPreparer
  1397. {
  1398. public:
  1399. ///
  1400. /// @brief Group of input tables that allows to specify properties on all of them at once.
  1401. ///
  1402. /// The instances are created with @ref NYT::TJobOperationPreparer::BeginInputGroup, not directly.
  1403. class TInputGroup
  1404. {
  1405. public:
  1406. TInputGroup(TJobOperationPreparer& preparer, TVector<int> indices);
  1407. /// @brief Specify the type of input rows.
  1408. template <typename TRow>
  1409. TInputGroup& Description();
  1410. /// @brief Specify renaming of input columns.
  1411. TInputGroup& ColumnRenaming(const THashMap<TString, TString>& renaming);
  1412. /// @brief Specify what input columns to send to job
  1413. ///
  1414. /// @note Filter is applied before renaming, so it must specify original column names.
  1415. TInputGroup& ColumnFilter(const TVector<TString>& columns);
  1416. /// @brief Finish describing the input group.
  1417. TJobOperationPreparer& EndInputGroup();
  1418. private:
  1419. TJobOperationPreparer& Preparer_;
  1420. TVector<int> Indices_;
  1421. };
  1422. ///
  1423. /// @brief Group of output tables that allows to specify properties on all of them at once.
  1424. ///
  1425. /// The instances are created with @ref NYT::TJobOperationPreparer::BeginOutputGroup, not directly.
  1426. class TOutputGroup
  1427. {
  1428. public:
  1429. TOutputGroup(TJobOperationPreparer& preparer, TVector<int> indices);
  1430. /// @brief Specify the type of output rows.
  1431. ///
  1432. /// @tparam TRow type of output rows from tables of this group.
  1433. /// @param inferSchema Infer schema from `TRow` and specify it for these output tables.
  1434. template <typename TRow>
  1435. TOutputGroup& Description(bool inferSchema = true);
  1436. /// @brief Specify schema for these tables.
  1437. TOutputGroup& Schema(const TTableSchema& schema);
  1438. /// @brief Specify that all the the tables in this group are unschematized.
  1439. ///
  1440. /// It is equivalent of `.Schema(TTableSchema().Strict(false)`.
  1441. TOutputGroup& NoSchema();
  1442. /// @brief Finish describing the output group.
  1443. TJobOperationPreparer& EndOutputGroup();
  1444. private:
  1445. TJobOperationPreparer& Preparer_;
  1446. TVector<int> Indices_;
  1447. };
  1448. public:
  1449. explicit TJobOperationPreparer(const IOperationPreparationContext& context);
  1450. /// @brief Begin input group consisting of tables with indices `[begin, end)`.
  1451. ///
  1452. /// @param begin First index.
  1453. /// @param end Index after the last one.
  1454. TInputGroup BeginInputGroup(int begin, int end);
  1455. /// @brief Begin input group consisting of tables with indices from `indices`.
  1456. ///
  1457. /// @tparam TCont Container with integers. Must support `std::begin` and `std::end` functions.
  1458. /// @param indices Indices of tables to include in the group.
  1459. template <typename TCont>
  1460. TInputGroup BeginInputGroup(const TCont& indices);
  1461. /// @brief Begin output group consisting of tables with indices `[begin, end)`.
  1462. ///
  1463. /// @param begin First index.
  1464. /// @param end Index after the last one.
  1465. TOutputGroup BeginOutputGroup(int begin, int end);
  1466. /// @brief Begin input group consisting of tables with indices from `indices`.
  1467. ///
  1468. /// @tparam TCont Container with integers. Must support `std::begin` and `std::end` functions.
  1469. /// @param indices Indices of tables to include in the group.
  1470. template <typename TCont>
  1471. TOutputGroup BeginOutputGroup(const TCont& indices);
  1472. /// @brief Specify the schema for output table no `tableIndex`.
  1473. ///
  1474. /// @note All the output schemas must be specified either with this method, `NoOutputSchema` or `OutputDescription` with `inferSchema == true`
  1475. TJobOperationPreparer& OutputSchema(int tableIndex, TTableSchema schema);
  1476. /// @brief Mark the output table no. `tableIndex` as unschematized.
  1477. TJobOperationPreparer& NoOutputSchema(int tableIndex);
  1478. /// @brief Specify renaming of input columns for table no. `tableIndex`.
  1479. TJobOperationPreparer& InputColumnRenaming(int tableIndex, const THashMap<TString, TString>& renaming);
  1480. /// @brief Specify what input columns of table no. `tableIndex` to send to job
  1481. ///
  1482. /// @note Filter is applied before renaming, so it must specify original column names.
  1483. TJobOperationPreparer& InputColumnFilter(int tableIndex, const TVector<TString>& columns);
  1484. /// @brief Specify the type of input rows for table no. `tableIndex`.
  1485. ///
  1486. /// @tparam TRow type of input rows.
  1487. template <typename TRow>
  1488. TJobOperationPreparer& InputDescription(int tableIndex);
  1489. /// @brief Specify the type of output rows for table no. `tableIndex`.
  1490. ///
  1491. /// @tparam TRow type of output rows.
  1492. /// @param inferSchema Infer schema from `TRow` and specify it for the output tables.
  1493. template <typename TRow>
  1494. TJobOperationPreparer& OutputDescription(int tableIndex, bool inferSchema = true);
  1495. /// @brief Set type of output rows for table no. `tableIndex` to TNode
  1496. ///
  1497. /// @note Set schema via `OutputSchema` if needed
  1498. TJobOperationPreparer& NodeOutput(int tableIndex);
  1499. /// @brief Specify input format hints.
  1500. ///
  1501. /// These hints have lower priority than ones specified in spec.
  1502. TJobOperationPreparer& InputFormatHints(TFormatHints hints);
  1503. /// @brief Specify output format hints.
  1504. ///
  1505. /// These hints have lower priority than ones specified in spec.
  1506. TJobOperationPreparer& OutputFormatHints(TFormatHints hints);
  1507. /// @brief Specify format hints.
  1508. ///
  1509. /// These hints have lower priority than ones specified in spec.
  1510. TJobOperationPreparer& FormatHints(TUserJobFormatHints newFormatHints);
  1511. /// @name "Private" members
  1512. /// The following methods should not be used by clients in @ref NYT::IJob::PrepareOperation
  1513. ///@{
  1514. /// @brief Finish the building process.
  1515. void Finish();
  1516. /// @brief Get output table schemas as specified by the user.
  1517. TVector<TTableSchema> GetOutputSchemas();
  1518. /// @brief Get input column renamings as specified by the user.
  1519. const TVector<THashMap<TString, TString>>& GetInputColumnRenamings() const;
  1520. /// @brief Get input column filters as specified by the user.
  1521. const TVector<TMaybe<TVector<TString>>>& GetInputColumnFilters() const;
  1522. /// @brief Get input column descriptions as specified by the user.
  1523. const TVector<TMaybe<TTableStructure>>& GetInputDescriptions() const;
  1524. /// @brief Get output column descriptions as specified by the user.
  1525. const TVector<TMaybe<TTableStructure>>& GetOutputDescriptions() const;
  1526. /// @brief Get format hints as specified by the user.
  1527. const TUserJobFormatHints& GetFormatHints() const;
  1528. ///@}
  1529. private:
  1530. /// @brief Validate that schema for output table no. `tableIndex` has not been set yet.
  1531. void ValidateMissingOutputSchema(int tableIndex) const;
  1532. /// @brief Validate that description for input table no. `tableIndex` has not been set yet.
  1533. void ValidateMissingInputDescription(int tableIndex) const;
  1534. /// @brief Validate that description for output table no. `tableIndex` has not been set yet.
  1535. void ValidateMissingOutputDescription(int tableIndex) const;
  1536. /// @brief Validate that `tableIndex` is in correct range for input table indices.
  1537. ///
  1538. /// @param message Message to add to the exception in case of violation.
  1539. void ValidateInputTableIndex(int tableIndex, TStringBuf message) const;
  1540. /// @brief Validate that `tableIndex` is in correct range for output table indices.
  1541. ///
  1542. /// @param message Message to add to the exception in case of violation.
  1543. void ValidateOutputTableIndex(int tableIndex, TStringBuf message) const;
  1544. /// @brief Validate that all the output schemas has been set.
  1545. void FinallyValidate() const;
  1546. static TTableSchema EmptyNonstrictSchema();
  1547. private:
  1548. const IOperationPreparationContext& Context_;
  1549. TVector<TMaybe<TTableSchema>> OutputSchemas_;
  1550. TVector<THashMap<TString, TString>> InputColumnRenamings_;
  1551. TVector<TMaybe<TVector<TString>>> InputColumnFilters_;
  1552. TVector<TMaybe<TTableStructure>> InputTableDescriptions_;
  1553. TVector<TMaybe<TTableStructure>> OutputTableDescriptions_;
  1554. TUserJobFormatHints FormatHints_ = {};
  1555. };
  1556. ////////////////////////////////////////////////////////////////////////////////
  1557. ///
  1558. /// @brief Interface for all user jobs.
  1559. class IJob
  1560. : public TThrRefBase
  1561. {
  1562. public:
  1563. ///
  1564. /// @brief Type of job.
  1565. enum EType
  1566. {
  1567. Mapper,
  1568. Reducer,
  1569. ReducerAggregator,
  1570. RawJob,
  1571. VanillaJob,
  1572. };
  1573. ///
  1574. /// @brief Save job state to stream to be restored on cluster nodes.
  1575. virtual void Save(IOutputStream& stream) const
  1576. {
  1577. Y_UNUSED(stream);
  1578. }
  1579. ///
  1580. /// @brief Restore job state from a stream.
  1581. virtual void Load(IInputStream& stream)
  1582. {
  1583. Y_UNUSED(stream);
  1584. }
  1585. ///
  1586. /// @brief Get operation secure vault (specified in @ref NYT::TOperationOptions::SecureVault) inside a job.
  1587. const TNode& SecureVault() const
  1588. {
  1589. return GetJobSecureVault();
  1590. }
  1591. ///
  1592. /// @brief Get number of output tables.
  1593. i64 GetOutputTableCount() const
  1594. {
  1595. Y_ABORT_UNLESS(NDetail::OutputTableCount > 0);
  1596. return NDetail::OutputTableCount;
  1597. }
  1598. ///
  1599. /// @brief Method allowing user to control some properties of input and output tables and formats.
  1600. ///
  1601. /// User can override this method in their job class to:
  1602. /// - specify output table schemas.
  1603. /// The most natural way is usually through @ref NYT::TJobOperationPreparer::OutputDescription (especially for protobuf),
  1604. /// but you can use @ref NYT::TJobOperationPreparer::OutputSchema directly
  1605. /// - specify output row type (@ref NYT::TJobOperationPreparer::OutputDescription)
  1606. /// - specify input row type (@ref NYT::TJobOperationPreparer::InputDescription)
  1607. /// - specify input column filter and renaming (@ref NYT::TJobOperationPreparer::InputColumnFilter and @ref NYT::TJobOperationPreparer::InputColumnRenaming)
  1608. /// - specify format hints (@ref NYT::TJobOperationPreparer::InputFormatHints,
  1609. /// NYT::TJobOperationPreparer::OutputFormatHints and @ref NYT::TJobOperationPreparer::FormatHints)
  1610. /// - maybe something more, cf. the methods of @ref NYT::TJobOperationPreparer.
  1611. ///
  1612. /// If one has several similar tables, groups can be used.
  1613. /// Groups are delimited by @ref NYT::TJobOperationPreparer::BeginInputGroup /
  1614. /// @ref NYT::TJobOperationPreparer::TInputGroup::EndInputGroup and
  1615. /// @ref NYT::TJobOperationPreparer::BeginOutputGroup /
  1616. /// @ref NYT::TJobOperationPreparer::TOutputGroup::EndOutputGroup.
  1617. /// Example:
  1618. /// @code{.cpp}
  1619. /// preparer
  1620. /// .BeginInputGroup({1,2,4,8})
  1621. /// .ColumnRenaming({{"a", "b"}, {"c", "d"}})
  1622. /// .ColumnFilter({"a", "c"})
  1623. /// .EndInputGroup();
  1624. /// @endcode
  1625. ///
  1626. /// @note All the output table schemas must be set
  1627. /// (possibly as empty nonstrict using @ref NYT::TJobOperationPreparer::NoOutputSchema or
  1628. /// @ref NYT::TJobOperationPreparer::TOutputGroup::NoSchema).
  1629. /// By default all the output table schemas are marked as empty nonstrict.
  1630. virtual void PrepareOperation(const IOperationPreparationContext& context, TJobOperationPreparer& preparer) const;
  1631. };
  1632. ///
  1633. /// @brief Declare what fields of currently declared job class to save and restore on cluster node.
  1634. #define Y_SAVELOAD_JOB(...) \
  1635. virtual void Save(IOutputStream& stream) const override { Save(&stream); } \
  1636. virtual void Load(IInputStream& stream) override { Load(&stream); } \
  1637. Y_PASS_VA_ARGS(Y_SAVELOAD_DEFINE(__VA_ARGS__))
  1638. ///
  1639. /// @brief Same as the macro above, but also calls Base class's SaveLoad methods.
  1640. #define Y_SAVELOAD_JOB_DERIVED(Base, ...) \
  1641. virtual void Save(IOutputStream& stream) const override { \
  1642. Base::Save(stream); \
  1643. Save(&stream); \
  1644. } \
  1645. virtual void Load(IInputStream& stream) override { \
  1646. Base::Load(stream); \
  1647. Load(&stream); \
  1648. } \
  1649. Y_PASS_VA_ARGS(Y_SAVELOAD_DEFINE(__VA_ARGS__))
  1650. ////////////////////////////////////////////////////////////////////////////////
  1651. ///
  1652. /// @brief Interface for jobs with typed inputs and outputs.
  1653. class IStructuredJob
  1654. : public IJob
  1655. {
  1656. public:
  1657. ///
  1658. /// @brief This methods are called when creating table reader and writer for the job.
  1659. ///
  1660. /// Override them if you want to implement custom input logic. (e.g. additional bufferization)
  1661. virtual TRawTableReaderPtr CreateCustomRawJobReader(int fd) const;
  1662. virtual THolder<IProxyOutput> CreateCustomRawJobWriter(size_t outputTableCount) const;
  1663. virtual TStructuredRowStreamDescription GetInputRowStreamDescription() const = 0;
  1664. virtual TStructuredRowStreamDescription GetOutputRowStreamDescription() const = 0;
  1665. };
  1666. ////////////////////////////////////////////////////////////////////////////////
  1667. ///
  1668. /// @brief Create default raw job reader.
  1669. TRawTableReaderPtr CreateRawJobReader(int fd = 0);
  1670. ///
  1671. /// @brief Create default raw job writer.
  1672. THolder<IProxyOutput> CreateRawJobWriter(size_t outputTableCount);
  1673. ////////////////////////////////////////////////////////////////////////////////
  1674. ///
  1675. /// @brief Base interface for structured (typed) map jobs.
  1676. class IMapperBase
  1677. : public IStructuredJob
  1678. { };
  1679. ///
  1680. /// @brief Base interface for structured (typed) map jobs with given reader and writer.
  1681. template <class TR, class TW>
  1682. class IMapper
  1683. : public IMapperBase
  1684. {
  1685. public:
  1686. using TReader = TR;
  1687. using TWriter = TW;
  1688. public:
  1689. /// Type of job implemented by this class.
  1690. static constexpr EType JobType = EType::Mapper;
  1691. ///
  1692. /// @brief This method is called before feeding input rows to mapper (before `Do` method).
  1693. virtual void Start(TWriter* writer)
  1694. {
  1695. Y_UNUSED(writer);
  1696. }
  1697. ///
  1698. /// @brief This method is called exactly once for the whole job input.
  1699. ///
  1700. /// Read input rows from `reader` and write output ones to `writer`.
  1701. virtual void Do(TReader* reader, TWriter* writer) = 0;
  1702. ///
  1703. /// @brief This method is called after feeding input rows to mapper (after `Do` method).
  1704. virtual void Finish(TWriter* writer)
  1705. {
  1706. Y_UNUSED(writer);
  1707. }
  1708. virtual TStructuredRowStreamDescription GetInputRowStreamDescription() const override;
  1709. virtual TStructuredRowStreamDescription GetOutputRowStreamDescription() const override;
  1710. };
  1711. ////////////////////////////////////////////////////////////////////////////////
  1712. ///
  1713. /// @brief Base interface for structured (typed) reduce jobs.
  1714. ///
  1715. /// It is common base for @ref NYT::IReducer and @ref NYT::IAggregatorReducer.
  1716. class IReducerBase
  1717. : public IStructuredJob
  1718. { };
  1719. ///
  1720. /// @brief Base interface for structured (typed) reduce jobs with given reader and writer.
  1721. template <class TR, class TW>
  1722. class IReducer
  1723. : public IReducerBase
  1724. {
  1725. public:
  1726. using TReader = TR;
  1727. using TWriter = TW;
  1728. public:
  1729. /// Type of job implemented by this class.
  1730. static constexpr EType JobType = EType::Reducer;
  1731. public:
  1732. ///
  1733. /// @brief This method is called before feeding input rows to reducer (before `Do` method).
  1734. virtual void Start(TWriter* writer)
  1735. {
  1736. Y_UNUSED(writer);
  1737. }
  1738. ///
  1739. /// @brief This method is called exactly once for each range with same value of `ReduceBy` (or `JoinBy`) keys.
  1740. virtual void Do(TReader* reader, TWriter* writer) = 0;
  1741. ///
  1742. /// @brief This method is called after feeding input rows to reducer (after `Do` method).
  1743. virtual void Finish(TWriter* writer)
  1744. {
  1745. Y_UNUSED(writer);
  1746. }
  1747. ///
  1748. /// @brief Refuse to process the remaining row ranges and finish the job (successfully).
  1749. void Break();
  1750. virtual TStructuredRowStreamDescription GetInputRowStreamDescription() const override;
  1751. virtual TStructuredRowStreamDescription GetOutputRowStreamDescription() const override;
  1752. };
  1753. ////////////////////////////////////////////////////////////////////////////////
  1754. ///
  1755. /// @brief Base interface of jobs used inside reduce operations.
  1756. ///
  1757. /// Unlike @ref NYT::IReducer jobs their `Do' method is called only once
  1758. /// and takes whole range of records split by key boundaries.
  1759. ///
  1760. /// Template argument `TR` must be @ref NYT::TTableRangesReader.
  1761. template <class TR, class TW>
  1762. class IAggregatorReducer
  1763. : public IReducerBase
  1764. {
  1765. public:
  1766. using TReader = TR;
  1767. using TWriter = TW;
  1768. public:
  1769. /// Type of job implemented by this class.
  1770. static constexpr EType JobType = EType::ReducerAggregator;
  1771. public:
  1772. ///
  1773. /// @brief This method is called before feeding input rows to reducer (before `Do` method).
  1774. virtual void Start(TWriter* writer)
  1775. {
  1776. Y_UNUSED(writer);
  1777. }
  1778. ///
  1779. /// @brief This method is called exactly once for the whole job input.
  1780. virtual void Do(TReader* reader, TWriter* writer) = 0;
  1781. ///
  1782. /// @brief This method is called after feeding input rows to reducer (after `Do` method).
  1783. virtual void Finish(TWriter* writer)
  1784. {
  1785. Y_UNUSED(writer);
  1786. }
  1787. virtual TStructuredRowStreamDescription GetInputRowStreamDescription() const override;
  1788. virtual TStructuredRowStreamDescription GetOutputRowStreamDescription() const override;
  1789. };
  1790. ////////////////////////////////////////////////////////////////////////////////
  1791. ///
  1792. /// @brief Interface for raw jobs (i.e. reading and writing byte streams).
  1793. class IRawJob
  1794. : public IJob
  1795. {
  1796. public:
  1797. /// Type of job implemented by this class.
  1798. static constexpr EType JobType = EType::RawJob;
  1799. ///
  1800. /// @brief This method is called exactly once for the whole job input.
  1801. virtual void Do(const TRawJobContext& jobContext) = 0;
  1802. };
  1803. ///
  1804. /// @brief Interface of jobs that run the given bash command.
  1805. class ICommandJob
  1806. : public IJob
  1807. {
  1808. public:
  1809. ///
  1810. /// @brief Get bash command to run.
  1811. ///
  1812. /// @note This method is called on the client side.
  1813. virtual const TString& GetCommand() const = 0;
  1814. };
  1815. ///
  1816. /// @brief Raw job executing given bash command.
  1817. ///
  1818. /// @note The binary will not be uploaded.
  1819. class TCommandRawJob
  1820. : public IRawJob
  1821. , public ICommandJob
  1822. {
  1823. public:
  1824. ///
  1825. /// @brief Create job with specified command.
  1826. ///
  1827. /// @param command Bash command to run.
  1828. explicit TCommandRawJob(TStringBuf command = {});
  1829. const TString& GetCommand() const override;
  1830. void Do(const TRawJobContext& jobContext) override;
  1831. private:
  1832. TString Command_;
  1833. };
  1834. ////////////////////////////////////////////////////////////////////////////////
  1835. ///
  1836. /// @brief Base interface for vanilla jobs.
  1837. ///
  1838. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/vanilla
  1839. class IVanillaJobBase
  1840. : public virtual IStructuredJob
  1841. {
  1842. public:
  1843. /// Type of job implemented by this class.
  1844. static constexpr EType JobType = EType::VanillaJob;
  1845. };
  1846. template <class TW = void>
  1847. class IVanillaJob;
  1848. ///
  1849. /// @brief Interface of vanilla job without outputs.
  1850. template <>
  1851. class IVanillaJob<void>
  1852. : public IVanillaJobBase
  1853. {
  1854. public:
  1855. ///
  1856. /// @brief This method is called exactly once for each vanilla job.
  1857. virtual void Do() = 0;
  1858. virtual TStructuredRowStreamDescription GetInputRowStreamDescription() const override;
  1859. virtual TStructuredRowStreamDescription GetOutputRowStreamDescription() const override;
  1860. };
  1861. ///
  1862. /// @brief Vanilla job executing given bash command.
  1863. ///
  1864. /// @note The binary will not be uploaded.
  1865. class TCommandVanillaJob
  1866. : public IVanillaJob<>
  1867. , public ICommandJob
  1868. {
  1869. public:
  1870. ///
  1871. /// @brief Create job with specified command.
  1872. ///
  1873. /// @param command Bash command to run.
  1874. explicit TCommandVanillaJob(TStringBuf command = {});
  1875. const TString& GetCommand() const override;
  1876. void Do() override;
  1877. private:
  1878. TString Command_;
  1879. };
  1880. ///
  1881. /// @brief Interface for vanilla jobs with output tables.
  1882. template <class TW>
  1883. class IVanillaJob
  1884. : public IVanillaJobBase
  1885. {
  1886. public:
  1887. using TWriter = TW;
  1888. public:
  1889. ///
  1890. /// @brief This method is called before `Do` method.
  1891. virtual void Start(TWriter* /* writer */)
  1892. { }
  1893. ///
  1894. /// @brief This method is called exactly once for each vanilla job.
  1895. ///
  1896. /// Write output rows to `writer`.
  1897. virtual void Do(TWriter* writer) = 0;
  1898. ///
  1899. /// @brief This method is called after `Do` method.
  1900. virtual void Finish(TWriter* /* writer */)
  1901. { }
  1902. virtual TStructuredRowStreamDescription GetInputRowStreamDescription() const override;
  1903. virtual TStructuredRowStreamDescription GetOutputRowStreamDescription() const override;
  1904. };
  1905. ////////////////////////////////////////////////////////////////////////////////
  1906. ///
  1907. /// @brief Attributes to request for an operation.
  1908. enum class EOperationAttribute : int
  1909. {
  1910. Id /* "id" */,
  1911. Type /* "type" */,
  1912. State /* "state" */,
  1913. AuthenticatedUser /* "authenticated_user" */,
  1914. StartTime /* "start_time" */,
  1915. FinishTime /* "finish_time" */,
  1916. BriefProgress /* "brief_progress" */,
  1917. BriefSpec /* "brief_spec" */,
  1918. Suspended /* "suspended" */,
  1919. Result /* "result" */,
  1920. Progress /* "progress" */,
  1921. Events /* "events" */,
  1922. Spec /* "spec" */,
  1923. FullSpec /* "full_spec" */,
  1924. UnrecognizedSpec /* "unrecognized_spec" */,
  1925. };
  1926. ///
  1927. /// @brief Class describing which attributes to request in @ref NYT::IClient::GetOperation or @ref NYT::IClient::ListOperations.
  1928. struct TOperationAttributeFilter
  1929. {
  1930. /// @cond Doxygen_Suppress
  1931. using TSelf = TOperationAttributeFilter;
  1932. /// @endcond
  1933. TVector<EOperationAttribute> Attributes_;
  1934. ///
  1935. /// @brief Add attribute to the filter. Calls are supposed to be chained.
  1936. TSelf& Add(EOperationAttribute attribute)
  1937. {
  1938. Attributes_.push_back(attribute);
  1939. return *this;
  1940. }
  1941. };
  1942. ///
  1943. /// @brief Options for @ref NYT::IClient::GetOperation call.
  1944. struct TGetOperationOptions
  1945. {
  1946. /// @cond Doxygen_Suppress
  1947. using TSelf = TGetOperationOptions;
  1948. /// @endcond
  1949. ///
  1950. /// @brief What attributes to request (if omitted, the default set of attributes will be requested).
  1951. FLUENT_FIELD_OPTION(TOperationAttributeFilter, AttributeFilter);
  1952. FLUENT_FIELD_OPTION(bool, IncludeRuntime);
  1953. };
  1954. ///
  1955. /// @brief "Coarse-grained" state of an operation.
  1956. enum class EOperationBriefState : int
  1957. {
  1958. InProgress /* "in_progress" */,
  1959. Completed /* "completed" */,
  1960. Aborted /* "aborted" */,
  1961. /// Failed
  1962. Failed /* "failed" */,
  1963. };
  1964. ///
  1965. /// @brief Operation state.
  1966. enum class EOperationState : int
  1967. {
  1968. None /* "none" */,
  1969. Starting /* "starting" */,
  1970. Orphaned /* "orphaned" */,
  1971. WaitingForAgent /* "waiting_for_agent" */,
  1972. Initializing /* "initializing" */,
  1973. Preparing /* "preparing" */,
  1974. Materializing /* "orphaned" */,
  1975. ReviveInitializing /* "revive_initializing" */,
  1976. Reviving /* "reviving" */,
  1977. RevivingJobs /* "reviving_jobs" */,
  1978. Pending /* "pending" */,
  1979. Running /* "running" */,
  1980. Completing /* "completing" */,
  1981. Completed /* "completed" */,
  1982. Aborting /* "aborting" */,
  1983. Aborted /* "aborted" */,
  1984. Failing /* "failing" */,
  1985. Failed /* "failed" */,
  1986. };
  1987. ///
  1988. /// @brief Operation type.
  1989. enum class EOperationType : int
  1990. {
  1991. Map /* "map" */,
  1992. Merge /* "merge" */,
  1993. Erase /* "erase" */,
  1994. Sort /* "sort" */,
  1995. Reduce /* "reduce" */,
  1996. MapReduce /* "map_reduce" */,
  1997. RemoteCopy /* "remote_copy" */,
  1998. JoinReduce /* "join_reduce" */,
  1999. Vanilla /* "vanilla" */,
  2000. };
  2001. ///
  2002. /// @brief Operation progress.
  2003. struct TOperationProgress
  2004. {
  2005. ///
  2006. /// @brief Total job statistics.
  2007. TJobStatistics JobStatistics;
  2008. ///
  2009. /// @brief Job counter for various job states with hierarchy.
  2010. TJobCounters JobCounters;
  2011. ///
  2012. /// @brief Time when this progress was built on scheduler or CA.
  2013. TMaybe<TInstant> BuildTime;
  2014. };
  2015. ///
  2016. /// @brief Brief operation progress (numbers of jobs in these states).
  2017. struct TOperationBriefProgress
  2018. {
  2019. ui64 Aborted = 0;
  2020. ui64 Completed = 0;
  2021. ui64 Failed = 0;
  2022. ui64 Lost = 0;
  2023. ui64 Pending = 0;
  2024. ui64 Running = 0;
  2025. ui64 Total = 0;
  2026. };
  2027. ///
  2028. /// @brief Operation result.
  2029. struct TOperationResult
  2030. {
  2031. ///
  2032. /// @brief For a unsuccessfully finished operation: description of error.
  2033. TMaybe<TYtError> Error;
  2034. };
  2035. ///
  2036. /// @brief Operation event (change of state).
  2037. struct TOperationEvent
  2038. {
  2039. ///
  2040. /// @brief New state of operation.
  2041. TString State;
  2042. ///
  2043. /// @brief Time of state change.
  2044. TInstant Time;
  2045. };
  2046. ///
  2047. /// @brief Operation info.
  2048. ///
  2049. /// A field may be `Nothing()` either if it was not requested (see @ref NYT::TGetOperationOptions::AttributeFilter)
  2050. /// or it is not available (i.e. `FinishTime` for a running operation).
  2051. /// @see https://ytsaurus.tech/docs/en/api/commands#get_operation
  2052. struct TOperationAttributes
  2053. {
  2054. ///
  2055. /// @brief Operation id.
  2056. TMaybe<TOperationId> Id;
  2057. ///
  2058. /// @brief Operation type.
  2059. TMaybe<EOperationType> Type;
  2060. ///
  2061. /// @brief Operation state.
  2062. TMaybe<TString> State;
  2063. ///
  2064. /// @brief "Coarse-grained" operation state.
  2065. TMaybe<EOperationBriefState> BriefState;
  2066. ///
  2067. /// @brief Name of user that started the operation.
  2068. TMaybe<TString> AuthenticatedUser;
  2069. ///
  2070. /// @brief Operation start time.
  2071. TMaybe<TInstant> StartTime;
  2072. ///
  2073. /// @brief Operation finish time (if the operation has finished).
  2074. TMaybe<TInstant> FinishTime;
  2075. ///
  2076. /// @brief Brief progress of the operation.
  2077. TMaybe<TOperationBriefProgress> BriefProgress;
  2078. ///
  2079. /// @brief Brief spec of operation (light-weight fields only).
  2080. TMaybe<TNode> BriefSpec;
  2081. ///
  2082. /// @brief Spec of the operation as provided by the user.
  2083. TMaybe<TNode> Spec;
  2084. ///
  2085. /// @brief Full spec of operation (all fields not specified by user are filled with default values).
  2086. TMaybe<TNode> FullSpec;
  2087. ///
  2088. /// @brief Fields not recognized by scheduler.
  2089. TMaybe<TNode> UnrecognizedSpec;
  2090. ///
  2091. /// @brief Is operation suspended.
  2092. TMaybe<bool> Suspended;
  2093. ///
  2094. /// @brief Operation result.
  2095. TMaybe<TOperationResult> Result;
  2096. ///
  2097. /// @brief Operation progress.
  2098. TMaybe<TOperationProgress> Progress;
  2099. ///
  2100. /// @brief List of operation events (changes of state).
  2101. TMaybe<TVector<TOperationEvent>> Events;
  2102. ///
  2103. /// @brief Map from alert name to its description.
  2104. TMaybe<THashMap<TString, TYtError>> Alerts;
  2105. };
  2106. ///
  2107. /// @brief Direction of cursor for paging, see @ref NYT::TListOperationsOptions::CursorDirection.
  2108. enum class ECursorDirection
  2109. {
  2110. Past /* "past" */,
  2111. Future /* "future" */,
  2112. };
  2113. ///
  2114. /// @brief Options of @ref NYT::IClient::ListOperations command.
  2115. ///
  2116. /// @see https://ytsaurus.tech/docs/en/api/commands.html#list_operations
  2117. struct TListOperationsOptions
  2118. {
  2119. /// @cond Doxygen_Suppress
  2120. using TSelf = TListOperationsOptions;
  2121. /// @endcond
  2122. ///
  2123. /// @name Time range specification
  2124. ///
  2125. /// List operations with start time in half-closed interval
  2126. /// `[CursorTime, ToTime)` if `CursorDirection == Future` or
  2127. /// `[FromTime, CursorTime)` if `CursorDirection == Past`.
  2128. ///@{
  2129. ///
  2130. /// @brief Search for operations with start time >= `FromTime`.
  2131. FLUENT_FIELD_OPTION(TInstant, FromTime);
  2132. ///
  2133. /// @brief Search for operations with start time < `ToTime`.
  2134. FLUENT_FIELD_OPTION(TInstant, ToTime);
  2135. ///
  2136. /// @brief Additional restriction on operation start time (useful for pagination).
  2137. ///
  2138. /// Search for operations with start time >= `CursorTime` if `CursorDirection == Future`
  2139. /// and with start time < `CursorTime` if `CursorDirection == Past`
  2140. FLUENT_FIELD_OPTION(TInstant, CursorTime);
  2141. ///
  2142. /// @brief Direction of pagination (see @ref NYT::TListOperationsOptions::CursorTime).
  2143. FLUENT_FIELD_OPTION(ECursorDirection, CursorDirection);
  2144. ///@}
  2145. ///
  2146. /// @name Filters
  2147. /// Choose operations satisfying given filters.
  2148. ///@{
  2149. ///
  2150. /// @brief Search for `Filter` as a substring in operation text factors
  2151. /// (e.g. title or input/output table paths).
  2152. FLUENT_FIELD_OPTION(TString, Filter);
  2153. ///
  2154. /// @brief Choose operations whose pools include `Pool`.
  2155. FLUENT_FIELD_OPTION(TString, Pool);
  2156. ///
  2157. /// @brief Choose operations with given @ref NYT::TOperationAttributes::AuthenticatedUser.
  2158. FLUENT_FIELD_OPTION(TString, User);
  2159. ///
  2160. /// @brief Choose operations with given @ref NYT::TOperationAttributes::State.
  2161. FLUENT_FIELD_OPTION(EOperationState, State);
  2162. ///
  2163. /// @brief Choose operations with given @ref NYT::TOperationAttributes::Type.
  2164. FLUENT_FIELD_OPTION(EOperationType, Type);
  2165. ///
  2166. /// @brief Choose operations having (or not having) any failed jobs.
  2167. FLUENT_FIELD_OPTION(bool, WithFailedJobs);
  2168. ///@}
  2169. ///
  2170. /// @brief Search for operations in the archive in addition to Cypress.
  2171. FLUENT_FIELD_OPTION(bool, IncludeArchive);
  2172. ///
  2173. /// @brief Include the counters for different filter parameters in the response.
  2174. ///
  2175. /// Include number of operations for each pool, user, state, type
  2176. /// and the number of operations having failed jobs.
  2177. FLUENT_FIELD_OPTION(bool, IncludeCounters);
  2178. ///
  2179. /// @brief Return no more than `Limit` operations (current default and maximum value is 1000).
  2180. FLUENT_FIELD_OPTION(i64, Limit);
  2181. };
  2182. ///
  2183. /// @brief Response for @ref NYT::IClient::ListOperations command.
  2184. struct TListOperationsResult
  2185. {
  2186. ///
  2187. /// @brief Found operations' attributes.
  2188. TVector<TOperationAttributes> Operations;
  2189. ///
  2190. /// @name Counters for different filter.
  2191. ///
  2192. /// If counters were requested (@ref NYT::TListOperationsOptions::IncludeCounters is `true`)
  2193. /// the maps contain the number of operations found for each pool, user, state and type.
  2194. /// NOTE:
  2195. /// 1) Counters ignore CursorTime and CursorDirection,
  2196. /// they always are collected in the whole [FromTime, ToTime) interval.
  2197. /// 2) Each next counter in the sequence [pool, user, state, type, with_failed_jobs]
  2198. /// takes into account all the previous filters (i.e. if you set User filter to "some-user"
  2199. /// type counts describe only operations with user "some-user").
  2200. /// @{
  2201. ///
  2202. /// @brief Number of operations for each pool.
  2203. TMaybe<THashMap<TString, i64>> PoolCounts;
  2204. ///
  2205. /// @brief Number of operations for each user (subject to previous filters).
  2206. TMaybe<THashMap<TString, i64>> UserCounts;
  2207. ///
  2208. /// @brief Number of operations for each state (subject to previous filters).
  2209. TMaybe<THashMap<TString, i64>> StateCounts;
  2210. ///
  2211. /// @brief Number of operations for each type (subject to previous filters).
  2212. TMaybe<THashMap<EOperationType, i64>> TypeCounts;
  2213. ///
  2214. /// @brief Number of operations having failed jobs (subject to all previous filters).
  2215. TMaybe<i64> WithFailedJobsCount;
  2216. /// @}
  2217. ///
  2218. /// @brief Whether some operations were not returned due to @ref NYT::TListOperationsOptions::Limit.
  2219. ///
  2220. /// `Incomplete == true` means that not all operations satisfying filters
  2221. /// were returned (limit exceeded) and you need to repeat the request with new @ref NYT::TListOperationsOptions::CursorTime
  2222. /// (e.g. `CursorTime == *Operations.back().StartTime`, but don't forget to
  2223. /// remove the duplicates).
  2224. bool Incomplete;
  2225. };
  2226. ////////////////////////////////////////////////////////////////////////////////
  2227. ///
  2228. /// @brief Data source for @ref NYT::IClient::ListJobs command.
  2229. enum class EListJobsDataSource : int
  2230. {
  2231. Runtime /* "runtime" */,
  2232. Archive /* "archive" */,
  2233. Auto /* "auto" */,
  2234. Manual /* "manual" */,
  2235. };
  2236. ///
  2237. /// @brief Job type.
  2238. enum class EJobType : int
  2239. {
  2240. Map /* "map" */,
  2241. PartitionMap /* "partition_map" */,
  2242. SortedMerge /* "sorted_merge" */,
  2243. OrderedMerge /* "ordered_merge" */,
  2244. UnorderedMerge /* "unordered_merge" */,
  2245. Partition /* "partition" */,
  2246. SimpleSort /* "simple_sort" */,
  2247. FinalSort /* "final_sort" */,
  2248. SortedReduce /* "sorted_reduce" */,
  2249. PartitionReduce /* "partition_reduce" */,
  2250. ReduceCombiner /* "reduce_combiner" */,
  2251. RemoteCopy /* "remote_copy" */,
  2252. IntermediateSort /* "intermediate_sort" */,
  2253. OrderedMap /* "ordered_map" */,
  2254. JoinReduce /* "join_reduce" */,
  2255. Vanilla /* "vanilla" */,
  2256. SchedulerUnknown /* "scheduler_unknown" */,
  2257. ReplicateChunk /* "replicate_chunk" */,
  2258. RemoveChunk /* "remove_chunk" */,
  2259. RepairChunk /* "repair_chunk" */,
  2260. SealChunk /* "seal_chunk" */,
  2261. ShallowMerge /* "shallow_merge" */,
  2262. MergeChunks /* "merge_chunks" */,
  2263. AutotomizeChunk /* "autotomize_chunk" */,
  2264. ReincarnateChunk /* "reincarnate_chunk" */,
  2265. };
  2266. ///
  2267. /// @brief Well-known task names.
  2268. enum class ETaskName : int
  2269. {
  2270. Map /* "map" */,
  2271. PartitionMap0 /* "partition_map(0)" */,
  2272. SortedMerge /* "sorted_merge" */,
  2273. OrderedMerge /* "ordered_merge" */,
  2274. UnorderedMerge /* "unordered_merge" */,
  2275. Partition0 /* "partition(0)" */,
  2276. Partition1 /* "partition(1)" */,
  2277. Partition2 /* "partition(2)" */,
  2278. SimpleSort /* "simple_sort" */,
  2279. FinalSort /* "final_sort" */,
  2280. SortedReduce /* "sorted_reduce" */,
  2281. PartitionReduce /* "partition_reduce" */,
  2282. ReduceCombiner /* "reduce_combiner" */,
  2283. RemoteCopy /* "remote_copy" */,
  2284. IntermediateSort /* "intermediate_sort" */,
  2285. OrderedMap /* "ordered_map" */,
  2286. JoinReduce /* "join_reduce" */,
  2287. };
  2288. ///
  2289. /// @brief Task name (can either well-known or just a string).
  2290. class TTaskName
  2291. {
  2292. public:
  2293. // Constructors are implicit by design.
  2294. ///
  2295. /// @brief Construct a custom task name.
  2296. TTaskName(TString taskName);
  2297. ///
  2298. /// @brief Construct a custom task name.
  2299. TTaskName(const char* taskName);
  2300. ///
  2301. /// @brief Construct a well-known task name.
  2302. TTaskName(ETaskName taskName);
  2303. const TString& Get() const;
  2304. private:
  2305. TString TaskName_;
  2306. };
  2307. ///
  2308. /// @brief Job state.
  2309. enum class EJobState : int
  2310. {
  2311. None /* "none" */,
  2312. Waiting /* "waiting" */,
  2313. Running /* "running" */,
  2314. Aborting /* "aborting" */,
  2315. Completed /* "completed" */,
  2316. Failed /* "failed" */,
  2317. Aborted /* "aborted" */,
  2318. Lost /* "lost" */,
  2319. };
  2320. ///
  2321. /// @brief Job sort field.
  2322. ///
  2323. /// @see @ref NYT::TListJobsOptions.
  2324. enum class EJobSortField : int
  2325. {
  2326. Type /* "type" */,
  2327. State /* "state" */,
  2328. StartTime /* "start_time" */,
  2329. FinishTime /* "finish_time" */,
  2330. Address /* "address" */,
  2331. Duration /* "duration" */,
  2332. Progress /* "progress" */,
  2333. Id /* "id" */,
  2334. TaskName /* "task_name" */,
  2335. };
  2336. ///
  2337. /// @brief Job sort direction.
  2338. ///
  2339. /// @see @ref NYT::TListJobsOptions.
  2340. enum class EJobSortDirection : int
  2341. {
  2342. Ascending /* "ascending" */,
  2343. Descending /* "descending" */,
  2344. };
  2345. ///
  2346. /// @brief Options for @ref NYT::IClient::ListJobs.
  2347. ///
  2348. /// @see https://ytsaurus.tech/docs/en/api/commands.html#list_jobs
  2349. struct TListJobsOptions
  2350. {
  2351. /// @cond Doxygen_Suppress
  2352. using TSelf = TListJobsOptions;
  2353. /// @endcond
  2354. ///
  2355. /// @name Filters
  2356. /// Return only jobs with given value of parameter (type, state, address and existence of stderr).
  2357. /// If a field is `Nothing()`, return jobs with all possible values of the corresponding parameter.
  2358. /// @{
  2359. ///
  2360. /// @brief Job type.
  2361. FLUENT_FIELD_OPTION(EJobType, Type);
  2362. ///
  2363. /// @brief Job state.
  2364. FLUENT_FIELD_OPTION(EJobState, State);
  2365. ///
  2366. /// @brief Address of the cluster node where job was running.
  2367. FLUENT_FIELD_OPTION(TString, Address);
  2368. ///
  2369. /// @brief Return only jobs whose stderr has been saved.
  2370. FLUENT_FIELD_OPTION(bool, WithStderr);
  2371. ///
  2372. /// @brief Return only jobs whose spec has been saved.
  2373. FLUENT_FIELD_OPTION(bool, WithSpec);
  2374. ///
  2375. /// @brief Return only jobs whose fail context has been saved.
  2376. FLUENT_FIELD_OPTION(bool, WithFailContext);
  2377. ///
  2378. /// @brief Return only jobs with monitoring descriptor.
  2379. FLUENT_FIELD_OPTION(bool, WithMonitoringDescriptor);
  2380. ///
  2381. /// @brief Return only jobs with given operation incarnation.
  2382. FLUENT_FIELD_OPTION(TString, OperationIncarnation);
  2383. ///
  2384. /// @brief Search for jobs with start time >= `FromTime`.
  2385. FLUENT_FIELD_OPTION(TInstant, FromTime);
  2386. ///
  2387. /// @brief Search for jobs with start time <= `ToTime`.
  2388. FLUENT_FIELD_OPTION(TInstant, ToTime);
  2389. ///
  2390. /// @brief Search for jobs with filters encoded in token.
  2391. FLUENT_FIELD_OPTION(TString, ContinuationToken);
  2392. /// @}
  2393. ///
  2394. /// @name Sort options
  2395. /// @{
  2396. ///
  2397. /// @brief Sort by this field.
  2398. FLUENT_FIELD_OPTION(EJobSortField, SortField);
  2399. ///
  2400. /// @brief Sort order.
  2401. FLUENT_FIELD_OPTION(ESortOrder, SortOrder);
  2402. /// @}
  2403. ///
  2404. /// @brief Data source.
  2405. ///
  2406. /// Where to search for jobs: in scheduler and Cypress ('Runtime'), in archive ('Archive'),
  2407. /// automatically basing on operation presence in Cypress ('Auto') or choose manually (`Manual').
  2408. FLUENT_FIELD_OPTION(EListJobsDataSource, DataSource);
  2409. /// @deprecated
  2410. FLUENT_FIELD_OPTION(bool, IncludeCypress);
  2411. /// @deprecated
  2412. FLUENT_FIELD_OPTION(bool, IncludeControllerAgent);
  2413. /// @deprecated
  2414. FLUENT_FIELD_OPTION(bool, IncludeArchive);
  2415. ///
  2416. /// @brief Maximum number of jobs to return.
  2417. FLUENT_FIELD_OPTION(i64, Limit);
  2418. ///
  2419. /// @brief Number of jobs (in specified sort order) to skip.
  2420. ///
  2421. /// Together with @ref NYT::TListJobsOptions::Limit may be used for pagination.
  2422. FLUENT_FIELD_OPTION(i64, Offset);
  2423. };
  2424. ///
  2425. /// @brief Description of a core dump that happened in the job.
  2426. struct TCoreInfo
  2427. {
  2428. i64 ProcessId;
  2429. TString ExecutableName;
  2430. TMaybe<ui64> Size;
  2431. TMaybe<TYtError> Error;
  2432. };
  2433. ///
  2434. /// @brief Job attributes.
  2435. ///
  2436. /// A field may be `Nothing()` if it is not available (i.e. `FinishTime` for a running job).
  2437. ///
  2438. /// @see https://ytsaurus.tech/docs/en/api/commands#get_job
  2439. struct TJobAttributes
  2440. {
  2441. ///
  2442. /// @brief Job id.
  2443. TMaybe<TJobId> Id;
  2444. ///
  2445. /// @brief Job type
  2446. TMaybe<EJobType> Type;
  2447. ///
  2448. /// @brief Job state.
  2449. TMaybe<EJobState> State;
  2450. ///
  2451. /// @brief Address of a cluster node where job was running.
  2452. TMaybe<TString> Address;
  2453. ///
  2454. /// @brief The name of the task that job corresponds to.
  2455. TMaybe<TString> TaskName;
  2456. ///
  2457. /// @brief Job start time.
  2458. TMaybe<TInstant> StartTime;
  2459. ///
  2460. /// @brief Job finish time (for a finished job).
  2461. TMaybe<TInstant> FinishTime;
  2462. ///
  2463. /// @brief Estimated ratio of job's completed work.
  2464. TMaybe<double> Progress;
  2465. ///
  2466. /// @brief Size of saved job stderr.
  2467. TMaybe<i64> StderrSize;
  2468. ///
  2469. /// @brief Error for a unsuccessfully finished job.
  2470. TMaybe<TYtError> Error;
  2471. ///
  2472. /// @brief Job brief statistics.
  2473. TMaybe<TNode> BriefStatistics;
  2474. ///
  2475. /// @brief Job input paths (with ranges).
  2476. TMaybe<TVector<TRichYPath>> InputPaths;
  2477. ///
  2478. /// @brief Infos for core dumps produced by job.
  2479. TMaybe<TVector<TCoreInfo>> CoreInfos;
  2480. };
  2481. ///
  2482. /// @brief Response for @ref NYT::IOperation::ListJobs.
  2483. struct TListJobsResult
  2484. {
  2485. ///
  2486. /// @brief Jobs.
  2487. TVector<TJobAttributes> Jobs;
  2488. ///
  2489. /// @deprecated
  2490. TMaybe<i64> CypressJobCount;
  2491. ///
  2492. /// @brief Number of jobs retrieved from controller agent.
  2493. TMaybe<i64> ControllerAgentJobCount;
  2494. ///
  2495. /// @brief Number of jobs retrieved from archive.
  2496. TMaybe<i64> ArchiveJobCount;
  2497. };
  2498. ////////////////////////////////////////////////////////////////////////////////
  2499. ///
  2500. /// @brief Options for @ref NYT::IClient::GetJob.
  2501. struct TGetJobOptions
  2502. {
  2503. /// @cond Doxygen_Suppress
  2504. using TSelf = TGetJobOptions;
  2505. /// @endcond
  2506. };
  2507. ///
  2508. /// @brief Options for @ref NYT::IClient::GetJobInput.
  2509. struct TGetJobInputOptions
  2510. {
  2511. /// @cond Doxygen_Suppress
  2512. using TSelf = TGetJobInputOptions;
  2513. /// @endcond
  2514. };
  2515. ///
  2516. /// @brief Options for @ref NYT::IClient::GetJobFailContext.
  2517. struct TGetJobFailContextOptions
  2518. {
  2519. /// @cond Doxygen_Suppress
  2520. using TSelf = TGetJobFailContextOptions;
  2521. /// @endcond
  2522. };
  2523. ///
  2524. /// @brief Options for @ref NYT::IClient::GetJobStderr.
  2525. struct TGetJobStderrOptions
  2526. {
  2527. /// @cond Doxygen_Suppress
  2528. using TSelf = TGetJobStderrOptions;
  2529. /// @endcond
  2530. };
  2531. ////////////////////////////////////////////////////////////////////////////////
  2532. ///
  2533. /// @brief Options for @ref NYT::IOperation::GetFailedJobInfo.
  2534. struct TGetFailedJobInfoOptions
  2535. {
  2536. /// @cond Doxygen_Suppress
  2537. using TSelf = TGetFailedJobInfoOptions;
  2538. /// @endcond
  2539. ///
  2540. /// @brief How many jobs to download. Which jobs will be chosen is undefined.
  2541. FLUENT_FIELD_DEFAULT(ui64, MaxJobCount, 10);
  2542. ///
  2543. /// @brief How much of stderr tail should be downloaded.
  2544. FLUENT_FIELD_DEFAULT(ui64, StderrTailSize, 64 * 1024);
  2545. };
  2546. ////////////////////////////////////////////////////////////////////////////////
  2547. ///
  2548. /// @brief Options for @ref NYT::IClient::GetJobTrace.
  2549. struct TGetJobTraceOptions
  2550. {
  2551. /// @cond Doxygen_Suppress
  2552. using TSelf = TGetJobTraceOptions;
  2553. /// @endcond
  2554. ///
  2555. /// @brief Id of the job.
  2556. FLUENT_FIELD_OPTION(TJobId, JobId);
  2557. ///
  2558. /// @brief Id of the trace.
  2559. FLUENT_FIELD_OPTION(TJobTraceId, TraceId);
  2560. ///
  2561. /// @brief Search for traces with time >= `FromTime`.
  2562. FLUENT_FIELD_OPTION(i64, FromTime);
  2563. ///
  2564. /// @brief Search for traces with time <= `ToTime`.
  2565. FLUENT_FIELD_OPTION(i64, ToTime);
  2566. ///
  2567. /// @brief Search for traces with event index >= `FromEventIndex`.
  2568. FLUENT_FIELD_OPTION(i64, FromEventIndex);
  2569. ///
  2570. /// @brief Search for traces with event index >= `ToEventIndex`.
  2571. FLUENT_FIELD_OPTION(i64, ToEventIndex);
  2572. };
  2573. ///
  2574. /// @brief Response for @ref NYT::IOperation::GetJobTrace.
  2575. struct TJobTraceEvent
  2576. {
  2577. ///
  2578. /// @brief Id of the operation.
  2579. TOperationId OperationId;
  2580. ///
  2581. /// @brief Id of the job.
  2582. TJobId JobId;
  2583. ///
  2584. /// @brief Id of the trace.
  2585. TJobTraceId TraceId;
  2586. ///
  2587. /// @brief Index of the trace event.
  2588. i64 EventIndex;
  2589. ///
  2590. /// @brief Raw evenr in json format.
  2591. TString Event;
  2592. ///
  2593. /// @brief Time of the event.
  2594. TInstant EventTime;
  2595. };
  2596. ////////////////////////////////////////////////////////////////////////////////
  2597. ///
  2598. /// @brief Interface representing an operation.
  2599. struct IOperation
  2600. : public TThrRefBase
  2601. {
  2602. virtual ~IOperation() = default;
  2603. ///
  2604. /// @brief Get operation id.
  2605. virtual const TOperationId& GetId() const = 0;
  2606. ///
  2607. /// @brief Get URL of the operation in YT Web UI.
  2608. virtual TString GetWebInterfaceUrl() const = 0;
  2609. ///
  2610. /// @brief Get last error for not started operations. Get state on YT cluster for started operations.
  2611. ///
  2612. /// For not started operations last error is an error that's being retried during operation
  2613. /// preparation/start (e.g. lock files, start operation request).
  2614. virtual TString GetStatus() const = 0;
  2615. ///
  2616. /// @brief Get preparation future.
  2617. ///
  2618. /// @return future that is set when operation is prepared.
  2619. virtual ::NThreading::TFuture<void> GetPreparedFuture() = 0;
  2620. ///
  2621. /// @brief Start operation synchronously.
  2622. ///
  2623. /// @note: Do NOT call this method twice.
  2624. ///
  2625. /// If operation is not prepared yet, Start() will block waiting for preparation finish.
  2626. /// Be ready to catch exception if operation preparation or start failed.
  2627. virtual void Start() = 0;
  2628. ///
  2629. /// @brief Is the operation started
  2630. ///
  2631. /// Returns true if the operation is started on the cluster
  2632. virtual bool IsStarted() const = 0;
  2633. ///
  2634. /// @brief Get start future.
  2635. ///
  2636. /// @return future that is set when operation is started.
  2637. virtual ::NThreading::TFuture<void> GetStartedFuture() = 0;
  2638. ///
  2639. /// @brief Start watching operation.
  2640. ///
  2641. /// @return future that is set when operation is complete.
  2642. ///
  2643. /// @note: the user should check value of returned future to ensure that operation completed successfully e.g.
  2644. /// @code{.cpp}
  2645. /// auto operationComplete = operation->Watch();
  2646. /// operationComplete.Wait();
  2647. /// operationComplete.GetValue(); /// will throw if operation completed with errors
  2648. /// @endcode
  2649. ///
  2650. /// If operation is completed successfully the returned future contains void value.
  2651. /// If operation is completed with error future contains @ref NYT::TOperationFailedError.
  2652. /// In rare cases when error occurred while waiting (e.g. YT become unavailable) future might contain other exception.
  2653. virtual ::NThreading::TFuture<void> Watch() = 0;
  2654. ///
  2655. /// @brief Get information about failed jobs.
  2656. ///
  2657. /// Can be called for operation in any stage.
  2658. /// Though user should keep in mind that this method always fetches info from cypress
  2659. /// and doesn't work when operation is archived. Successfully completed operations can be archived
  2660. /// quite quickly (in about ~30 seconds).
  2661. virtual TVector<TFailedJobInfo> GetFailedJobInfo(const TGetFailedJobInfoOptions& options = TGetFailedJobInfoOptions()) = 0;
  2662. ///
  2663. /// Get operation brief state.
  2664. virtual EOperationBriefState GetBriefState() = 0;
  2665. ///
  2666. /// @brief Get error (if operation has failed).
  2667. ///
  2668. /// @return `Nothing()` if operation is in 'Completed' or 'InProgress' state (or reason for failed / aborted operation).
  2669. virtual TMaybe<TYtError> GetError() = 0;
  2670. ///
  2671. /// Get job statistics.
  2672. virtual TJobStatistics GetJobStatistics() = 0;
  2673. ///
  2674. /// Get operation progress.
  2675. ///
  2676. /// @return `Nothing()` if operation has no running jobs yet, e.g. when it is in "materializing" or "pending" state.
  2677. virtual TMaybe<TOperationBriefProgress> GetBriefProgress() = 0;
  2678. ///
  2679. /// @brief Abort operation.
  2680. ///
  2681. /// Operation will be finished immediately.
  2682. /// All results of completed/running jobs will be lost.
  2683. ///
  2684. /// @see https://ytsaurus.tech/docs/en/api/commands#abort_op
  2685. virtual void AbortOperation() = 0;
  2686. ///
  2687. /// @brief Complete operation.
  2688. ///
  2689. /// Operation will be finished immediately.
  2690. /// All results of completed jobs will appear in output tables.
  2691. /// All results of running (not completed) jobs will be lost.
  2692. ///
  2693. /// @see https://ytsaurus.tech/docs/en/api/commands#complete_op
  2694. virtual void CompleteOperation() = 0;
  2695. ///
  2696. /// @brief Suspend operation.
  2697. ///
  2698. /// Jobs will not be aborted by default, c.f. @ref NYT::TSuspendOperationOptions.
  2699. ///
  2700. /// @see https://ytsaurus.tech/docs/en/api/commands#suspend_op
  2701. virtual void SuspendOperation(
  2702. const TSuspendOperationOptions& options = TSuspendOperationOptions()) = 0;
  2703. ///
  2704. /// @brief Resume previously suspended operation.
  2705. ///
  2706. /// @see https://ytsaurus.tech/docs/en/api/commands#resume_op
  2707. virtual void ResumeOperation(
  2708. const TResumeOperationOptions& options = TResumeOperationOptions()) = 0;
  2709. ///
  2710. /// @brief Get operation attributes.
  2711. ///
  2712. /// @see https://ytsaurus.tech/docs/en/api/commands#get_operation
  2713. virtual TOperationAttributes GetAttributes(
  2714. const TGetOperationOptions& options = TGetOperationOptions()) = 0;
  2715. ///
  2716. /// @brief Update operation runtime parameters.
  2717. ///
  2718. /// @see https://ytsaurus.tech/docs/en/api/commands#update_op_parameters
  2719. virtual void UpdateParameters(
  2720. const TUpdateOperationParametersOptions& options = TUpdateOperationParametersOptions()) = 0;
  2721. ///
  2722. /// @brief Get job attributes.
  2723. ///
  2724. /// @see https://ytsaurus.tech/docs/en/api/commands#get_job
  2725. virtual TJobAttributes GetJob(
  2726. const TJobId& jobId,
  2727. const TGetJobOptions& options = TGetJobOptions()) = 0;
  2728. ///
  2729. /// List jobs satisfying given filters (see @ref NYT::TListJobsOptions).
  2730. ///
  2731. /// @see https://ytsaurus.tech/docs/en/api/commands#list_jobs
  2732. virtual TListJobsResult ListJobs(
  2733. const TListJobsOptions& options = TListJobsOptions()) = 0;
  2734. };
  2735. ///
  2736. /// @brief Interface of client capable of managing operations.
  2737. struct IOperationClient
  2738. {
  2739. ///
  2740. /// @brief Run Map operation.
  2741. ///
  2742. /// @param spec Operation spec.
  2743. /// @param mapper Instance of a job to run.
  2744. /// @param options Optional parameters.
  2745. ///
  2746. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/map
  2747. IOperationPtr Map(
  2748. const TMapOperationSpec& spec,
  2749. ::TIntrusivePtr<IMapperBase> mapper,
  2750. const TOperationOptions& options = TOperationOptions());
  2751. ///
  2752. /// @brief Run Map operation.
  2753. ///
  2754. /// @param mapper Instance of a job to run.
  2755. /// @param input Input table(s)
  2756. /// @param output Output table(s)
  2757. /// @param spec Operation spec.
  2758. /// @param options Optional parameters.
  2759. ///
  2760. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/map
  2761. IOperationPtr Map(
  2762. ::TIntrusivePtr<IMapperBase> mapper,
  2763. const TOneOrMany<TStructuredTablePath>& input,
  2764. const TOneOrMany<TStructuredTablePath>& output,
  2765. const TMapOperationSpec& spec = TMapOperationSpec(),
  2766. const TOperationOptions& options = TOperationOptions());
  2767. ///
  2768. /// @brief Run raw Map operation.
  2769. ///
  2770. /// @param spec Operation spec.
  2771. /// @param rawJob Instance of a raw mapper to run.
  2772. /// @param options Optional parameters.
  2773. ///
  2774. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/map
  2775. virtual IOperationPtr RawMap(
  2776. const TRawMapOperationSpec& spec,
  2777. ::TIntrusivePtr<IRawJob> rawJob,
  2778. const TOperationOptions& options = TOperationOptions()) = 0;
  2779. ///
  2780. /// @brief Run Reduce operation.
  2781. ///
  2782. /// @param spec Operation spec.
  2783. /// @param reducer Instance of a job to run.
  2784. /// @param options Optional parameters.
  2785. ///
  2786. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce
  2787. IOperationPtr Reduce(
  2788. const TReduceOperationSpec& spec,
  2789. ::TIntrusivePtr<IReducerBase> reducer,
  2790. const TOperationOptions& options = TOperationOptions());
  2791. ///
  2792. /// @brief Run Reduce operation.
  2793. ///
  2794. /// @param reducer Instance of a job to run.
  2795. /// @param input Input table(s)
  2796. /// @param output Output table(s)
  2797. /// @param reduceBy Columns to group rows by.
  2798. /// @param spec Operation spec.
  2799. /// @param options Optional parameters.
  2800. ///
  2801. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce
  2802. IOperationPtr Reduce(
  2803. ::TIntrusivePtr<IReducerBase> reducer,
  2804. const TOneOrMany<TStructuredTablePath>& input,
  2805. const TOneOrMany<TStructuredTablePath>& output,
  2806. const TSortColumns& reduceBy,
  2807. const TReduceOperationSpec& spec = TReduceOperationSpec(),
  2808. const TOperationOptions& options = TOperationOptions());
  2809. ///
  2810. /// @brief Run raw Reduce operation.
  2811. ///
  2812. /// @param spec Operation spec.
  2813. /// @param rawJob Instance of a raw reducer to run.
  2814. /// @param options Optional parameters.
  2815. ///
  2816. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/reduce
  2817. virtual IOperationPtr RawReduce(
  2818. const TRawReduceOperationSpec& spec,
  2819. ::TIntrusivePtr<IRawJob> rawJob,
  2820. const TOperationOptions& options = TOperationOptions()) = 0;
  2821. ///
  2822. /// @brief Run JoinReduce operation.
  2823. ///
  2824. /// @param spec Operation spec.
  2825. /// @param reducer Instance of a job to run.
  2826. /// @param options Optional parameters.
  2827. ///
  2828. /// @deprecated Use @ref NYT::IOperationClient::Reduce with @ref NYT::TReduceOperationSpec::EnableKeyGuarantee set to `false.
  2829. IOperationPtr JoinReduce(
  2830. const TJoinReduceOperationSpec& spec,
  2831. ::TIntrusivePtr<IReducerBase> reducer,
  2832. const TOperationOptions& options = TOperationOptions());
  2833. ///
  2834. /// @brief Run raw JoinReduce operation.
  2835. ///
  2836. /// @param spec Operation spec.
  2837. /// @param rawJob Instance of a raw reducer to run.
  2838. /// @param options Optional parameters.
  2839. ///
  2840. /// @deprecated Use @ref NYT::IOperationClient::RawReduce with @ref NYT::TReduceOperationSpec::EnableKeyGuarantee set to `false.
  2841. virtual IOperationPtr RawJoinReduce(
  2842. const TRawJoinReduceOperationSpec& spec,
  2843. ::TIntrusivePtr<IRawJob> rawJob,
  2844. const TOperationOptions& options = TOperationOptions()) = 0;
  2845. ///
  2846. /// @brief Run MapReduce operation.
  2847. ///
  2848. /// @param spec Operation spec.
  2849. /// @param mapper Instance of a map job to run (identity mapper if `nullptr`).
  2850. /// @param reducer Instance of a reduce job to run.
  2851. /// @param options Optional parameters.
  2852. ///
  2853. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/mapreduce
  2854. IOperationPtr MapReduce(
  2855. const TMapReduceOperationSpec& spec,
  2856. ::TIntrusivePtr<IMapperBase> mapper,
  2857. ::TIntrusivePtr<IReducerBase> reducer,
  2858. const TOperationOptions& options = TOperationOptions());
  2859. ///
  2860. /// @brief Run MapReduce operation.
  2861. ///
  2862. /// @param spec Operation spec.
  2863. /// @param mapper Instance of a map job to run (identity mapper if `nullptr`).
  2864. /// @param reducerCombiner Instance of a reduce combiner to run (identity reduce combiner if `nullptr`).
  2865. /// @param reducer Instance of a reduce job to run.
  2866. /// @param options Optional parameters.
  2867. ///
  2868. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/mapreduce
  2869. IOperationPtr MapReduce(
  2870. const TMapReduceOperationSpec& spec,
  2871. ::TIntrusivePtr<IMapperBase> mapper,
  2872. ::TIntrusivePtr<IReducerBase> reduceCombiner,
  2873. ::TIntrusivePtr<IReducerBase> reducer,
  2874. const TOperationOptions& options = TOperationOptions());
  2875. ///
  2876. /// @brief Run MapReduce operation.
  2877. ///
  2878. /// @param mapper Instance of mapper to run (identity mapper if `nullptr`).
  2879. /// @param reducer Instance of reducer to run.
  2880. /// @param input Input table(s)
  2881. /// @param output Output table(s)
  2882. /// @param reduceBy Columns to group rows by.
  2883. /// @param spec Operation spec.
  2884. /// @param options Optional parameters.
  2885. ///
  2886. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/mapreduce
  2887. IOperationPtr MapReduce(
  2888. ::TIntrusivePtr<IMapperBase> mapper,
  2889. ::TIntrusivePtr<IReducerBase> reducer,
  2890. const TOneOrMany<TStructuredTablePath>& input,
  2891. const TOneOrMany<TStructuredTablePath>& output,
  2892. const TSortColumns& reduceBy,
  2893. TMapReduceOperationSpec spec = TMapReduceOperationSpec(),
  2894. const TOperationOptions& options = TOperationOptions());
  2895. ///
  2896. /// @brief Run MapReduce operation.
  2897. ///
  2898. /// @param mapper Instance of mapper to run (identity mapper if `nullptr`).
  2899. /// @param reduceCombiner Instance of reduceCombiner to run (identity reduce combiner if `nullptr`).
  2900. /// @param reducer Instance of reducer to run.
  2901. /// @param input Input table(s)
  2902. /// @param output Output table(s)
  2903. /// @param reduceBy Columns to group rows by.
  2904. /// @param spec Operation spec.
  2905. /// @param options Optional parameters.
  2906. ///
  2907. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/mapreduce
  2908. IOperationPtr MapReduce(
  2909. ::TIntrusivePtr<IMapperBase> mapper,
  2910. ::TIntrusivePtr<IReducerBase> reduceCombiner,
  2911. ::TIntrusivePtr<IReducerBase> reducer,
  2912. const TOneOrMany<TStructuredTablePath>& input,
  2913. const TOneOrMany<TStructuredTablePath>& output,
  2914. const TSortColumns& reduceBy,
  2915. TMapReduceOperationSpec spec = TMapReduceOperationSpec(),
  2916. const TOperationOptions& options = TOperationOptions());
  2917. ///
  2918. /// @brief Run raw MapReduce operation.
  2919. ///
  2920. /// @param spec Operation spec.
  2921. /// @param mapper Instance of a raw mapper to run (identity mapper if `nullptr`).
  2922. /// @param mapper Instance of a raw reduce combiner to run (identity reduce combiner if `nullptr`).
  2923. /// @param mapper Instance of a raw reducer to run.
  2924. /// @param options Optional parameters.
  2925. ///
  2926. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/mapreduce
  2927. virtual IOperationPtr RawMapReduce(
  2928. const TRawMapReduceOperationSpec& spec,
  2929. ::TIntrusivePtr<IRawJob> mapper,
  2930. ::TIntrusivePtr<IRawJob> reduceCombiner,
  2931. ::TIntrusivePtr<IRawJob> reducer,
  2932. const TOperationOptions& options = TOperationOptions()) = 0;
  2933. ///
  2934. /// @brief Run Sort operation.
  2935. ///
  2936. /// @param spec Operation spec.
  2937. /// @param options Optional parameters.
  2938. ///
  2939. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/sort
  2940. virtual IOperationPtr Sort(
  2941. const TSortOperationSpec& spec,
  2942. const TOperationOptions& options = TOperationOptions()) = 0;
  2943. ///
  2944. /// @brief Run Sort operation.
  2945. ///
  2946. /// @param input Input table(s).
  2947. /// @param output Output table.
  2948. /// @param sortBy Columns to sort input rows by.
  2949. /// @param spec Operation spec.
  2950. /// @param options Optional parameters.
  2951. ///
  2952. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/sort
  2953. IOperationPtr Sort(
  2954. const TOneOrMany<TRichYPath>& input,
  2955. const TRichYPath& output,
  2956. const TSortColumns& sortBy,
  2957. const TSortOperationSpec& spec = TSortOperationSpec(),
  2958. const TOperationOptions& options = TOperationOptions());
  2959. ///
  2960. /// @brief Run Merge operation.
  2961. ///
  2962. /// @param spec Operation spec.
  2963. /// @param options Optional parameters.
  2964. ///
  2965. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/merge
  2966. virtual IOperationPtr Merge(
  2967. const TMergeOperationSpec& spec,
  2968. const TOperationOptions& options = TOperationOptions()) = 0;
  2969. ///
  2970. /// @brief Run Erase operation.
  2971. ///
  2972. /// @param spec Operation spec.
  2973. /// @param options Optional parameters.
  2974. ///
  2975. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/erase
  2976. virtual IOperationPtr Erase(
  2977. const TEraseOperationSpec& spec,
  2978. const TOperationOptions& options = TOperationOptions()) = 0;
  2979. ///
  2980. /// @brief Run RemoteCopy operation.
  2981. ///
  2982. /// @param spec Operation spec.
  2983. /// @param options Optional parameters.
  2984. ///
  2985. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/remote_copy
  2986. virtual IOperationPtr RemoteCopy(
  2987. const TRemoteCopyOperationSpec& spec,
  2988. const TOperationOptions& options = TOperationOptions()) = 0;
  2989. ///
  2990. /// @brief Run Vanilla operation.
  2991. ///
  2992. /// @param spec Operation spec.
  2993. /// @param options Optional parameters.
  2994. ///
  2995. /// @see https://ytsaurus.tech/docs/en/user-guide/data-processing/operations/vanilla
  2996. virtual IOperationPtr RunVanilla(
  2997. const TVanillaOperationSpec& spec,
  2998. const TOperationOptions& options = TOperationOptions()) = 0;
  2999. ///
  3000. /// @brief Abort operation.
  3001. ///
  3002. /// @see https://ytsaurus.tech/docs/en/api/commands#abort_operation
  3003. virtual void AbortOperation(
  3004. const TOperationId& operationId) = 0;
  3005. ///
  3006. /// @brief Complete operation.
  3007. ///
  3008. /// @see https://ytsaurus.tech/docs/en/api/commands#complete_operation
  3009. virtual void CompleteOperation(
  3010. const TOperationId& operationId) = 0;
  3011. ///
  3012. /// @brief Wait for operation to finish.
  3013. virtual void WaitForOperation(
  3014. const TOperationId& operationId) = 0;
  3015. ///
  3016. /// @brief Check and return operation status.
  3017. ///
  3018. /// @note this function will never return @ref NYT::EOperationBriefState::Failed or @ref NYT::EOperationBriefState::Aborted status,
  3019. /// it will throw @ref NYT::TOperationFailedError instead.
  3020. virtual EOperationBriefState CheckOperation(
  3021. const TOperationId& operationId) = 0;
  3022. ///
  3023. /// @brief Create an operation object given operation id.
  3024. ///
  3025. /// @throw @ref NYT::TErrorResponse if the operation doesn't exist.
  3026. virtual IOperationPtr AttachOperation(const TOperationId& operationId) = 0;
  3027. private:
  3028. virtual IOperationPtr DoMap(
  3029. const TMapOperationSpec& spec,
  3030. ::TIntrusivePtr<IStructuredJob> mapper,
  3031. const TOperationOptions& options) = 0;
  3032. virtual IOperationPtr DoReduce(
  3033. const TReduceOperationSpec& spec,
  3034. ::TIntrusivePtr<IStructuredJob> reducer,
  3035. const TOperationOptions& options) = 0;
  3036. virtual IOperationPtr DoJoinReduce(
  3037. const TJoinReduceOperationSpec& spec,
  3038. ::TIntrusivePtr<IStructuredJob> reducer,
  3039. const TOperationOptions& options) = 0;
  3040. virtual IOperationPtr DoMapReduce(
  3041. const TMapReduceOperationSpec& spec,
  3042. ::TIntrusivePtr<IStructuredJob> mapper,
  3043. ::TIntrusivePtr<IStructuredJob> reduceCombiner,
  3044. ::TIntrusivePtr<IStructuredJob> reducer,
  3045. const TOperationOptions& options) = 0;
  3046. };
  3047. ////////////////////////////////////////////////////////////////////////////////
  3048. } // namespace NYT
  3049. #define OPERATION_INL_H_
  3050. #include "operation-inl.h"
  3051. #undef OPERATION_INL_H_