operation.h 113 KB

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