operation.h 114 KB

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