operation.h 110 KB

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