eclhelper.hpp 108 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850
  1. /*##############################################################################
  2. # HPCC SYSTEMS software Copyright (C) 2013 HPCC Systems®.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. ##############################################################################
  16. */
  17. #ifndef ECLHELPER_HPP
  18. #define ECLHELPER_HPP
  19. /*
  20. This file contains interface definitions for the meta-information, dataset processing an activities.
  21. It should only contain pure interface definitions or inline functions.
  22. A note on naming conventions:
  23. getXXX implies that the returned value should be released by the caller
  24. queryXXX implies that it should not
  25. Methods named getXXX returning const char * from generated code will return a value that MAY need releasing (via roxiemem)
  26. or that may be constants. Callers should always call roxiemem::ReleaseRoxieRow on the returned value - this will do nothing
  27. if the supplied pointer was not from the roxiemem heap. Usually an OwnedRoxieString is the easiest way to achieve this.
  28. */
  29. #include "jscm.hpp"
  30. #ifndef CHEAP_UCHAR_DEF
  31. #ifdef _USE_ICU
  32. #include "unicode/utf.h"
  33. #else
  34. typedef unsigned short UChar;
  35. #endif
  36. #endif
  37. #include "rtlconst.hpp"
  38. //Should be incremented whenever the virtuals in the context or a helper are changed, so
  39. //that a work unit can't be rerun. Try as hard as possible to retain compatibility.
  40. #define ACTIVITY_INTERFACE_VERSION 202
  41. #define MIN_ACTIVITY_INTERFACE_VERSION 202 //minimum value that is compatible with current interface
  42. typedef unsigned char byte;
  43. #ifndef I64C
  44. #ifdef _WIN32
  45. #define I64C(n) n##i64
  46. #else
  47. #define I64C(n) n##LL
  48. #endif
  49. #endif
  50. typedef unsigned __int64 __uint64;
  51. typedef __uint64 offset_t;
  52. interface IOutputMetaData;
  53. interface ICodeContext;
  54. interface IAtom;
  55. interface IException;
  56. interface IFieldFilter;
  57. class MemoryBuffer;
  58. class StringBuffer;
  59. class rtlRowBuilder;
  60. class Decimal;
  61. struct RtlFieldInfo;
  62. struct RtlTypeInfo;
  63. #ifndef ICOMPARE_DEFINED
  64. #define ICOMPARE_DEFINED
  65. struct ICompare
  66. {
  67. virtual int docompare(const void *,const void *) const =0;
  68. protected:
  69. virtual ~ICompare() {}
  70. };
  71. #endif
  72. #ifndef ICOMPAREEQ_DEFINED
  73. #define ICOMPAREEQ_DEFINED
  74. struct ICompareEq
  75. {
  76. virtual bool match(const void *,const void *) const =0;
  77. protected:
  78. virtual ~ICompareEq() {}
  79. };
  80. #endif
  81. #ifndef IRANGECOMPARE_DEFINED
  82. #define IRANGECOMPARE_DEFINED
  83. struct IRangeCompare
  84. {
  85. virtual int docompare(const void * left,const void * right, unsigned numFields) const =0;
  86. virtual unsigned maxFields() = 0;
  87. protected:
  88. virtual ~IRangeCompare() {}
  89. };
  90. #endif
  91. interface INaryCompareEq
  92. {
  93. virtual bool match(unsigned _num, const void * * _rows) const = 0;
  94. };
  95. interface IEngineRowAllocator;
  96. interface IRowBuilder
  97. {
  98. virtual byte * ensureCapacity(size32_t required, const char * fieldName) = 0;
  99. protected:
  100. virtual byte * createSelf() = 0;
  101. virtual void reportMissingRow() const = 0;
  102. public:
  103. virtual IEngineRowAllocator *queryAllocator() const = 0;
  104. };
  105. class ARowBuilder : public IRowBuilder
  106. {
  107. public:
  108. #ifdef _DEBUG
  109. inline byte * row() const { if (!self) reportMissingRow(); return self; }
  110. #else
  111. inline byte * row() const { return self; }
  112. #endif
  113. inline byte * getSelf()
  114. {
  115. if (self)
  116. return self;
  117. return createSelf();
  118. }
  119. protected:
  120. inline ARowBuilder() { self = NULL; }
  121. protected:
  122. byte * self; //This is embedded as a member to avoid overhead of a virtual call
  123. };
  124. #define COMMON_NEWTHOR_FUNCTIONS \
  125. virtual void Link() const = 0; \
  126. virtual bool Release() const = 0;
  127. #ifndef IRECORDSIZE_DEFINED // also in jio.hpp
  128. #define IRECORDSIZE_DEFINED
  129. interface IRecordSize : public IInterface
  130. {
  131. virtual size32_t getRecordSize(const void *rec) = 0;
  132. virtual size32_t getFixedSize() const = 0;
  133. virtual size32_t getMinRecordSize() const = 0;
  134. inline bool isFixedSize() const { return getFixedSize()!=0; }
  135. inline bool isVariableSize() const { return getFixedSize()==0; }
  136. };
  137. #endif
  138. interface IXmlWriter : public IInterface
  139. {
  140. public:
  141. virtual void outputQuoted(const char *text) = 0;
  142. virtual void outputString(unsigned len, const char *field, const char *fieldname) = 0;
  143. virtual void outputBool(bool field, const char *fieldname) = 0;
  144. virtual void outputData(unsigned len, const void *field, const char *fieldname) = 0;
  145. virtual void outputInt(__int64 field, unsigned size, const char *fieldname) = 0;
  146. virtual void outputUInt(unsigned __int64 field, unsigned size, const char *fieldname) = 0;
  147. virtual void outputReal(double field, const char *fieldname) = 0;
  148. virtual void outputDecimal(const void *field, unsigned size, unsigned precision, const char *fieldname) = 0;
  149. virtual void outputUDecimal(const void *field, unsigned size, unsigned precision, const char *fieldname) = 0;
  150. virtual void outputUnicode(unsigned len, const UChar *field, const char *fieldname) = 0;
  151. virtual void outputQString(unsigned len, const char *field, const char *fieldname) = 0;
  152. virtual void outputBeginDataset(const char *dsname, bool nestChildren) = 0;
  153. virtual void outputEndDataset(const char *dsname) = 0;
  154. virtual void outputBeginNested(const char *fieldname, bool nestChildren) = 0;
  155. virtual void outputEndNested(const char *fieldname) = 0;
  156. virtual void outputSetAll() = 0;
  157. virtual void outputUtf8(unsigned len, const char *field, const char *fieldname) = 0;
  158. virtual void outputBeginArray(const char *fieldname) = 0;
  159. virtual void outputEndArray(const char *fieldname) = 0;
  160. virtual void outputInlineXml(const char *text) = 0; //for appending raw xml content
  161. virtual void outputXmlns(const char *name, const char *uri) = 0;
  162. inline void outputCString(const char *field, const char *fieldname) { outputString((size32_t)strlen(field), field, fieldname); }
  163. };
  164. interface IFieldProcessor : public IInterface
  165. {
  166. public:
  167. virtual void processString(unsigned len, const char *value, const RtlFieldInfo * field) = 0;
  168. virtual void processBool(bool value, const RtlFieldInfo * field) = 0;
  169. virtual void processData(unsigned len, const void *value, const RtlFieldInfo * field) = 0;
  170. virtual void processInt(__int64 value, const RtlFieldInfo * field) = 0;
  171. virtual void processUInt(unsigned __int64 value, const RtlFieldInfo * field) = 0;
  172. virtual void processReal(double value, const RtlFieldInfo * field) = 0;
  173. virtual void processDecimal(const void *value, unsigned digits, unsigned precision, const RtlFieldInfo * field) = 0;
  174. virtual void processUDecimal(const void *value, unsigned digits, unsigned precision, const RtlFieldInfo * field) = 0;
  175. virtual void processUnicode(unsigned len, const UChar *value, const RtlFieldInfo * field) = 0;
  176. virtual void processQString(unsigned len, const char *value, const RtlFieldInfo * field) = 0;
  177. virtual void processUtf8(unsigned len, const char *value, const RtlFieldInfo * field) = 0;
  178. inline void processCString(const char *value, const RtlFieldInfo * field) { processString((size32_t)strlen(value), value, field); }
  179. //The following are used process the structured fields
  180. virtual bool processBeginSet(const RtlFieldInfo * field, unsigned elements, bool isAll, const byte *data) = 0;
  181. virtual bool processBeginDataset(const RtlFieldInfo * field, unsigned rows) = 0;
  182. virtual bool processBeginRow(const RtlFieldInfo * field) = 0; // either in a dataset, or nested
  183. virtual void processEndSet(const RtlFieldInfo * field) = 0;
  184. virtual void processEndDataset(const RtlFieldInfo * field) = 0;
  185. virtual void processEndRow(const RtlFieldInfo * field) = 0;
  186. };
  187. class RtlDynamicRowBuilder;
  188. interface IFieldSource : public IInterface
  189. {
  190. public:
  191. virtual bool getBooleanResult(const RtlFieldInfo *field) = 0;
  192. virtual void getDataResult(const RtlFieldInfo *field, size32_t &len, void * &result) = 0;
  193. virtual double getRealResult(const RtlFieldInfo *field) = 0;
  194. virtual __int64 getSignedResult(const RtlFieldInfo *field) = 0;
  195. virtual unsigned __int64 getUnsignedResult(const RtlFieldInfo *field) = 0;
  196. virtual void getStringResult(const RtlFieldInfo *field, size32_t &len, char * &result) = 0;
  197. virtual void getUTF8Result(const RtlFieldInfo *field, size32_t &chars, char * &result) = 0;
  198. virtual void getUnicodeResult(const RtlFieldInfo *field, size32_t &chars, UChar * &result) = 0;
  199. virtual void getDecimalResult(const RtlFieldInfo *field, Decimal &value) = 0;
  200. //The following are used process the structured fields
  201. virtual void processBeginSet(const RtlFieldInfo * field, bool &isAll) = 0;
  202. virtual void processBeginDataset(const RtlFieldInfo * field) = 0;
  203. virtual void processBeginRow(const RtlFieldInfo * field) = 0;
  204. virtual bool processNextSet(const RtlFieldInfo * field) = 0;
  205. virtual bool processNextRow(const RtlFieldInfo * field) = 0;
  206. virtual void processEndSet(const RtlFieldInfo * field) = 0;
  207. virtual void processEndDataset(const RtlFieldInfo * field) = 0;
  208. virtual void processEndRow(const RtlFieldInfo * field) = 0;
  209. };
  210. // Functions for processing rows - creating, serializing, destroying etc.
  211. interface IOutputRowSerializer;
  212. interface IOutputRowDeserializer;
  213. class CRuntimeStatisticCollection;
  214. interface IEngineRowAllocator : extends IInterface
  215. {
  216. virtual const byte * * createRowset(unsigned _numItems) = 0;
  217. virtual const byte * * linkRowset(const byte * * rowset) = 0;
  218. virtual void releaseRowset(unsigned count, const byte * * rowset) = 0;
  219. virtual const byte * * appendRowOwn(const byte * * rowset, unsigned newRowCount, void * row) = 0;
  220. virtual const byte * * reallocRows(const byte * * rowset, unsigned oldRowCount, unsigned newRowCount) = 0;
  221. virtual void * createRow() = 0;
  222. virtual void releaseRow(const void * row) = 0;
  223. virtual void * linkRow(const void * row) = 0;
  224. //Used for dynamically sizing rows.
  225. virtual void * createRow(size32_t & allocatedSize) = 0;
  226. virtual void * resizeRow(size32_t newSize, void * row, size32_t & size) = 0; //NB: size is updated with the new size
  227. virtual void * finalizeRow(size32_t newSize, void * row, size32_t oldSize) = 0;
  228. virtual IOutputMetaData * queryOutputMeta() = 0;
  229. virtual unsigned queryActivityId() const = 0;
  230. virtual StringBuffer &getId(StringBuffer &) = 0;
  231. virtual IOutputRowSerializer *createDiskSerializer(ICodeContext *ctx = NULL) = 0;
  232. virtual IOutputRowDeserializer *createDiskDeserializer(ICodeContext *ctx) = 0;
  233. virtual IOutputRowSerializer *createInternalSerializer(ICodeContext *ctx = NULL) = 0;
  234. virtual IOutputRowDeserializer *createInternalDeserializer(ICodeContext *ctx) = 0;
  235. virtual IEngineRowAllocator *createChildRowAllocator(const RtlTypeInfo *childtype) = 0;
  236. virtual void gatherStats(CRuntimeStatisticCollection & stats) = 0;
  237. virtual void releaseAllRows() = 0; // Only valid on unique allocators, use with extreme care
  238. };
  239. interface IRowSerializerTarget
  240. {
  241. virtual void put(size32_t len, const void * ptr) = 0;
  242. virtual size32_t beginNested(size32_t count) = 0;
  243. virtual void endNested(size32_t position) = 0;
  244. };
  245. interface IRowDeserializerSource
  246. {
  247. virtual const byte * peek(size32_t maxLen) = 0; // try and ensure up to maxSize bytes are available.
  248. virtual offset_t beginNested() = 0;
  249. virtual bool finishedNested(offset_t & pos) = 0;
  250. virtual size32_t read(size32_t len, void * ptr) = 0;
  251. virtual size32_t readSize() = 0;
  252. virtual size32_t readPackedInt(void * ptr) = 0;
  253. virtual size32_t readUtf8(ARowBuilder & target, size32_t offset, size32_t fixedSize, size32_t len) = 0;
  254. virtual size32_t readVStr(ARowBuilder & target, size32_t offset, size32_t fixedSize) = 0;
  255. virtual size32_t readVUni(ARowBuilder & target, size32_t offset, size32_t fixedSize) = 0;
  256. //Generally called from a prefetcher rather than a deserializer, but could be called from a deserializer that also removed fields.
  257. virtual void skip(size32_t size) = 0;
  258. virtual void skipPackedInt() = 0;
  259. virtual void skipUtf8(size32_t len) = 0;
  260. virtual void skipVStr() = 0;
  261. virtual void skipVUni() = 0;
  262. };
  263. interface IRowPrefetcherSource : extends IRowDeserializerSource
  264. {
  265. virtual const byte * querySelf() = 0; // What is the address of the start of the row being prefetched (or nested dataset)
  266. virtual void noteStartChild() = 0; // start of reading a child row - ensure that querySelf() refers to the child row
  267. virtual void noteFinishChild() = 0; // called when finished reading a child row.
  268. };
  269. interface IOutputRowSerializer : public IInterface
  270. {
  271. public:
  272. virtual void serialize(IRowSerializerTarget & out, const byte * self) = 0;
  273. };
  274. interface IOutputRowDeserializer : public IInterface
  275. {
  276. public:
  277. virtual size32_t deserialize(ARowBuilder & rowBuilder, IRowDeserializerSource & in) = 0;
  278. };
  279. interface ISourceRowPrefetcher : public IInterface
  280. {
  281. public:
  282. virtual void readAhead(IRowPrefetcherSource & in) = 0;
  283. };
  284. //This version number covers adding new functions into the metadata interface, and the serialized field/type information
  285. #define OUTPUTMETADATA_VERSION 2
  286. const char xpathCompoundSeparatorChar = (char)1;
  287. //fieldType is a compound field....
  288. // NOTE - do not change these values - they are stored in serialized type structures e.g. in index metadata
  289. enum RtlFieldTypeMask
  290. {
  291. RFTMkind = 0x000000ff, // values are defined in rtlconst.hpp
  292. RFTMunsigned = 0x00000100, // numeric types only.
  293. RFTMebcdic = 0x00000100, // strings only
  294. RFTMlinkcounted = 0x00000200, // datasets, rows and records only. But possibly strings etc. later...
  295. RFTMislastbitfield = 0x00000200, // is last bitfield.
  296. RFTMunknownsize = 0x00000400, // if set, the field is unknown size - and length is the maximum length
  297. RFTMalien = 0x00000800, // this is the physical format of a user defined type, if unknown size we can't calculate it
  298. RFTMhasnonscalarxpath = 0x00001000, // field xpath contains multiple node, and is not therefore usable for naming scalar fields
  299. RFTMbiased = 0x00002000, // type is stored with a bias
  300. RFTMinifblock = 0x00004000, // on fields only, field is inside an ifblock (not presently generated)
  301. RFTMdynamic = 0x00008000, // Reserved for use by RtlRecord to indicate structure needs to be deleted
  302. RFTMispayloadfield = 0x00010000, // on fields only, field is in payload portion of index or dictionary
  303. // These flags are used in the serialized info only
  304. RFTMserializerFlags = 0x01f00000, // Mask to remove from saved values
  305. RFTMhasChildType = 0x00100000, // type has child type
  306. RFTMhasLocale = 0x00200000, // type has locale
  307. RFTMhasFields = 0x00400000, // type has fields
  308. RFTMhasXpath = 0x00800000, // field has xpath
  309. RFTMhasInitializer = 0x01000000, // field has initialzer
  310. RFTMcontainsunknown = 0x10000000, // contains a field of unknown type that we can't process properly
  311. RFTMinvalidxml = 0x20000000, // cannot be called to generate xml
  312. RFTMhasxmlattr = 0x40000000, // if specified, then xml output includes an attribute (recursive)
  313. RFTMnoserialize = 0x80000000, // cannot serialize this typeinfo structure (contains aliens or other nasties)
  314. RFTMinherited = (RFTMcontainsunknown|RFTMinvalidxml|RFTMhasxmlattr|RFTMnoserialize) // These flags are recursively set on any parent records too
  315. };
  316. //MORE: Can we provide any more useful information about ifblocks E.g., a pseudo field? We can add later if actually useful.
  317. interface IRtlFieldTypeSerializer;
  318. interface IRtlFieldTypeDeserializer;
  319. //Interface used to get field information. Separate from RtlTypeInfo for clarity and to ensure the vmt comes first.
  320. interface RtlITypeInfo
  321. {
  322. virtual size32_t size(const byte * self, const byte * selfrow) const = 0;
  323. virtual size32_t process(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IFieldProcessor & target) const = 0; // returns the size
  324. virtual size32_t toXML(const byte * self, const byte * selfrow, const RtlFieldInfo * field, IXmlWriter & out) const = 0;
  325. virtual const char * queryLocale() const = 0;
  326. virtual const RtlFieldInfo * const * queryFields() const = 0; // null terminated list
  327. virtual const RtlTypeInfo * queryChildType() const = 0;
  328. virtual const IFieldFilter * queryFilter() const = 0;
  329. virtual size32_t build(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, IFieldSource &source) const = 0;
  330. virtual size32_t buildNull(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field) const = 0;
  331. virtual size32_t buildString(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *result) const = 0;
  332. virtual size32_t buildUtf8(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, size32_t len, const char *result) const = 0;
  333. virtual size32_t buildInt(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, __int64 val) const = 0;
  334. virtual size32_t buildReal(ARowBuilder &builder, size32_t offset, const RtlFieldInfo *field, double val) const = 0;
  335. virtual void getString(size32_t & resultLen, char * & result, const void * ptr) const = 0;
  336. virtual void getUtf8(size32_t & resultLen, char * & result, const void * ptr) const = 0;
  337. virtual __int64 getInt(const void * ptr) const = 0;
  338. virtual double getReal(const void * ptr) const = 0;
  339. virtual size32_t getMinSize() const = 0;
  340. virtual size32_t deserialize(ARowBuilder & rowBuilder, IRowDeserializerSource & in, size32_t offset) const = 0;
  341. virtual void readAhead(IRowPrefetcherSource & in) const = 0;
  342. virtual int compare(const byte * left, const byte * right) const = 0;
  343. virtual unsigned hash(const byte * left, unsigned inHash) const = 0;
  344. protected:
  345. ~RtlITypeInfo() = default; // we can't use a virtual destructor as we want constexpr constructors.
  346. };
  347. //The core interface for the field meta information.
  348. struct RtlTypeInfo : public RtlITypeInfo
  349. {
  350. constexpr inline RtlTypeInfo(unsigned _fieldType, unsigned _length) : fieldType(_fieldType), length(_length) {}
  351. // Some inline helper functions to avoid having to interpret the flags.
  352. inline bool canSerialize() const { return (fieldType & RFTMnoserialize) == 0; }
  353. inline bool isEbcdic() const { return (fieldType & RFTMebcdic) != 0; }
  354. inline bool isFixedSize() const { return (fieldType & RFTMunknownsize) == 0; }
  355. inline bool isLinkCounted() const { return (fieldType & RFTMlinkcounted) != 0; }
  356. inline bool isSigned() const { return (fieldType & RFTMunsigned) == 0; }
  357. inline bool isUnsigned() const { return (fieldType & RFTMunsigned) != 0; }
  358. inline unsigned getDecimalDigits() const { return (length & 0xffff); }
  359. inline unsigned getDecimalPrecision() const { return (length >> 16); }
  360. inline unsigned getBitfieldIntSize() const { return (length & 0xff); }
  361. inline unsigned getBitfieldNumBits() const { return (length >> 8) & 0xff; }
  362. inline unsigned getBitfieldShift() const { return (length >> 16) & 0xff; }
  363. inline unsigned getType() const { return (fieldType & RFTMkind); }
  364. virtual bool isScalar() const = 0;
  365. virtual bool isNumeric() const = 0;
  366. virtual bool canTruncate() const = 0;
  367. virtual bool canExtend(char &) const = 0;
  368. virtual bool canMemCmp() const = 0;
  369. virtual void doCleanup() const = 0; // delete any special cached variables.
  370. virtual void doDelete() const = 0; // Used in place of virtual destructor to allow constexpr constructors.
  371. virtual bool equivalent(const RtlTypeInfo *other) const = 0;
  372. public:
  373. unsigned fieldType;
  374. unsigned length; // for bitfield (int-size, # bits, bitoffset) << 16
  375. // for decimal, numdigits | precision << 16
  376. // if RFTMunknownsize then maxlength (records) [maxcount(datasets)]
  377. protected:
  378. ~RtlTypeInfo() = default;
  379. };
  380. //Core struct used for representing meta for a field. Effectively used as an interface.
  381. struct RtlFieldInfo
  382. {
  383. constexpr inline RtlFieldInfo(const char * _name, const char * _xpath, const RtlTypeInfo * _type, unsigned _flags = 0, const char *_initializer = NULL)
  384. : name(_name), xpath(_xpath), type(_type), flags(_type->fieldType | _flags), initializer((const byte *) _initializer) {}
  385. const char * name;
  386. const char * xpath;
  387. const RtlTypeInfo * type;
  388. const byte *initializer;
  389. unsigned flags;
  390. inline bool hasNonScalarXpath() const { return (flags & RFTMhasnonscalarxpath) != 0; }
  391. inline bool omitable() const
  392. {
  393. return (flags & RFTMinifblock)!=0;
  394. }
  395. inline bool isFixedSize() const
  396. {
  397. return type->isFixedSize();
  398. }
  399. inline size32_t size(const byte * self, const byte * selfrow) const
  400. {
  401. return type->size(self, selfrow);
  402. }
  403. inline size32_t build(ARowBuilder &builder, size32_t offset, IFieldSource & source) const
  404. {
  405. return type->build(builder, offset, this, source);
  406. }
  407. inline size32_t process(const byte * self, const byte * selfrow, IFieldProcessor & target) const
  408. {
  409. return type->process(self, selfrow, this, target);
  410. }
  411. inline size32_t toXML(const byte * self, const byte * selfrow, IXmlWriter & target) const
  412. {
  413. return type->toXML(self, selfrow, this, target);
  414. }
  415. bool equivalent(const RtlFieldInfo *to) const;
  416. };
  417. enum
  418. {
  419. MDFgrouped = 0x0001,
  420. MDFhasxml = 0x0002,
  421. MDFneeddestruct = 0x0004,
  422. MDFneedserializedisk = 0x0008,
  423. MDFunknownmaxlength = 0x0010, // max length couldn't be determined from the record structure
  424. MDFhasserialize = 0x0020,
  425. MDFneedserializeinternal= 0x0040,
  426. MDFdiskmatchesinternal = 0x0080,
  427. MDFneedserializemask = (MDFneedserializedisk|MDFneedserializeinternal),
  428. };
  429. interface IIndirectMemberVisitor
  430. {
  431. virtual void visitRowset(size32_t count, const byte * * rows) = 0;
  432. virtual void visitRow(const byte * row) = 0;
  433. //MORE: add new functions if anything else is implemented out of line (e.g., strings)
  434. };
  435. class RtlRecord;
  436. interface IOutputMetaData : public IRecordSize
  437. {
  438. inline bool isGrouped() { return (getMetaFlags() & MDFgrouped) != 0; }
  439. inline bool hasXML() { return (getMetaFlags() & MDFhasxml) != 0; }
  440. virtual void toXML(const byte * self, IXmlWriter & out) = 0;
  441. virtual unsigned getVersion() const = 0;
  442. virtual unsigned getMetaFlags() = 0;
  443. virtual const RtlTypeInfo * queryTypeInfo() const { return NULL; } // non null for meta from generated code
  444. virtual void destruct(byte * self) = 0;
  445. virtual IOutputMetaData * querySerializedDiskMeta() = 0;
  446. virtual IOutputRowSerializer * createDiskSerializer(ICodeContext * ctx, unsigned activityId) = 0; // ctx is currently allowed to be NULL
  447. virtual IOutputRowDeserializer * createDiskDeserializer(ICodeContext * ctx, unsigned activityId) = 0;
  448. virtual ISourceRowPrefetcher * createDiskPrefetcher() = 0;
  449. virtual IOutputRowSerializer * createInternalSerializer(ICodeContext * ctx, unsigned activityId) = 0; // ctx is currently allowed to be NULL
  450. virtual IOutputRowDeserializer * createInternalDeserializer(ICodeContext * ctx, unsigned activityId) = 0;
  451. virtual void process(const byte * self, IFieldProcessor & target, unsigned from, unsigned to) {} // from and to are *hints* for the range of fields to call through with
  452. virtual void walkIndirectMembers(const byte * self, IIndirectMemberVisitor & visitor) = 0;
  453. virtual IOutputMetaData * queryChildMeta(unsigned i) = 0;
  454. virtual const RtlRecord &queryRecordAccessor(bool expand) const = 0;
  455. };
  456. #ifndef IROWSTREAM_DEFINED
  457. #define IROWSTREAM_DEFINED
  458. interface IRowStream : extends IInterface
  459. {
  460. virtual const void *nextRow()=0; // rows returned must be freed
  461. virtual void stop() = 0; // after stop called NULL is returned
  462. inline const void *ungroupedNextRow()
  463. {
  464. const void *ret = nextRow();
  465. if (!ret)
  466. ret = nextRow();
  467. return ret;
  468. }
  469. };
  470. #endif
  471. interface ITypedRowStream : extends IRowStream
  472. {
  473. virtual IOutputMetaData * queryOutputMeta() const = 0;
  474. inline bool isGrouped() { return queryOutputMeta()->isGrouped(); }
  475. };
  476. interface ISetToXmlTransformer
  477. {
  478. virtual void toXML(bool isAll, size32_t len, const byte * self, IXmlWriter & out) = 0;
  479. };
  480. enum
  481. {
  482. XWFtrim = 0x0001,
  483. XWFopt = 0x0002,
  484. XWFnoindent = 0x0004,
  485. XWFexpandempty = 0x0008
  486. };
  487. #ifndef IHASH_DEFINED // may be defined already elsewhere
  488. #define IHASH_DEFINED
  489. interface IHash
  490. {
  491. virtual unsigned hash(const void *data)=0;
  492. protected:
  493. virtual ~IHash() {}
  494. };
  495. #endif
  496. interface IXmlToRowTransformer;
  497. interface ICsvToRowTransformer;
  498. interface IThorDiskCallback;
  499. interface IThorIndexCallback;
  500. interface IIndexReadContext; // this is misnamed!
  501. interface IBlobProvider;
  502. interface IBlobCreator;
  503. //IResourceContext: Frozen unless major version upgrade.
  504. interface IResourceContext
  505. {
  506. virtual const char *loadResource(unsigned id) = 0;
  507. };
  508. //Provided by engine=>can extent
  509. interface IEclGraphResults : public IInterface
  510. {
  511. virtual void getLinkedResult(unsigned & count, const byte * * & ret, unsigned id) = 0;
  512. virtual void getDictionaryResult(size32_t & tcount, const byte * * & tgt, unsigned id) = 0;
  513. virtual const void * getLinkedRowResult(unsigned id) = 0;
  514. };
  515. //Provided by engine=>can extent
  516. //Results are returned so helpers can store a reference and be thread-safe.
  517. interface IThorChildGraph : public IInterface
  518. {
  519. virtual IEclGraphResults * evaluate(unsigned parentExtractSize, const byte * parentExtract) = 0;
  520. };
  521. interface ISectionTimer : public IInterface
  522. {
  523. virtual unsigned __int64 getStartCycles() = 0;
  524. virtual void noteSectionTime(unsigned __int64 startCycles) = 0;
  525. };
  526. //NB: New methods must always be added at the end of this interface to retain backward compatibility
  527. interface IContextLogger;
  528. interface IDebuggableContext;
  529. interface IDistributedFileTransaction;
  530. interface IUserDescriptor;
  531. interface IHThorArg;
  532. interface IHThorHashLookupInfo;
  533. interface IEngineContext;
  534. interface IWorkUnit;
  535. interface ICodeContext : public IResourceContext
  536. {
  537. // Fetching interim results from workunit/query context
  538. virtual bool getResultBool(const char * name, unsigned sequence) = 0;
  539. virtual void getResultData(unsigned & tlen, void * & tgt, const char * name, unsigned sequence) = 0;
  540. virtual void getResultDecimal(unsigned tlen, int precision, bool isSigned, void * tgt, const char * stepname, unsigned sequence) = 0;
  541. virtual void getResultDictionary(size32_t & tcount, const byte * * & tgt, IEngineRowAllocator * _rowAllocator, const char * name, unsigned sequence, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer, IHThorHashLookupInfo * hasher) = 0;
  542. virtual void getResultRaw(unsigned & tlen, void * & tgt, const char * name, unsigned sequence, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer) = 0;
  543. virtual void getResultSet(bool & isAll, size32_t & tlen, void * & tgt, const char * name, unsigned sequence, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer) = 0;
  544. virtual __int64 getResultInt(const char * name, unsigned sequence) = 0;
  545. virtual double getResultReal(const char * name, unsigned sequence) = 0;
  546. virtual void getResultRowset(size32_t & tcount, const byte * * & tgt, const char * name, unsigned sequence, IEngineRowAllocator * _rowAllocator, bool isGrouped, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer) = 0;
  547. virtual void getResultString(unsigned & tlen, char * & tgt, const char * name, unsigned sequence) = 0;
  548. virtual void getResultStringF(unsigned tlen, char * tgt, const char * name, unsigned sequence) = 0;
  549. virtual void getResultUnicode(unsigned & tlen, UChar * & tgt, const char * name, unsigned sequence) = 0;
  550. virtual char *getResultVarString(const char * name, unsigned sequence) = 0;
  551. virtual UChar *getResultVarUnicode(const char * name, unsigned sequence) = 0;
  552. // Writing results to workunit/query context/output
  553. virtual void setResultBool(const char *name, unsigned sequence, bool value) = 0;
  554. virtual void setResultData(const char *name, unsigned sequence, int len, const void * data) = 0;
  555. virtual void setResultDecimal(const char * stepname, unsigned sequence, int len, int precision, bool isSigned, const void *val) = 0;
  556. virtual void setResultInt(const char *name, unsigned sequence, __int64 value, unsigned size) = 0;
  557. virtual void setResultRaw(const char *name, unsigned sequence, int len, const void * data) = 0;
  558. virtual void setResultReal(const char * stepname, unsigned sequence, double value) = 0;
  559. virtual void setResultSet(const char *name, unsigned sequence, bool isAll, size32_t len, const void * data, ISetToXmlTransformer * transformer) = 0;
  560. virtual void setResultString(const char *name, unsigned sequence, int len, const char * str) = 0;
  561. virtual void setResultUInt(const char *name, unsigned sequence, unsigned __int64 value, unsigned size) = 0;
  562. virtual void setResultUnicode(const char *name, unsigned sequence, int len, UChar const * str) = 0;
  563. virtual void setResultVarString(const char * name, unsigned sequence, const char * value) = 0;
  564. virtual void setResultVarUnicode(const char * name, unsigned sequence, UChar const * value) = 0;
  565. // Checking persists etc are up to date
  566. virtual unsigned getResultHash(const char * name, unsigned sequence) = 0;
  567. virtual unsigned __int64 getDatasetHash(const char * name, unsigned __int64 crc) = 0;
  568. // Fetching various environment information, typically accessed via std.system
  569. virtual char *getClusterName() = 0; // caller frees return string.
  570. virtual char *getEnv(const char *name, const char *defaultValue) const = 0;
  571. virtual char *getGroupName() = 0; // caller frees return string.
  572. virtual char *getJobName() = 0; // caller frees return string.
  573. virtual char *getJobOwner() = 0; // caller frees return string.
  574. virtual unsigned getNodeNum() = 0;
  575. virtual unsigned getNodes() = 0;
  576. virtual char *getOS() = 0; // caller frees return string
  577. virtual char *getPlatform() = 0; // caller frees return string.
  578. virtual unsigned getPriority() const = 0;
  579. virtual char *getWuid() = 0; // caller frees return string.
  580. // Exception handling
  581. virtual void addWuException(const char * text, unsigned code, unsigned severity, const char * source) = 0;
  582. virtual void addWuAssertFailure(unsigned code, const char * text, const char * filename, unsigned lineno, unsigned column, bool isAbort) = 0;
  583. // File resolution etc
  584. virtual char * getExpandLogicalName(const char * logicalName) = 0;
  585. virtual unsigned __int64 getFileOffset(const char *logicalPart) = 0;
  586. virtual char *getFilePart(const char *logicalPart, bool create=false) = 0; // caller frees return string.
  587. virtual IDistributedFileTransaction *querySuperFileTransaction() = 0;
  588. virtual IUserDescriptor *queryUserDescriptor() = 0;
  589. // Graphs, child queries etc
  590. virtual void executeGraph(const char * graphName, bool realThor, size32_t parentExtractSize, const void * parentExtract) = 0;
  591. virtual unsigned getGraphLoopCounter() const = 0;
  592. virtual IThorChildGraph * resolveChildQuery(__int64 activityId, IHThorArg * colocal) = 0;
  593. virtual IEclGraphResults * resolveLocalQuery(__int64 activityId) = 0;
  594. // Logging etc
  595. virtual unsigned logString(const char *text) const = 0;
  596. virtual const IContextLogger &queryContextLogger() const = 0;
  597. virtual IDebuggableContext *queryDebugContext() const = 0;
  598. // Memory management
  599. virtual IEngineRowAllocator * getRowAllocator(IOutputMetaData * meta, unsigned activityId) const = 0;
  600. virtual const char * cloneVString(const char *str) const = 0;
  601. virtual const char * cloneVString(size32_t len, const char *str) const = 0;
  602. // Called from generated code for FROMXML/TOXML
  603. virtual const void * fromXml(IEngineRowAllocator * _rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace) = 0;
  604. virtual void getRowXML(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags) = 0;
  605. // Miscellaneous
  606. virtual void getExternalResultRaw(unsigned & tlen, void * & tgt, const char * wuid, const char * stepname, unsigned sequence, IXmlToRowTransformer * xmlTransformer, ICsvToRowTransformer * csvTransformer) = 0; // shouldn't really be here, but it broke thor.
  607. virtual char * queryIndexMetaData(char const * lfn, char const * xpath) = 0;
  608. virtual IEngineContext *queryEngineContext() = 0;
  609. virtual char *getDaliServers() = 0;
  610. virtual IWorkUnit *updateWorkUnit() const = 0;
  611. virtual const void * fromJson(IEngineRowAllocator * _rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace) = 0;
  612. virtual void getRowJSON(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags) = 0;
  613. virtual unsigned getExternalResultHash(const char * wuid, const char * name, unsigned sequence) = 0;
  614. virtual ISectionTimer * registerTimer(unsigned activityId, const char * name) = 0;
  615. virtual IEngineRowAllocator * getRowAllocatorEx(IOutputMetaData * meta, unsigned activityId, unsigned flags) const = 0;
  616. };
  617. //Provided by engine=>can extend
  618. interface IFilePositionProvider : extends IInterface
  619. {
  620. virtual unsigned __int64 getFilePosition(const void * row) = 0;
  621. virtual unsigned __int64 getLocalFilePosition(const void * row) = 0;
  622. };
  623. typedef size32_t (*rowTransformFunction)(ARowBuilder & rowBuilder, const byte * src);
  624. interface IColumnProvider;
  625. //Provided by engine=>can extend
  626. interface IColumnProviderIterator : extends IInterface
  627. {
  628. virtual IColumnProvider * first() = 0;
  629. virtual IColumnProvider * next() = 0;
  630. };
  631. //Provided by engine=>can extend
  632. interface IColumnProvider : extends IInterface
  633. {
  634. virtual bool getBool(const char * path) = 0;
  635. virtual void getData(size32_t len, void * text, const char * path) = 0;
  636. virtual void getDataX(size32_t & len, void * & text, const char * path) = 0;
  637. virtual __int64 getInt(const char * path) = 0;
  638. virtual void getQString(size32_t len, char * text, const char * path) = 0;
  639. virtual void getString(size32_t len, char * text, const char * path) = 0;
  640. virtual void getStringX(size32_t & len, char * & text, const char * path) = 0;
  641. virtual void getUnicodeX(size32_t & len, UChar * & text, const char * path) = 0;
  642. virtual bool getIsSetAll(const char * path) = 0;
  643. virtual IColumnProviderIterator * getChildIterator(const char * path) = 0;
  644. virtual void getUtf8X(size32_t & len, char * & text, const char * path) = 0;
  645. //v2 interface - allowing default values. Different names are used to ensure the vmts stay in the correct order.
  646. virtual bool readBool(const char * path, bool _default) = 0;
  647. virtual void readData(size32_t len, void * text, const char * path, size32_t _lenDefault, const void * _default) = 0;
  648. virtual void readDataX(size32_t & len, void * & text, const char * path, size32_t _lenDefault, const void * _default) = 0;
  649. virtual __int64 readInt(const char * path, __int64 _default) = 0;
  650. virtual void readQString(size32_t len, char * text, const char * path, size32_t _lenDefault, const char * _default) = 0;
  651. virtual void readString(size32_t len, char * text, const char * path, size32_t _lenDefault, const char * _default) = 0;
  652. virtual void readStringX(size32_t & len, char * & text, const char * path, size32_t _lenDefault, const char * _default) = 0;
  653. virtual void readUnicodeX(size32_t & len, UChar * & text, const char * path, size32_t _lenDefault, const UChar * _default) = 0;
  654. virtual bool readIsSetAll(const char * path, bool _default) = 0;
  655. virtual void readUtf8X(size32_t & len, char * & text, const char * path, size32_t _lenDefault, const char * _default) = 0;
  656. //V3
  657. virtual void getDataRaw(size32_t len, void * text, const char * path) = 0;
  658. virtual void getDataRawX(size32_t & len, void * & text, const char * path) = 0;
  659. virtual void readDataRaw(size32_t len, void * text, const char * path, size32_t _lenDefault, const void * _default) = 0;
  660. virtual void readDataRawX(size32_t & len, void * & text, const char * path, size32_t _lenDefault, const void * _default) = 0;
  661. };
  662. //Member - can extend if new accessor function defined.
  663. // IHThorXmlReadArg
  664. interface IXmlToRowTransformer : public IInterface
  665. {
  666. virtual size32_t transform(ARowBuilder & rowBuilder, IColumnProvider * row, IThorDiskCallback * callback) = 0;
  667. virtual IOutputMetaData * queryRecordSize() = 0;
  668. };
  669. interface ICsvParameters;
  670. //Frozen - used in too many places.
  671. interface ICsvToRowTransformer : public IInterface
  672. {
  673. virtual unsigned getMaxColumns() = 0;
  674. virtual size32_t transform(ARowBuilder & rowBuilder, unsigned * srcLen, const char * * src, unsigned __int64 _fpos) = 0;
  675. virtual ICsvParameters * queryCsvParameters() = 0;
  676. virtual IOutputMetaData * queryRecordSize() = 0;
  677. };
  678. // Activity index: Class name = s/TAK(.*)/IHThor$1Arg/, with $1 using camel case
  679. enum ThorActivityKind
  680. {
  681. //This list cannot be reordered - unless all workunits are invalidated...
  682. TAKnone,
  683. TAKsubgraph,
  684. TAKdiskwrite,
  685. TAKsort,
  686. TAKdedup,
  687. TAKfilter,
  688. TAKsplit,
  689. TAKproject,
  690. TAKrollup,
  691. TAKiterate,
  692. TAKaggregate,
  693. TAKhashaggregate,
  694. TAKfirstn,
  695. TAKsample,
  696. TAKdegroup,
  697. TAKgroup,
  698. TAKworkunitwrite,
  699. TAKfunnel,
  700. TAKapply,
  701. TAKhashdistribute,
  702. TAKhashdedup,
  703. TAKnormalize,
  704. TAKremoteresult,
  705. TAKpull,
  706. TAKnormalizechild,
  707. TAKchilddataset,
  708. TAKselectn,
  709. TAKenth,
  710. TAKif,
  711. TAKnull,
  712. TAKdistribution,
  713. TAKcountproject,
  714. TAKchoosesets,
  715. TAKpiperead,
  716. TAKpipewrite,
  717. TAKcsvwrite,
  718. TAKpipethrough,
  719. TAKindexwrite,
  720. TAKchoosesetsenth,
  721. TAKchoosesetslast,
  722. TAKfetch,
  723. TAKworkunitread,
  724. TAKthroughaggregate,
  725. TAKspill,
  726. TAKcase,
  727. TAKlimit,
  728. TAKcsvfetch,
  729. TAKxmlwrite,
  730. TAKparse,
  731. TAKsideeffect,
  732. TAKtopn,
  733. TAKmerge,
  734. TAKxmlfetch,
  735. TAKxmlparse,
  736. TAKkeyeddistribute,
  737. TAKsoap_rowdataset, // a source activity
  738. TAKsoap_rowaction, // source and sink activity
  739. TAKsoap_datasetdataset, // a through activity
  740. TAKsoap_datasetaction, // sink activity
  741. TAKkeydiff,
  742. TAKkeypatch,
  743. TAKsequential,
  744. TAKparallel,
  745. TAKchilditerator,
  746. TAKdatasetresult,
  747. TAKrowresult,
  748. TAKchildif, // condition inside a child query
  749. TAKpartition,
  750. TAKlocalgraph,
  751. TAKifaction,
  752. TAKemptyaction,
  753. TAKdiskread, // records one at a time. (filter+project)
  754. TAKdisknormalize, // same, but normalize a child dataset (filter+project)
  755. TAKdiskaggregate, // non-grouped aggregate of dataset, or normalized dataset (filter/project input)
  756. TAKdiskcount, // non-grouped count of dataset (not child), (may filter input)
  757. TAKdiskgroupaggregate, // grouped aggregate on dataset (filter) (may work on project of input)
  758. TAKdiskexists, // non-grouped count of dataset (not child), (may filter input)
  759. TAKindexread,
  760. TAKindexnormalize,
  761. TAKindexaggregate,
  762. TAKindexcount,
  763. TAKindexgroupaggregate,
  764. TAKindexexists,
  765. TAKchildread,
  766. TAKchildnormalize,
  767. TAKchildaggregate,
  768. TAKchildcount,
  769. TAKchildgroupaggregate,
  770. TAKchildexists,
  771. TAKskiplimit,
  772. TAKchildthroughnormalize,
  773. TAKcsvread,
  774. TAKxmlread,
  775. TAKlocalresultread,
  776. TAKlocalresultwrite,
  777. TAKcombine,
  778. TAKregroup,
  779. TAKrollupgroup,
  780. TAKcombinegroup,
  781. TAKlocalresultspill,
  782. TAKsimpleaction,
  783. TAKloopcount,
  784. TAKlooprow,
  785. TAKloopdataset,
  786. TAKchildcase,
  787. TAKremotegraph,
  788. TAKlibrarycall,
  789. TAKlocalstreamread,
  790. TAKprocess,
  791. TAKgraphloop,
  792. TAKparallelgraphloop,
  793. TAKgraphloopresultread,
  794. TAKgraphloopresultwrite,
  795. TAKgrouped,
  796. TAKsorted,
  797. TAKdistributed,
  798. TAKnwayjoin,
  799. TAKnwaymerge,
  800. TAKnwaymergejoin,
  801. TAKnwayinput, // for variable selections from a static list
  802. TAKnwaygraphloopresultread,
  803. TAKnwayselect,
  804. TAKnonempty,
  805. TAKcreaterowlimit,
  806. TAKexistsaggregate,
  807. TAKcountaggregate,
  808. TAKprefetchproject,
  809. TAKprefetchcountproject,
  810. TAKfiltergroup,
  811. TAKmemoryspillread,
  812. TAKmemoryspillwrite,
  813. TAKmemoryspillsplit,
  814. TAKsection,
  815. TAKlinkedrawiterator,
  816. TAKnormalizelinkedchild,
  817. TAKfilterproject,
  818. TAKcatch,
  819. TAKskipcatch,
  820. TAKcreaterowcatch,
  821. TAKsectioninput,
  822. TAKcaseaction,
  823. TAKwhen_dataset,
  824. TAKwhen_action,
  825. TAKsubsort,
  826. TAKindexgroupexists,
  827. TAKindexgroupcount,
  828. TAKhashdistributemerge,
  829. TAKhttp_rowdataset, // a source activity
  830. TAKinlinetable,
  831. TAKstreamediterator,
  832. TAKexternalsource,
  833. TAKexternalsink,
  834. TAKexternalprocess,
  835. TAKdictionaryworkunitwrite,
  836. TAKdictionaryresultwrite,
  837. //Joins
  838. TAKjoin,
  839. TAKhashjoin,
  840. TAKlookupjoin,
  841. TAKselfjoin,
  842. TAKkeyedjoin,
  843. TAKalljoin,
  844. TAKsmartjoin,
  845. TAKunknownjoin1, // place holders to make it easy to insert new join kinds
  846. TAKunknownjoin2,
  847. TAKunknownjoin3,
  848. TAKjoinlight, // lightweight, local, presorted join.
  849. TAKselfjoinlight,
  850. TAKlastjoin,
  851. //Denormalize
  852. TAKdenormalize,
  853. TAKhashdenormalize,
  854. TAKlookupdenormalize,
  855. TAKselfdenormalize,
  856. TAKkeyeddenormalize,
  857. TAKalldenormalize,
  858. TAKsmartdenormalize,
  859. TAKunknowndenormalize1,
  860. TAKunknowndenormalize2,
  861. TAKunknowndenormalize3,
  862. TAKlastdenormalize,
  863. //DenormalizeGroup
  864. TAKdenormalizegroup,
  865. TAKhashdenormalizegroup,
  866. TAKlookupdenormalizegroup,
  867. TAKselfdenormalizegroup,
  868. TAKkeyeddenormalizegroup,
  869. TAKalldenormalizegroup,
  870. TAKsmartdenormalizegroup,
  871. TAKunknowndenormalizegroup1,
  872. TAKunknowndenormalizegroup2,
  873. TAKunknowndenormalizegroup3,
  874. TAKlastdenormalizegroup,
  875. TAKjsonwrite,
  876. TAKjsonread,
  877. TAKtrace,
  878. TAKquantile,
  879. TAKjsonfetch,
  880. TAKspillread,
  881. TAKspillwrite,
  882. TAKlast
  883. };
  884. inline bool isSimpleJoin(ThorActivityKind kind) { return (kind >= TAKjoin) && (kind <= TAKlastjoin); }
  885. inline bool isDenormalizeJoin(ThorActivityKind kind) { return (kind >= TAKdenormalize) && (kind <= TAKlastdenormalize); }
  886. inline bool isDenormalizeGroupJoin(ThorActivityKind kind) { return (kind >= TAKdenormalizegroup) && (kind <= TAKlastdenormalizegroup); }
  887. struct ISortKeySerializer
  888. {
  889. virtual size32_t keyToRecord(ARowBuilder & rowBuilder, const void * _key, size32_t & recordSize) = 0; // both return size of key!
  890. virtual size32_t recordToKey(ARowBuilder & rowBuilder, const void * _record, size32_t & recordSize) = 0; // record size in 3rd parameter
  891. virtual IOutputMetaData * queryRecordSize() = 0;
  892. virtual ICompare * queryCompareKey() = 0;
  893. virtual ICompare * queryCompareKeyRow() = 0;
  894. };
  895. struct CFieldOffsetSize
  896. {
  897. size32_t offset;
  898. size32_t size;
  899. };
  900. //Derived=>Frozen unless major version upgrade.
  901. interface IHThorArg : public IInterface
  902. {
  903. virtual IOutputMetaData * queryOutputMeta() = 0;
  904. virtual void onCreate(ICodeContext * ctx, IHThorArg * colocalParent, MemoryBuffer * serializedCreate) = 0;
  905. virtual void serializeCreateContext(MemoryBuffer & out) = 0;
  906. virtual void onStart(const byte * parentExtract, MemoryBuffer * serializedStart) = 0;
  907. virtual void serializeStartContext(MemoryBuffer & out) = 0;
  908. };
  909. typedef IHThorArg * (*EclHelperFactory)();
  910. //flags for thor disk access
  911. enum
  912. {
  913. //General disk access flags
  914. TDXtemporary = 0x0001,
  915. TDXgrouped = 0x0002,
  916. TDXcompress = 0x0004,
  917. TDXvarfilename = 0x0008, // filename is dependant on the context.
  918. TDXupdateaccessed = 0x0010,
  919. TDXdynamicfilename = 0x0020,
  920. TDXjobtemp = 0x0040, // stay around while a wu is being executed.
  921. //disk read flags
  922. TDRoptional = 0x00000100,
  923. TDRunsorted = 0x00000200,
  924. TDRorderedmerge = 0x00000400, // for aggregate variants only
  925. TDRusexmlcontents = 0x00000800, // xml reading. Are the contents <> of an attribute used?
  926. TDRpreload = 0x00001000, // also present in the graph.
  927. TDRkeyed = 0x00002000, // is anything keyed?
  928. TDRxmlnoroot = 0x00004000, // xml without a surrounding root tag.
  929. TDRcountkeyedlimit = 0x00008000,
  930. TDRkeyedlimitskips = 0x00010000,
  931. TDRlimitskips = 0x00020000,
  932. TDRnocrccheck = 0x00040000,
  933. TDRaggregateexists = 0x00080000, // only aggregate is exists()
  934. TDRgroupmonitors = 0x00100000, // are segement monitors created for all group by conditions.
  935. TDRlimitcreates = 0x00200000,
  936. TDRkeyedlimitcreates= 0x00400000,
  937. TDRunfilteredcount = 0x00800000, // count/aggregegate doesn't have an additional filter
  938. TDRfilenamecallback = 0x01000000,
  939. //disk write flags
  940. TDWextend = 0x0100,
  941. TDWoverwrite = 0x0200,
  942. TDWpersist = 0x0400,
  943. TDWnoreplicate = 0x0800,
  944. TDWbackup = 0x1000,
  945. TDWowned = 0x2000, // a file which should stay around even after the wu completes, but be deleted when wu is.
  946. TDWresult = 0x4000, // a result sent to disk
  947. TDWupdate = 0x10000, // only rebuild if inputs have changed.
  948. TDWnewcompress = 0x20000, // new compressed format - only specified on output
  949. TDWnooverwrite = 0x40000,
  950. TDWupdatecrc = 0x80000, // has format crc
  951. TDWexpires = 0x100000,
  952. };
  953. //flags for thor index read
  954. enum
  955. {
  956. TIRsorted = 0x00000001,
  957. TIRnofilter = 0x00000002,
  958. TIRpreload = 0x00000004,
  959. TIRoptional = 0x00000008,
  960. TIRcountkeyedlimit = 0x00000010,
  961. TIRkeyedlimitskips = 0x00000020,
  962. TIRlimitskips = 0x00000040,
  963. TIRstepleadequality = 0x00000080, // all filters before the first stepping field are equalities
  964. TIRaggregateexists = 0x00000100, // only aggregate is exists()
  965. TIRgroupmonitors = 0x00000200, // are segement monitors created for all group by conditions.
  966. TIRlimitcreates = 0x00000400,
  967. TIRkeyedlimitcreates= 0x00000800,
  968. TIRvarfilename = 0x00001000, // filename is dependant on the context.
  969. TIRdynamicfilename = 0x00002000,
  970. TIRunfilteredtransform = 0x00004000,
  971. TIRorderedmerge = 0x00008000,
  972. TIRunordered = 0x00010000,
  973. };
  974. //flags for thor index write
  975. enum
  976. {
  977. TIWoverwrite = 0x0001,
  978. TIWbackup = 0x0002,
  979. TIWunused = 0x0004, // no longer used
  980. TIWvarfilename = 0x0008, // filename is dependant on the context.
  981. TIWsmall = 0x0010,
  982. TIWupdate = 0x0020,
  983. TIWlocal = 0x0040, // i.e., no tlk
  984. TIWrowcompress = 0x0080,
  985. TIWnolzwcompress = 0x0100,
  986. TIWnooverwrite = 0x0200,
  987. TIWupdatecrc = 0x0400,
  988. TIWhaswidth = 0x0800,
  989. TIWexpires = 0x1000,
  990. TIWmaxlength = 0x2000, // explicit maxlength
  991. };
  992. //flags for thor dataset/temp tables
  993. enum
  994. {
  995. TTFnoconstant = 0x0001, // default flags is zero
  996. TTFdistributed = 0x0002,
  997. TTFfiltered = 0x0004,
  998. };
  999. struct IBloomBuilderInfo
  1000. {
  1001. virtual bool getBloomEnabled() const = 0;
  1002. virtual __uint64 getBloomFields() const = 0;
  1003. virtual unsigned getBloomLimit() const = 0;
  1004. virtual double getBloomProbability() const = 0;
  1005. };
  1006. struct IHThorIndexWriteArg : public IHThorArg
  1007. {
  1008. virtual const char * getFileName() = 0;
  1009. virtual int getSequence() = 0;
  1010. virtual IOutputMetaData * queryDiskRecordSize() = 0;
  1011. virtual const char * queryRecordECL() = 0;
  1012. virtual unsigned getFlags() = 0;
  1013. virtual size32_t transform(ARowBuilder & rowBuilder, const void * src, IBlobCreator * blobs, unsigned __int64 & filepos) = 0; //NB: returns size
  1014. virtual const char * getDistributeIndexName() = 0;
  1015. virtual unsigned getKeyedSize() = 0;
  1016. virtual unsigned getExpiryDays() = 0;
  1017. virtual void getUpdateCRCs(unsigned & eclCRC, unsigned __int64 & totalCRC) = 0;
  1018. virtual unsigned getFormatCrc() = 0;
  1019. virtual const char * getCluster(unsigned idx) = 0;
  1020. virtual bool getIndexLayout(size32_t & _retLen, void * & _retData) = 0;
  1021. virtual bool getIndexMeta(size32_t & lenName, char * & name, size32_t & lenValue, char * & value, unsigned idx) = 0;
  1022. virtual unsigned getWidth() = 0; // only guaranteed present if TIWhaswidth defined
  1023. virtual ICompare * queryCompare() = 0; // only guaranteed present if TIWhaswidth defined
  1024. virtual unsigned getMaxKeySize() = 0;
  1025. virtual const IBloomBuilderInfo * const *queryBloomInfo() const = 0;
  1026. virtual __uint64 getPartitionFieldMask() const = 0;
  1027. };
  1028. struct IHThorFirstNArg : public IHThorArg
  1029. {
  1030. virtual __int64 getLimit() = 0;
  1031. virtual __int64 numToSkip() { return 0; }
  1032. virtual bool preserveGrouping() = 0;
  1033. };
  1034. struct IHThorChooseSetsArg : public IHThorArg
  1035. {
  1036. virtual unsigned getNumSets() = 0;
  1037. virtual unsigned getRecordAction(const void * _self) = 0;
  1038. virtual bool setCounts(unsigned * data) = 0;
  1039. };
  1040. struct IHThorChooseSetsExArg : public IHThorArg
  1041. {
  1042. virtual unsigned getNumSets() = 0;
  1043. virtual unsigned getCategory(const void * _self) = 0;
  1044. virtual void getLimits(__int64 * counts) = 0;
  1045. };
  1046. struct IHThorDiskWriteArg : public IHThorArg
  1047. {
  1048. virtual const char * getFileName() = 0;
  1049. virtual int getSequence() = 0;
  1050. virtual IOutputMetaData * queryDiskRecordSize() = 0;
  1051. virtual const char * queryRecordECL() = 0;
  1052. virtual unsigned getFlags() = 0;
  1053. virtual unsigned getTempUsageCount() = 0;
  1054. virtual unsigned getExpiryDays() = 0;
  1055. virtual void getUpdateCRCs(unsigned & eclCRC, unsigned __int64 & totalCRC) = 0;
  1056. virtual void getEncryptKey(size32_t & keyLen, void * & key) = 0;
  1057. virtual unsigned getFormatCrc() = 0;
  1058. virtual const char * getCluster(unsigned idx) = 0;
  1059. };
  1060. struct IHThorFilterArg : public IHThorArg
  1061. {
  1062. virtual bool isValid(const void * _left) = 0;
  1063. virtual bool canMatchAny() { return true; }
  1064. };
  1065. struct IHThorFilterGroupArg : public IHThorArg
  1066. {
  1067. virtual bool isValid(unsigned _num, const void * * _rows) = 0;
  1068. virtual bool canMatchAny() { return true; }
  1069. };
  1070. struct IHThorGroupArg : public IHThorArg
  1071. {
  1072. virtual bool isSameGroup(const void * _left, const void * _right) = 0;
  1073. };
  1074. struct IHThorDegroupArg : public IHThorArg
  1075. {
  1076. };
  1077. typedef IHThorGroupArg IHThorGroupedArg;
  1078. //Typedefed=>Be careful about extending
  1079. struct IHThorIterateArg : public IHThorArg
  1080. {
  1081. virtual bool canFilter() = 0;
  1082. virtual size32_t createDefault(ARowBuilder & rowBuilder) = 0;
  1083. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, const void * _right, unsigned __int64 counter) = 0;
  1084. };
  1085. typedef IHThorIterateArg IHThorGroupIterateArg;
  1086. struct IHThorProcessArg : public IHThorArg
  1087. {
  1088. virtual bool canFilter() = 0;
  1089. virtual IOutputMetaData * queryRightRecordSize() = 0;
  1090. virtual size32_t createInitialRight(ARowBuilder & rowBuilder) = 0;
  1091. virtual size32_t transform(ARowBuilder & rowBuilder, ARowBuilder & rightBuilder, const void * _left, const void * _right, unsigned __int64 counter) = 0;
  1092. };
  1093. struct IHThorProjectArg : public IHThorArg
  1094. {
  1095. virtual bool canFilter() { return false; }
  1096. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left) = 0;
  1097. };
  1098. struct IHThorCountProjectArg : public IHThorArg
  1099. {
  1100. virtual bool canFilter() { return false; }
  1101. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, unsigned __int64 _counter) = 0;
  1102. };
  1103. struct IHThorNormalizeArg : public IHThorArg
  1104. {
  1105. virtual unsigned numExpandedRows(const void * _self) = 0;
  1106. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, unsigned whichCount) = 0;
  1107. };
  1108. struct IHThorSelectNArg : public IHThorArg
  1109. {
  1110. virtual unsigned __int64 getRowToSelect() = 0;
  1111. virtual size32_t createDefault(ARowBuilder & rowBuilder) = 0;
  1112. };
  1113. enum
  1114. {
  1115. TQFfirst = 0x0001, // default flags is zero
  1116. TQFlast = 0x0002,
  1117. TQFsorted = 0x0004,
  1118. TQFlocalsorted = 0x0008,
  1119. TQFhasscore = 0x0010,
  1120. TQFhasrange = 0x0020,
  1121. TQFhasskew = 0x0040,
  1122. TQFdedup = 0x0080,
  1123. TQFunstable = 0x0100,
  1124. TQFvariabledivisions= 0x0200, // num divisions is not a constant
  1125. TQFneedtransform = 0x0400, // if not set the records are returned as-is
  1126. };
  1127. struct IHThorQuantileArg : public IHThorArg
  1128. {
  1129. virtual unsigned getFlags() = 0;
  1130. virtual unsigned __int64 getNumDivisions() = 0;
  1131. virtual double getSkew() = 0;
  1132. virtual ICompare * queryCompare() = 0;
  1133. virtual size32_t createDefault(ARowBuilder & rowBuilder) = 0;
  1134. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, unsigned __int64 _counter) = 0;
  1135. virtual unsigned __int64 getScore(const void * _left) = 0;
  1136. virtual void getRange(bool & isAll, size32_t & tlen, void * & tgt) = 0;
  1137. };
  1138. struct IHThorCombineArg : public IHThorArg
  1139. {
  1140. virtual bool canFilter() { return false; }
  1141. virtual size32_t transform(ARowBuilder & rowBuilder, unsigned _num, const void * * _rows) = 0;
  1142. };
  1143. struct IHThorCombineGroupArg : public IHThorArg
  1144. {
  1145. virtual bool canFilter() { return false; }
  1146. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, unsigned _num, const void * * _rows) = 0;
  1147. };
  1148. struct IHThorRollupGroupArg : public IHThorArg
  1149. {
  1150. virtual bool canFilter() { return false; }
  1151. virtual size32_t transform(ARowBuilder & rowBuilder, unsigned _num, const void * * _rows) = 0;
  1152. };
  1153. typedef IHThorArg IHThorRegroupArg;
  1154. //Following is compatible with all interfaces
  1155. typedef IHThorArg IHThorNullArg;
  1156. struct IHThorActionArg : public IHThorArg
  1157. {
  1158. virtual void action() {};
  1159. };
  1160. typedef IHThorActionArg IHThorSideEffectArg;
  1161. const int WhenDefaultId = 0;
  1162. const int WhenSuccessId = -1;
  1163. const int WhenFailureId = -2;
  1164. const int WhenParallelId = -3;
  1165. const int WhenBeforeId = -4;
  1166. typedef IHThorNullArg IHThorWhenActionArg;
  1167. struct IHThorLimitArg : public IHThorArg
  1168. {
  1169. virtual unsigned __int64 getRowLimit() = 0;
  1170. virtual void onLimitExceeded() = 0;
  1171. virtual size32_t transformOnLimitExceeded(ARowBuilder & rowBuilder) = 0;
  1172. };
  1173. struct IHThorCatchArg : public IHThorArg
  1174. {
  1175. virtual unsigned getFlags() = 0;
  1176. virtual bool isHandler(IException * e) = 0;
  1177. virtual void onExceptionCaught() = 0;
  1178. virtual size32_t transformOnExceptionCaught(ARowBuilder & rowBuilder, IException * e) = 0;
  1179. };
  1180. struct IHThorSplitArg : public IHThorArg
  1181. {
  1182. virtual unsigned numBranches() = 0;
  1183. virtual bool isBalanced() { return false; }
  1184. };
  1185. struct IHThorSpillExtra : public IInterface
  1186. {
  1187. //fill in functions here if we need any more...
  1188. };
  1189. struct IHThorSpillArg : public IHThorDiskWriteArg
  1190. {
  1191. };
  1192. //Member=>New accessor function if derived.
  1193. interface INormalizeChildIterator : public IInterface
  1194. {
  1195. virtual byte * first(const void * parentRecord) = 0;
  1196. virtual byte * next() = 0;
  1197. };
  1198. struct IHThorNormalizeChildArg : public IHThorArg
  1199. {
  1200. virtual INormalizeChildIterator * queryIterator() = 0;
  1201. virtual IOutputMetaData * queryChildRecordSize() = 0;
  1202. virtual size32_t transform(ARowBuilder & rowBuilder, const void * left, const void * right, unsigned counter) = 0;
  1203. };
  1204. struct IHThorNormalizeLinkedChildArg : public IHThorArg
  1205. {
  1206. virtual byte * first(const void * parentRecord) = 0;
  1207. virtual byte * next() = 0;
  1208. };
  1209. struct IHThorChildIteratorArg : public IHThorArg
  1210. {
  1211. virtual bool first() = 0;
  1212. virtual bool next() = 0;
  1213. virtual size32_t transform(ARowBuilder & rowBuilder) = 0;
  1214. };
  1215. struct IHThorRawIteratorArg : public IHThorArg
  1216. {
  1217. virtual void queryDataset(size32_t & len, const void * & data) = 0;
  1218. };
  1219. struct IHThorLinkedRawIteratorArg : public IHThorArg
  1220. {
  1221. virtual const byte * next() = 0;
  1222. };
  1223. enum {
  1224. RFrolledismatchleft = 0x00001, // Is the value of left passed to matches() the result of the rollup?
  1225. };
  1226. struct IHThorRollupArg : public IHThorArg
  1227. {
  1228. virtual unsigned getFlags() = 0;
  1229. virtual bool matches(const void * _left, const void * _right) = 0;
  1230. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, const void * _right) = 0;
  1231. };
  1232. enum
  1233. {
  1234. HDFwholerecord = 0x0001,
  1235. HDFcompareall = 0x0002,
  1236. HDFkeepleft = 0x0004,
  1237. HDFkeepbest = 0x0008
  1238. };
  1239. struct IHThorDedupArg : public IHThorArg
  1240. {
  1241. inline bool compareAll() { return (getFlags() & HDFcompareall) != 0; }
  1242. inline bool keepLeft() { return (getFlags() & HDFkeepleft) != 0; }
  1243. inline bool keepBest() { return (getFlags() & HDFkeepbest) != 0; }
  1244. virtual bool matches(const void * _left, const void * _right) = 0;
  1245. virtual unsigned numToKeep() = 0;
  1246. virtual ICompare * queryComparePrimary() = 0; // used to break global dedup into chunks
  1247. virtual unsigned getFlags() = 0;
  1248. virtual ICompare * queryCompareBest() = 0;
  1249. };
  1250. enum
  1251. {
  1252. TAForderedmerge = 0x00000001,
  1253. };
  1254. //Group Aggregate, Normalize Aggregate
  1255. struct IHThorRowAggregator
  1256. {
  1257. virtual size32_t clearAggregate(ARowBuilder & rowBuilder) = 0; // has to be called because of conditional counts/sums etc.
  1258. virtual size32_t processFirst(ARowBuilder & rowBuilder, const void * src) = 0;
  1259. virtual size32_t processNext(ARowBuilder & rowBuilder, const void * src) = 0;
  1260. virtual size32_t mergeAggregate(ARowBuilder & rowBuilder, const void * src) = 0; //only call if transform called at least once on src.
  1261. };
  1262. struct IHThorAggregateArg : public IHThorArg, public IHThorRowAggregator
  1263. {
  1264. virtual unsigned getAggregateFlags() = 0;
  1265. };
  1266. struct IHThorThroughAggregateExtra : public IInterface
  1267. {
  1268. virtual void sendResult(const void * self) = 0;
  1269. virtual IOutputMetaData * queryAggregateRecordSize() = 0;
  1270. };
  1271. struct IHThorThroughAggregateArg : public IHThorAggregateArg, public IHThorThroughAggregateExtra
  1272. {
  1273. COMMON_NEWTHOR_FUNCTIONS
  1274. };
  1275. interface IDistributionTable;
  1276. struct IHThorDistributionArg : public IHThorArg
  1277. {
  1278. virtual void clearAggregate(IDistributionTable * * target) = 0;
  1279. virtual void destruct(IDistributionTable * * target) = 0;
  1280. virtual void process(IDistributionTable * * target, const void * src) = 0;
  1281. virtual void serialize(IDistributionTable * * self, MemoryBuffer & out) = 0;
  1282. virtual void merge(IDistributionTable * * self, MemoryBuffer & in) = 0;
  1283. virtual IOutputMetaData * queryInternalRecordSize() = 0;
  1284. virtual void gatherResult(IDistributionTable * * self, StringBuffer & temp) = 0;
  1285. virtual void sendResult(size32_t length, const char * text) = 0;
  1286. };
  1287. struct IHThorGroupAggregateArg : public IHThorAggregateArg
  1288. {
  1289. //use extra base class if inserting functions here
  1290. };
  1291. struct IHThorHashAggregateExtra : public IInterface
  1292. {
  1293. virtual IHash * queryHash() = 0;
  1294. virtual ICompare * queryCompareElements() = 0; // expect to docompare(const void * element1, const void * element2);
  1295. virtual ICompare * queryCompareRowElement() = 0; // expect to docompare(const void * row, const void * element);
  1296. virtual IHash * queryHashElement() = 0;
  1297. };
  1298. struct IHThorHashAggregateArg : public IHThorAggregateArg, public IHThorHashAggregateExtra
  1299. {
  1300. COMMON_NEWTHOR_FUNCTIONS
  1301. };
  1302. struct IHThorInlineTableArg : public IHThorArg
  1303. {
  1304. virtual size32_t getRow(ARowBuilder & rowBuilder, __uint64 row) = 0;
  1305. virtual __uint64 numRows() = 0;
  1306. virtual unsigned getFlags() = 0;
  1307. };
  1308. struct IHThorSampleArg : public IHThorArg
  1309. {
  1310. virtual unsigned getProportion() = 0;
  1311. virtual unsigned getSampleNumber() = 0;
  1312. };
  1313. struct IHThorEnthArg : public IHThorArg
  1314. {
  1315. virtual unsigned __int64 getProportionNumerator() = 0;
  1316. virtual unsigned __int64 getProportionDenominator() = 0;
  1317. virtual unsigned getSampleNumber() = 0;
  1318. };
  1319. struct IHThorFunnelArg : public IHThorArg
  1320. {
  1321. virtual bool isOrdered() = 0;
  1322. virtual bool pullSequentially() = 0;
  1323. };
  1324. struct IHThorNonEmptyArg : public IHThorArg
  1325. {
  1326. };
  1327. struct IHThorMergeArg : public IHThorArg
  1328. {
  1329. virtual ICompare * queryCompare() = 0;
  1330. virtual ISortKeySerializer * querySerialize() = 0;
  1331. virtual ICompare * queryCompareKey() = 0;
  1332. virtual ICompare * queryCompareRowKey() = 0;
  1333. virtual bool dedup() = 0;
  1334. };
  1335. struct IHThorRemoteResultArg : public IHThorArg
  1336. {
  1337. virtual void sendResult(const void * self) = 0;
  1338. virtual int getSequence() = 0;
  1339. };
  1340. struct IHThorApplyArg : public IHThorArg
  1341. {
  1342. virtual void apply(const void * src) = 0;
  1343. virtual int getSequence() = 0;
  1344. virtual void start() = 0;
  1345. virtual void end() = 0;
  1346. };
  1347. enum
  1348. {
  1349. TAFconstant = 0x0001,
  1350. TAFstable = 0x0002,
  1351. TAFunstable = 0x0004,
  1352. TAFspill = 0x0008,
  1353. TAFparallel = 0x0010,
  1354. };
  1355. struct IHThorSortArg : public IHThorArg
  1356. {
  1357. virtual const char * getSortedFilename()=0;
  1358. virtual IOutputMetaData * querySortedRecordSize()=0;
  1359. virtual ICompare * queryCompare()=0;
  1360. virtual ICompare * queryCompareLeftRight()=0;
  1361. virtual ISortKeySerializer * querySerialize() = 0;
  1362. virtual unsigned __int64 getThreshold() = 0; // limit to size of dataset on a node. (0=default)
  1363. virtual double getSkew() = 0;
  1364. virtual bool hasManyRecords() = 0;
  1365. virtual double getTargetSkew() = 0;
  1366. virtual ICompare * queryCompareSerializedRow()=0; // null if row already serialized, or if compare not available
  1367. virtual unsigned getAlgorithmFlags() = 0;
  1368. virtual const char * getAlgorithm() = 0;
  1369. };
  1370. typedef IHThorSortArg IHThorSortedArg;
  1371. struct IHThorTopNExtra : public IInterface
  1372. {
  1373. virtual __int64 getLimit() = 0;
  1374. virtual bool hasBest() = 0;
  1375. virtual int compareBest(const void * _left) = 0;
  1376. };
  1377. struct IHThorTopNArg : public IHThorSortArg, public IHThorTopNExtra
  1378. {
  1379. COMMON_NEWTHOR_FUNCTIONS
  1380. };
  1381. struct IHThorSubSortExtra : public IInterface
  1382. {
  1383. virtual bool isSameGroup(const void * _left, const void * _right) = 0;
  1384. };
  1385. struct IHThorSubSortArg : public IHThorSortArg, public IHThorSubSortExtra
  1386. {
  1387. COMMON_NEWTHOR_FUNCTIONS
  1388. };
  1389. // JoinFlags
  1390. enum {
  1391. JFleftouter = 0x00000001,
  1392. JFrightouter = 0x00000002,
  1393. JFexclude = 0x00000004,
  1394. JFleftonly =JFleftouter|JFexclude,
  1395. JFrightonly =JFrightouter|JFexclude,
  1396. JFtypemask =JFleftouter|JFrightouter|JFexclude,
  1397. JFfirst = 0x00000008,
  1398. JFfirstleft = 0x00000010,
  1399. JFfirstright = 0x00000020,
  1400. JFpartitionright = 0x00000040,
  1401. JFtransformMaySkip = 0x00000080,
  1402. JFfetchMayFilter = 0x00000100,
  1403. JFmatchAbortLimitSkips = 0x00000200,
  1404. JFonfail = 0x00000400,
  1405. JFindexoptional = 0x00000800,
  1406. JFslidingmatch = 0x00001000,
  1407. JFextractjoinfields = 0x00002000,
  1408. JFmatchrequired = 0x00004000,
  1409. JFmanylookup = 0x00008000,
  1410. JFparallel = 0x00010000,
  1411. JFsequential = 0x00020000,
  1412. JFcountmatchabortlimit = 0x00080000,
  1413. JFreorderable = 0x00100000,
  1414. JFtransformmatchesleft = 0x00200000,
  1415. JFvarindexfilename = 0x00400000,
  1416. JFdynamicindexfilename = 0x00800000,
  1417. JFlimitedprefixjoin = 0x01000000,
  1418. JFindexfromactivity = 0x02000000,
  1419. JFleftSortedLocally = 0x04000000,
  1420. JFrightSortedLocally = 0x08000000,
  1421. JFsmart = 0x10000000,
  1422. JFunstable = 0x20000000, // can sorts be unstable?
  1423. JFnevermatchself = 0x40000000, // for a self join can a record match itself
  1424. };
  1425. // FetchFlags
  1426. enum {
  1427. FFdatafileoptional = 0x0001,
  1428. FFvarfilename = 0x0002,
  1429. FFdynamicfilename = 0x0004,
  1430. };
  1431. // JoinTransformFlags
  1432. enum {
  1433. JTFmatchedleft = 0x0001,
  1434. JTFmatchedright = 0x0002
  1435. };
  1436. struct IHThorAnyJoinBaseArg : public IHThorArg
  1437. {
  1438. virtual bool match(const void * _left, const void * _right) = 0;
  1439. virtual size32_t createDefaultLeft(ARowBuilder & rowBuilder) = 0;
  1440. virtual size32_t createDefaultRight(ARowBuilder & rowBuilder) = 0;
  1441. virtual unsigned getJoinFlags() = 0;
  1442. virtual unsigned getKeepLimit() = 0;
  1443. virtual unsigned getMatchAbortLimit() = 0;
  1444. virtual void onMatchAbortLimitExceeded() = 0;
  1445. //Join:
  1446. //Denormalize
  1447. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, const void * _right, unsigned _count, unsigned _flags) = 0;
  1448. //Denormalize group
  1449. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, const void * _right, unsigned _numRows, const void * * _rows, unsigned _flags) = 0;
  1450. inline bool isLeftAlreadyLocallySorted() { return (getJoinFlags() & JFleftSortedLocally) != 0; }
  1451. inline bool isRightAlreadyLocallySorted() { return (getJoinFlags() & JFrightSortedLocally) != 0; }
  1452. };
  1453. struct IHThorJoinBaseArg : public IHThorAnyJoinBaseArg
  1454. {
  1455. virtual ICompare * queryCompareRight()=0;
  1456. virtual ICompare * queryCompareLeft()=0;
  1457. virtual bool isLeftAlreadySorted() = 0;
  1458. virtual bool isRightAlreadySorted() = 0;
  1459. virtual ICompare * queryCompareLeftRight()=0;
  1460. virtual ISortKeySerializer * querySerializeLeft() = 0;
  1461. virtual ISortKeySerializer * querySerializeRight() = 0;
  1462. virtual unsigned __int64 getThreshold() = 0; // limit to size of dataset on a node. (0=default)
  1463. virtual double getSkew() = 0;
  1464. virtual unsigned getJoinLimit() = 0; // if a key joins more than this limit no records are output (0 = no limit)
  1465. virtual double getTargetSkew() = 0;
  1466. virtual ICompare * queryCompareLeftRightLower() = 0;
  1467. virtual ICompare * queryCompareLeftRightUpper() = 0;
  1468. virtual ICompare * queryPrefixCompare() = 0;
  1469. virtual size32_t onFailTransform(ARowBuilder & rowBuilder, const void * _left, const void * _right, IException * e, unsigned flags) = 0;
  1470. virtual ICompare * queryCompareLeftKeyRightRow()=0; // compare serialized left key with right row
  1471. virtual ICompare * queryCompareRightKeyLeftRow()=0; // as above if partition right selected
  1472. };
  1473. struct IHThorFetchContext
  1474. {
  1475. virtual unsigned __int64 extractPosition(const void * _right) = 0; // Gets file position value from rhs row
  1476. virtual const char * getFileName() = 0; // Returns filename of raw file fpos'es refer into
  1477. virtual IOutputMetaData * queryDiskRecordSize() = 0; // Expected layout
  1478. virtual IOutputMetaData * queryProjectedDiskRecordSize() = 0; // Projected layout
  1479. virtual unsigned getFetchFlags() { return 0; }
  1480. virtual unsigned getDiskFormatCrc() { return 0; }
  1481. virtual void getFileEncryptKey(size32_t & keyLen, void * & key) { keyLen = 0; key = 0; }
  1482. };
  1483. struct IHThorKeyedJoinBaseArg : public IHThorArg
  1484. {
  1485. // For the data going to the indexRead remote activity:
  1486. virtual size32_t extractIndexReadFields(ARowBuilder & rowBuilder, const void * _input) = 0;
  1487. virtual IOutputMetaData * queryIndexReadInputRecordSize() = 0;
  1488. virtual bool leftCanMatch(const void * inputRow) { return true; }
  1489. // Inside the indexRead remote activity:
  1490. virtual const char * getIndexFileName() = 0;
  1491. virtual IOutputMetaData * queryIndexRecordSize() = 0; // Expected layout
  1492. virtual IOutputMetaData * queryProjectedIndexRecordSize() = 0; // Projected layout
  1493. virtual void createSegmentMonitors(IIndexReadContext *ctx, const void *lhs) = 0;
  1494. virtual bool indexReadMatch(const void * indexRow, const void * inputRow, IBlobProvider * blobs) = 0;
  1495. virtual unsigned getJoinLimit() = 0; // if a key joins more than this limit no records are output (0 = no limit)
  1496. virtual unsigned getKeepLimit() = 0; // limit to number of matches that are kept (0 = no limit)
  1497. virtual unsigned getIndexFormatCrc() = 0;
  1498. virtual bool getIndexLayout(size32_t & _retLen, void * & _retData) = 0;
  1499. // For the data going to the fetch remote activity:
  1500. virtual size32_t extractFetchFields(ARowBuilder & rowBuilder, const void * _input) = 0;
  1501. virtual IOutputMetaData * queryFetchInputRecordSize() = 0;
  1502. // Inside the fetch remote activity
  1503. virtual bool fetchMatch(const void * diskRow, const void * inputRow) = 0;
  1504. virtual size32_t extractJoinFields(ARowBuilder & rowBuilder, const void * diskRowOr, IBlobProvider * blobs) = 0;
  1505. virtual IOutputMetaData * queryJoinFieldsRecordSize() = 0;
  1506. // Back at the server
  1507. virtual size32_t createDefaultRight(ARowBuilder & rowBuilder) = 0;
  1508. virtual unsigned getJoinFlags() = 0;
  1509. virtual bool diskAccessRequired() = 0; // if false, all transform values can be fulfilled from the key, which is passed as right.
  1510. virtual unsigned __int64 getRowLimit() { return (unsigned __int64) -1; }
  1511. virtual void onLimitExceeded() { }
  1512. virtual unsigned __int64 getSkipLimit() { return 0; }
  1513. virtual unsigned getMatchAbortLimit() = 0;
  1514. virtual void onMatchAbortLimitExceeded() { }
  1515. //keyedFpos is always 0
  1516. virtual size32_t onFailTransform(ARowBuilder & rowBuilder, const void * _dummyRight, const void * _origRow, unsigned __int64 keyedFpos, IException * e) { return 0; }
  1517. //Join:
  1518. //Denormalize:
  1519. //The _filepos field is used for full keyed join to pass in the fileposition. It should really use the disk IThorDiskCallback interface.
  1520. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _joinFields, const void * _origRow, unsigned __int64 keyedFpos, unsigned counter) { return 0; }
  1521. //Denormalize group:
  1522. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _joinFields, const void * _origRow, unsigned _numRows, const void * * _rows) { return 0; }
  1523. };
  1524. struct IHThorKeyedJoinArg : public IHThorKeyedJoinBaseArg, public IHThorFetchContext
  1525. {
  1526. COMMON_NEWTHOR_FUNCTIONS
  1527. };
  1528. struct IHThorJoinArg : public IHThorJoinBaseArg
  1529. {
  1530. };
  1531. typedef IHThorJoinArg IHThorDenormalizeArg;
  1532. typedef IHThorAnyJoinBaseArg IHThorAllJoinArg;
  1533. // Used for hash and lookup joins.
  1534. struct IHThorHashJoinExtra : public IInterface
  1535. {
  1536. virtual IHash * queryHashLeft()=0;
  1537. virtual IHash * queryHashRight()=0;
  1538. };
  1539. struct IHThorHashJoinArg : public IHThorJoinArg, public IHThorHashJoinExtra
  1540. {
  1541. COMMON_NEWTHOR_FUNCTIONS
  1542. };
  1543. typedef IHThorHashJoinArg IHThorHashDenormalizeArg;
  1544. typedef IHThorHashJoinArg IHThorHashDenormalizeGroupArg;
  1545. enum
  1546. {
  1547. KDFvarindexfilename = 0x00000001,
  1548. KDFdynamicindexfilename = 0x00000002,
  1549. };
  1550. struct IHThorKeyedDistributeArg : public IHThorArg
  1551. {
  1552. // Inside the indexRead remote activity:
  1553. virtual const char * getIndexFileName() = 0;
  1554. virtual IOutputMetaData * queryIndexRecordSize() = 0; //Excluding fpos and sequence
  1555. virtual void createSegmentMonitors(IIndexReadContext *ctx, const void *lhs) = 0;
  1556. virtual unsigned getFlags() = 0;
  1557. virtual ICompare * queryCompareRowKey() = 0;
  1558. virtual unsigned getFormatCrc() = 0;
  1559. virtual bool getIndexLayout(size32_t & _retLen, void * & _retData) = 0;
  1560. };
  1561. struct IHThorFetchBaseArg : public IHThorArg, public IHThorFetchContext
  1562. {
  1563. virtual unsigned __int64 getRowLimit() { return (unsigned __int64) -1; }
  1564. virtual void onLimitExceeded() { }
  1565. inline bool transformNeedsRhs() { return queryExtractedSize() != 0; }
  1566. virtual size32_t extractJoinFields(ARowBuilder & rowBuilder, const void * _right) { return 0; }
  1567. virtual bool extractAllJoinFields() { return false; }
  1568. virtual IOutputMetaData * queryExtractedSize() { return NULL; }
  1569. };
  1570. struct IHThorBinFetchExtra : public IInterface
  1571. {
  1572. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _raw, const void * _key, unsigned __int64 _fpos) = 0;
  1573. };
  1574. struct IHThorFetchArg : public IHThorFetchBaseArg, public IHThorBinFetchExtra
  1575. {
  1576. COMMON_NEWTHOR_FUNCTIONS
  1577. };
  1578. enum
  1579. {
  1580. POFextend = 0x0001,
  1581. POFgrouped = 0x0002,
  1582. POFmaxsize = 0x0004,
  1583. };
  1584. struct IHThorWorkUnitWriteArg : public IHThorArg
  1585. {
  1586. virtual int getSequence() = 0;
  1587. virtual void serializeXml(const byte * self, IXmlWriter & out) = 0;
  1588. virtual const char * queryName() = 0;
  1589. virtual unsigned getFlags() = 0;
  1590. virtual unsigned getMaxSize() = 0; // size in Mb
  1591. };
  1592. struct IHThorXmlWorkunitWriteArg : public IHThorWorkUnitWriteArg
  1593. {
  1594. //Use a base class to add any functions here
  1595. };
  1596. struct IHThorHashDistributeArg : public IHThorArg
  1597. {
  1598. virtual IHash * queryHash()=0;
  1599. virtual bool isPulled()=0;
  1600. virtual double getSkew()=0; // iff queryHash returns NULL
  1601. virtual double getTargetSkew()=0;
  1602. virtual ICompare * queryMergeCompare()=0; // iff TAKhasdistributemerge
  1603. };
  1604. struct IHThorHashDedupArg : public IHThorArg
  1605. {
  1606. virtual ICompare * queryCompare()=0;
  1607. virtual IHash * queryHash()=0;
  1608. virtual IOutputMetaData * queryKeySize() = 0;
  1609. virtual size32_t recordToKey(ARowBuilder & rowBuilder, const void * _record) = 0;
  1610. virtual ICompare * queryKeyCompare()=0;
  1611. virtual unsigned getFlags() = 0;
  1612. virtual IHash * queryKeyHash()=0;
  1613. virtual ICompare * queryRowKeyCompare()=0; // lhs is a row, rhs is a key
  1614. virtual ICompare * queryCompareBest()=0;
  1615. inline bool compareAll() { return (getFlags() & HDFcompareall) != 0; }
  1616. inline bool keepLeft() { return (getFlags() & HDFkeepleft) != 0; }
  1617. inline bool keepBest() { return (getFlags() & HDFkeepbest) != 0; }
  1618. };
  1619. struct IHThorHashMinusArg : public IHThorArg
  1620. {
  1621. virtual ICompare * queryCompareLeft()=0;
  1622. virtual ICompare * queryCompareRight()=0;
  1623. virtual ICompare * queryCompareLeftRight()=0;
  1624. virtual IHash * queryHashLeft()=0;
  1625. virtual IHash * queryHashRight()=0;
  1626. };
  1627. struct IHThorIfArg : public IHThorArg
  1628. {
  1629. virtual bool getCondition() = 0;
  1630. };
  1631. struct IHThorCaseArg : public IHThorArg
  1632. {
  1633. virtual unsigned getBranch() = 0;
  1634. };
  1635. struct IHThorSequentialArg : public IHThorArg
  1636. {
  1637. virtual unsigned numBranches() = 0;
  1638. };
  1639. struct IHThorParallelArg : public IHThorArg
  1640. {
  1641. virtual unsigned numBranches() = 0;
  1642. };
  1643. enum
  1644. {
  1645. KDPoverwrite = 0x0001,
  1646. KDPtransform = 0x0002,
  1647. KDPvaroutputname = 0x0004,
  1648. KDPnooverwrite = 0x0008,
  1649. KDPexpires = 0x0010,
  1650. };
  1651. struct IHThorKeyDiffArg : public IHThorArg
  1652. {
  1653. virtual unsigned getFlags() = 0;
  1654. virtual const char * getOriginalName() = 0;
  1655. virtual const char * getUpdatedName() = 0;
  1656. virtual const char * getOutputName() = 0;
  1657. virtual int getSequence() = 0;
  1658. virtual unsigned getExpiryDays() = 0;
  1659. };
  1660. struct IHThorKeyPatchArg : public IHThorArg
  1661. {
  1662. virtual unsigned getFlags() = 0;
  1663. virtual const char * getOriginalName() = 0; // may be null
  1664. virtual const char * getPatchName() = 0;
  1665. virtual const char * getOutputName() = 0;
  1666. virtual int getSequence() = 0;
  1667. virtual unsigned getExpiryDays() = 0;
  1668. };
  1669. #ifdef WIN32
  1670. typedef unsigned char byte;
  1671. #endif
  1672. struct IHThorWorkunitReadArg : public IHThorArg
  1673. {
  1674. virtual const char * queryName() = 0;
  1675. virtual int querySequence() = 0;
  1676. virtual const char * getWUID() = 0;
  1677. virtual ICsvToRowTransformer * queryCsvTransformer() = 0;
  1678. virtual IXmlToRowTransformer * queryXmlTransformer() = 0;
  1679. };
  1680. struct IHThorLocalResultReadArg : public IHThorArg
  1681. {
  1682. virtual unsigned querySequence() = 0;
  1683. };
  1684. struct IHThorLocalResultWriteArg : public IHThorArg
  1685. {
  1686. virtual unsigned querySequence() = 0;
  1687. virtual bool usedOutsideGraph() { return true; }
  1688. };
  1689. struct IHThorGraphLoopResultReadArg : public IHThorArg
  1690. {
  1691. virtual unsigned querySequence() = 0;
  1692. };
  1693. struct IHThorGraphLoopResultWriteArg : public IHThorArg
  1694. {
  1695. };
  1696. typedef IHThorLocalResultWriteArg IHThorLocalResultSpillArg;
  1697. //-- Csv --
  1698. struct ICsvParameters
  1699. {
  1700. enum
  1701. {
  1702. defaultQuote = 0x0001,
  1703. defaultSeparate = 0x0002,
  1704. defaultTerminate = 0x0004,
  1705. hasUnicode = 0x0008,
  1706. singleHeaderFooter = 0x0010,
  1707. preserveWhitespace = 0x0020,
  1708. manyHeaderFooter = 0x0040,
  1709. defaultEscape = 0x0080,
  1710. }; // flags values
  1711. virtual unsigned getFlags() = 0;
  1712. virtual bool queryEBCDIC() = 0;
  1713. virtual const char * getHeader() { return NULL; }
  1714. virtual unsigned queryHeaderLen() = 0;
  1715. virtual size32_t queryMaxSize() = 0;
  1716. virtual const char * getQuote(unsigned idx) = 0;
  1717. virtual const char * getSeparator(unsigned idx) = 0;
  1718. virtual const char * getTerminator(unsigned idx) = 0;
  1719. virtual const char * getEscape(unsigned idx) = 0;
  1720. virtual const char * getFooter() { return NULL; }
  1721. };
  1722. struct ITypedOutputStream
  1723. {
  1724. public:
  1725. virtual void writeReal(double value) = 0;
  1726. virtual void writeSigned(__int64 value) = 0;
  1727. virtual void writeString(size32_t len, const char * data) = 0;
  1728. virtual void writeUnicode(size32_t len, const UChar * data) = 0;
  1729. virtual void writeUnsigned(unsigned __int64 value) = 0;
  1730. virtual void writeUtf8(size32_t len, const char * data) = 0;
  1731. };
  1732. struct IHThorCsvWriteExtra : public IInterface
  1733. {
  1734. virtual ICsvParameters * queryCsvParameters() = 0;
  1735. virtual void writeRow(const byte * self, ITypedOutputStream * out) = 0;
  1736. };
  1737. struct IHThorCsvWriteArg : public IHThorDiskWriteArg, public IHThorCsvWriteExtra
  1738. {
  1739. COMMON_NEWTHOR_FUNCTIONS
  1740. };
  1741. struct IHThorCsvFetchExtra: public IInterface
  1742. {
  1743. virtual unsigned getMaxColumns() = 0;
  1744. virtual ICsvParameters * queryCsvParameters() = 0;
  1745. virtual size32_t transform(ARowBuilder & rowBuilder, unsigned * lenLeft, const char * * dataLeft, const void * _key, unsigned __int64 _fpos) = 0;
  1746. };
  1747. struct IHThorCsvFetchArg : public IHThorFetchBaseArg, public IHThorCsvFetchExtra
  1748. {
  1749. COMMON_NEWTHOR_FUNCTIONS
  1750. };
  1751. //-- Xml --
  1752. struct IHThorXmlParseArg : public IHThorArg
  1753. {
  1754. virtual size32_t transform(ARowBuilder & rowBuilder, const void * left, IColumnProvider * parsed) = 0;
  1755. virtual const char * getXmlIteratorPath() = 0;
  1756. virtual void getSearchText(size32_t & retLen, char * & retText, const void * _self) = 0;
  1757. virtual bool searchTextNeedsFree() = 0;
  1758. virtual bool requiresContents() { return false; }
  1759. };
  1760. struct IHThorXmlFetchExtra : public IInterface
  1761. {
  1762. virtual size32_t transform(ARowBuilder & rowBuilder, IColumnProvider * rowLeft, const void * right, unsigned __int64 _fpos) = 0;
  1763. virtual bool requiresContents() { return false; }
  1764. };
  1765. struct IHThorXmlFetchArg : public IHThorFetchBaseArg, public IHThorXmlFetchExtra
  1766. {
  1767. COMMON_NEWTHOR_FUNCTIONS
  1768. };
  1769. //Simple xml generation...
  1770. struct IHThorXmlWriteExtra : public IInterface
  1771. {
  1772. virtual void toXML(const byte * self, IXmlWriter & out) = 0;
  1773. virtual const char * getXmlIteratorPath() { return NULL; } // supplies the prefix and suffix for a row
  1774. virtual const char * getHeader() { return NULL; }
  1775. virtual const char * getFooter() { return NULL; }
  1776. virtual unsigned getXmlFlags() { return 0; }
  1777. };
  1778. struct IHThorXmlWriteArg : public IHThorDiskWriteArg, public IHThorXmlWriteExtra
  1779. {
  1780. COMMON_NEWTHOR_FUNCTIONS
  1781. };
  1782. //-- PIPE access functions --
  1783. enum
  1784. {
  1785. TPFwritecsvtopipe = 0x0001,
  1786. TPFwritexmltopipe = 0x0002,
  1787. TPFreadcsvfrompipe = 0x0004,
  1788. TPFreadxmlfrompipe = 0x0008,
  1789. TPFreadusexmlcontents = 0x0010,
  1790. TPFreadnoroot = 0x0020,
  1791. TPFwritenoroot = 0x0040,
  1792. TPFrecreateeachrow = 0x0100,
  1793. TPFgroupeachrow = 0x0200,
  1794. TPFnofail = 0x0400,
  1795. };
  1796. struct IHThorPipeReadArg : public IHThorArg
  1797. {
  1798. virtual const char * getPipeProgram() = 0;
  1799. virtual IOutputMetaData * queryDiskRecordSize() = 0; // currently matches queryOutputMeta()
  1800. virtual unsigned getPipeFlags() = 0;
  1801. virtual ICsvToRowTransformer * queryCsvTransformer() = 0;
  1802. virtual IXmlToRowTransformer * queryXmlTransformer() = 0;
  1803. virtual const char * getXmlIteratorPath() = 0;
  1804. };
  1805. struct IHThorPipeWriteArg : public IHThorArg
  1806. {
  1807. virtual const char * getPipeProgram() = 0;
  1808. virtual int getSequence() = 0;
  1809. virtual IOutputMetaData * queryDiskRecordSize() = 0;
  1810. virtual char * getNameFromRow(const void * _self) { return NULL; }
  1811. virtual bool recreateEachRow() { return false; }
  1812. virtual unsigned getPipeFlags() = 0;
  1813. virtual IHThorCsvWriteExtra * queryCsvOutput() = 0;
  1814. virtual IHThorXmlWriteExtra * queryXmlOutput() = 0;
  1815. };
  1816. struct IHThorPipeThroughArg : public IHThorArg
  1817. {
  1818. virtual const char * getPipeProgram() = 0;
  1819. virtual char * getNameFromRow(const void * _self) { return NULL; }
  1820. virtual bool recreateEachRow() { return false; }
  1821. virtual unsigned getPipeFlags() = 0;
  1822. virtual IHThorCsvWriteExtra * queryCsvOutput() = 0;
  1823. virtual IHThorXmlWriteExtra * queryXmlOutput() = 0;
  1824. virtual ICsvToRowTransformer * queryCsvTransformer() = 0;
  1825. virtual IXmlToRowTransformer * queryXmlTransformer() = 0;
  1826. virtual const char * getXmlIteratorPath() = 0;
  1827. };
  1828. //-- SOAP --
  1829. enum
  1830. {
  1831. SOAPFgroup = 0x0001,
  1832. SOAPFonfail = 0x0002,
  1833. SOAPFlog = 0x0004,
  1834. SOAPFtrim = 0x0008,
  1835. SOAPFliteral = 0x0010,
  1836. SOAPFnamespace = 0x0020,
  1837. SOAPFencoding = 0x0040,
  1838. SOAPFpreserveSpace = 0x0080,
  1839. SOAPFlogmin = 0x0100,
  1840. SOAPFlogusermsg = 0x0200,
  1841. SOAPFhttpheaders = 0x0400,
  1842. SOAPFusescontents = 0x0800
  1843. };
  1844. struct IHThorWebServiceCallActionArg : public IHThorArg
  1845. {
  1846. virtual const char * getHosts() = 0;
  1847. virtual const char * getService() = 0;
  1848. //writing to the soap service.
  1849. virtual void toXML(const byte * self, IXmlWriter & out) = 0;
  1850. virtual const char * getHeader() = 0;
  1851. virtual const char * getFooter() = 0;
  1852. virtual unsigned getFlags() = 0;
  1853. virtual unsigned numParallelThreads() = 0;
  1854. virtual unsigned numRecordsPerBatch() = 0;
  1855. virtual int numRetries() = 0;
  1856. virtual double getTimeout() = 0;
  1857. virtual double getTimeLimit() = 0;
  1858. virtual const char * getSoapAction() = 0;
  1859. virtual const char * getNamespaceName() = 0;
  1860. virtual const char * getNamespaceVar() = 0;
  1861. virtual const char * getHttpHeaderName() = 0;
  1862. virtual const char * getHttpHeaderValue() = 0;
  1863. virtual const char * getProxyAddress() = 0;
  1864. virtual const char * getAcceptType() = 0;
  1865. virtual const char * getHttpHeaders() = 0;
  1866. virtual IXmlToRowTransformer * queryInputTransformer() = 0;
  1867. virtual const char * getInputIteratorPath() = 0;
  1868. virtual size32_t onFailTransform(ARowBuilder & rowBuilder, const void * left, IException * e) = 0;
  1869. virtual void getLogText(size32_t & lenText, char * & text, const void * left) = 0; // iff SOAPFlogusermsg set
  1870. };
  1871. typedef IHThorWebServiceCallActionArg IHThorSoapActionArg ;
  1872. typedef IHThorWebServiceCallActionArg IHThorHttpActionArg ;
  1873. class IHThorWebServiceCallArg : public IHThorWebServiceCallActionArg
  1874. {
  1875. };
  1876. typedef IHThorWebServiceCallArg IHThorSoapCallArg ;
  1877. typedef IHThorWebServiceCallArg IHThorHttpCallArg ;
  1878. typedef IHThorNullArg IHThorDatasetResultArg;
  1879. typedef IHThorNullArg IHThorRowResultArg;
  1880. //-- Parsing --
  1881. interface IMatchedResults
  1882. {
  1883. public:
  1884. virtual bool getMatched(unsigned idx) = 0;
  1885. virtual size32_t getMatchLength(unsigned idx) = 0;
  1886. virtual size32_t getMatchPosition(unsigned idx) = 0;
  1887. virtual void getMatchText(size32_t & outlen, char * & out, unsigned idx) = 0;
  1888. virtual void getMatchUnicode(size32_t & outlen, UChar * & out, unsigned idx) = 0;
  1889. virtual byte * queryRootResult() = 0;
  1890. virtual byte * queryMatchRow(unsigned idx) = 0;
  1891. virtual void getMatchUtf8(size32_t & outlen, char * & out, unsigned idx) = 0;
  1892. };
  1893. interface IProductionCallback
  1894. {
  1895. public:
  1896. virtual void getText(size32_t & outlen, char * & out, unsigned idx) = 0;
  1897. virtual void getUnicode(size32_t & outlen, UChar * & out, unsigned idx) = 0;
  1898. virtual byte * queryResult(unsigned idx) = 0;
  1899. virtual void getUtf8(size32_t & outlen, char * & out, unsigned idx) = 0;
  1900. };
  1901. interface IMatchWalker;
  1902. interface IValidator
  1903. {
  1904. };
  1905. interface IStringValidator : public IValidator
  1906. {
  1907. public:
  1908. virtual bool isValid(size32_t len, const char * text) = 0;
  1909. };
  1910. interface IUnicodeValidator : public IValidator
  1911. {
  1912. public:
  1913. virtual bool isValid(size32_t len, const UChar * text) = 0;
  1914. };
  1915. interface INlpHelper
  1916. {
  1917. public:
  1918. virtual IValidator * queryValidator(unsigned idx) = 0;
  1919. };
  1920. struct IHThorParseArg : public IHThorArg
  1921. {
  1922. enum { PFgroup = 1, PFparallel=2 };
  1923. virtual size32_t transform(ARowBuilder & rowBuilder, const void * left, IMatchedResults * results, IMatchWalker * walker) = 0;
  1924. virtual void getSearchText(size32_t & retLen, char * & retText, const void * _self) = 0;
  1925. virtual bool searchTextNeedsFree() = 0;
  1926. virtual void queryCompiled(IResourceContext *ctx, size32_t & retLen, const void * & retData) = 0;
  1927. virtual INlpHelper * queryHelper() = 0;
  1928. virtual unsigned getFlags() = 0;
  1929. virtual IOutputMetaData * queryProductionMeta(unsigned id) = 0;
  1930. virtual size32_t executeProduction(ARowBuilder & rowBuilder, unsigned id, IProductionCallback * input) = 0;
  1931. };
  1932. //------------------------- New interfaces for compound source activities -------------------------
  1933. enum { DISTANCE_EXACT_MATCH = 0x80000000 };
  1934. interface IDistanceCalculator
  1935. {
  1936. //returns which field has the difference, and distance in the 1st paramater. Returns DISTANCE_EXACT_MATCH if all fields match.
  1937. virtual unsigned getDistance(unsigned __int64 & distance, const void * before, const void * after, unsigned numFields) const =0;
  1938. protected:
  1939. virtual ~IDistanceCalculator() {}
  1940. };
  1941. interface ISteppingMeta
  1942. {
  1943. virtual unsigned getNumFields() = 0;
  1944. virtual const CFieldOffsetSize * queryFields() = 0; // order output by this activity (for merge/join = merge list)
  1945. virtual IRangeCompare * queryCompare() = 0; // NULL if can use memcmp to compare the fields?
  1946. virtual IDistanceCalculator * queryDistance() = 0;
  1947. };
  1948. //These were commoned up, but really they are completely different - so keep them separate
  1949. interface IThorDiskCallback : extends IFilePositionProvider
  1950. {
  1951. virtual const char * queryLogicalFilename(const void * row) = 0;
  1952. };
  1953. interface IThorIndexCallback : extends IInterface
  1954. {
  1955. virtual byte * lookupBlob(unsigned __int64 id) = 0; // return reference, not freed by code generator, can dispose once transform() has returned.
  1956. };
  1957. enum
  1958. {
  1959. SSFalwaysfilter = 0x0001,
  1960. SSFhaspriority = 0x0002,
  1961. SSFhasprefetch = 0x0004,
  1962. SSFisjoin = 0x0008,
  1963. };
  1964. interface IHThorSteppedSourceExtra
  1965. {
  1966. virtual unsigned getSteppedFlags() = 0;
  1967. virtual double getPriority() = 0;
  1968. virtual unsigned getPrefetchSize() = 0;
  1969. };
  1970. // Read, Normalize, Aggregate, Count, GroupAggregate, NormalizeAggregate
  1971. // any activity could theoretically have its (top-level) input filtered by segement monitors,
  1972. // so included below, but TAKchildXXX won't in practice. Filters are merged into the transform
  1973. // where-ever possible because that improves the scope for cse.
  1974. struct IHThorCompoundBaseArg : public IHThorArg
  1975. {
  1976. virtual bool canMatchAny() { return true; }
  1977. virtual void createSegmentMonitors(IIndexReadContext *ctx) {}
  1978. };
  1979. struct IHThorIndexReadBaseArg : extends IHThorCompoundBaseArg
  1980. {
  1981. virtual const char * getFileName() = 0;
  1982. virtual IOutputMetaData * queryDiskRecordSize() = 0; // Expected layout
  1983. virtual IOutputMetaData * queryProjectedDiskRecordSize() = 0; // Projected layout
  1984. virtual unsigned getFlags() = 0;
  1985. virtual unsigned getFormatCrc() = 0;
  1986. virtual void setCallback(IThorIndexCallback * callback) = 0;
  1987. virtual bool getIndexLayout(size32_t & _retLen, void * & _retData) = 0;
  1988. inline bool hasSegmentMonitors() { return (getFlags() & TIRnofilter) == 0; }
  1989. virtual IHThorSteppedSourceExtra *querySteppingExtra() { return NULL; }
  1990. };
  1991. struct IHThorDiskReadBaseArg : extends IHThorCompoundBaseArg
  1992. {
  1993. virtual const char * getFileName() = 0;
  1994. virtual IOutputMetaData * queryDiskRecordSize() = 0; // Expected layout
  1995. virtual IOutputMetaData * queryProjectedDiskRecordSize() = 0; // Projected layout
  1996. virtual unsigned getFlags() = 0;
  1997. virtual unsigned getFormatCrc() = 0;
  1998. virtual void getEncryptKey(size32_t & keyLen, void * & key) { keyLen = 0; key = 0; }
  1999. virtual void setCallback(IThorDiskCallback * callback) = 0;
  2000. inline bool hasSegmentMonitors() { return (getFlags() & TDRkeyed) != 0; }
  2001. };
  2002. //The following are mixin classes added to one of the activity base interfaces above.
  2003. // common between Read, Normalize
  2004. struct IHThorCompoundExtra : public IInterface
  2005. {
  2006. virtual unsigned __int64 getChooseNLimit() { return I64C(0x7fffffffffffffff); }
  2007. virtual unsigned __int64 getRowLimit() { return (unsigned __int64) -1; }
  2008. virtual void onLimitExceeded() { }
  2009. };
  2010. struct IHThorSourceCountLimit : public IInterface
  2011. {
  2012. virtual unsigned __int64 getRowLimit() = 0;
  2013. virtual void onLimitExceeded() = 0;
  2014. virtual unsigned __int64 getKeyedLimit() = 0;
  2015. virtual void onKeyedLimitExceeded() = 0;
  2016. };
  2017. struct IHThorSourceLimitTransformExtra : public IInterface
  2018. {
  2019. virtual size32_t transformOnLimitExceeded(ARowBuilder & rowBuilder) = 0;
  2020. virtual size32_t transformOnKeyedLimitExceeded(ARowBuilder & rowBuilder) = 0;
  2021. };
  2022. //Read
  2023. struct IHThorCompoundReadExtra : public IHThorCompoundExtra
  2024. {
  2025. virtual bool needTransform() = 0;
  2026. virtual bool transformMayFilter() = 0;
  2027. virtual size32_t transform(ARowBuilder & rowBuilder, const void * src) = 0;
  2028. virtual unsigned __int64 getKeyedLimit() = 0;
  2029. virtual void onKeyedLimitExceeded() = 0;
  2030. //v2 - stepping added
  2031. virtual ISteppingMeta * queryRawSteppingMeta() = 0;
  2032. virtual ISteppingMeta * queryProjectedSteppingMeta() = 0;
  2033. virtual void mapOutputToInput(ARowBuilder & rowBuilder, const void * projectedRow, unsigned numFields) = 0;
  2034. virtual size32_t unfilteredTransform(ARowBuilder & rowBuilder, const void * src) = 0; // only valid if TIRunmatchedtransform is set
  2035. };
  2036. //Normalize
  2037. struct IHThorCompoundNormalizeExtra : public IHThorCompoundExtra
  2038. {
  2039. virtual bool first(const void * src) = 0;
  2040. virtual bool next() = 0; //NB: src from transformFirst() must stay in memory while transformNext() is being called.
  2041. virtual size32_t transform(ARowBuilder & rowBuilder) = 0;
  2042. virtual unsigned __int64 getKeyedLimit() { return (unsigned __int64) -1; }
  2043. virtual void onKeyedLimitExceeded() { }
  2044. };
  2045. //Aggregate
  2046. struct IHThorCompoundAggregateExtra : public IInterface
  2047. {
  2048. virtual size32_t clearAggregate(ARowBuilder & rowBuilder) = 0;
  2049. virtual bool processedAnyRows() = 0;
  2050. virtual void processRow(ARowBuilder & rowBuilder, const void * src) = 0;
  2051. virtual void processRows(ARowBuilder & rowBuilder, size32_t srcLen, const void * src) = 0;
  2052. virtual size32_t mergeAggregate(ARowBuilder & rowBuilder, const void * src) = 0; //only call if transform called at least once on src.
  2053. };
  2054. //Count
  2055. struct IHThorCompoundCountExtra : public IInterface
  2056. {
  2057. virtual bool hasFilter() { return false; } // also true if denormalized(!)
  2058. virtual size32_t numValid(const void * src) { return 1; } //NB: Can be > 1 if source is normlized
  2059. virtual size32_t numValid(size32_t srcLen, const void * src) = 0;
  2060. virtual unsigned __int64 getChooseNLimit() { return (unsigned __int64) -1; }
  2061. };
  2062. //NormalizeAggregate
  2063. struct IHThorGroupAggregateCallback : public IInterface
  2064. {
  2065. virtual void processRow(const void * src) = 0;
  2066. };
  2067. struct IHThorCompoundGroupAggregateExtra : implements IHThorHashAggregateExtra, implements IHThorRowAggregator
  2068. {
  2069. virtual void processRow(const void * src, IHThorGroupAggregateCallback * callback) = 0;
  2070. virtual void processRows(size32_t srcLen, const void * src, IHThorGroupAggregateCallback * callback) = 0;
  2071. virtual bool createGroupSegmentMonitors(IIndexReadContext *ctx) = 0;
  2072. //Only applicable to index count variants.
  2073. virtual size32_t initialiseCountGrouping(ARowBuilder & rowBuilder, const void * src) = 0;
  2074. virtual size32_t processCountGrouping(ARowBuilder & rowBuilder, unsigned __int64 count) = 0;
  2075. virtual unsigned getGroupingMaxField() = 0;
  2076. };
  2077. //------------------------- Concrete definitions -------------------------
  2078. struct IHThorIndexReadArg : extends IHThorIndexReadBaseArg, extends IHThorSourceLimitTransformExtra, extends IHThorCompoundReadExtra
  2079. {
  2080. COMMON_NEWTHOR_FUNCTIONS
  2081. };
  2082. struct IHThorIndexNormalizeArg : extends IHThorIndexReadBaseArg, extends IHThorSourceLimitTransformExtra, extends IHThorCompoundNormalizeExtra
  2083. {
  2084. COMMON_NEWTHOR_FUNCTIONS
  2085. };
  2086. struct IHThorIndexAggregateArg : extends IHThorIndexReadBaseArg, extends IHThorCompoundAggregateExtra
  2087. {
  2088. COMMON_NEWTHOR_FUNCTIONS
  2089. };
  2090. struct IHThorIndexCountArg : extends IHThorIndexReadBaseArg, extends IHThorCompoundCountExtra, extends IHThorSourceCountLimit
  2091. {
  2092. COMMON_NEWTHOR_FUNCTIONS
  2093. };
  2094. struct IHThorIndexGroupAggregateArg : extends IHThorIndexReadBaseArg, extends IHThorCompoundGroupAggregateExtra
  2095. {
  2096. COMMON_NEWTHOR_FUNCTIONS
  2097. };
  2098. struct IHThorDiskReadArg : extends IHThorDiskReadBaseArg, extends IHThorSourceLimitTransformExtra, extends IHThorCompoundReadExtra
  2099. {
  2100. COMMON_NEWTHOR_FUNCTIONS
  2101. };
  2102. struct IHThorDiskNormalizeArg : extends IHThorDiskReadBaseArg, extends IHThorSourceLimitTransformExtra, extends IHThorCompoundNormalizeExtra
  2103. {
  2104. COMMON_NEWTHOR_FUNCTIONS
  2105. };
  2106. struct IHThorDiskAggregateArg : extends IHThorDiskReadBaseArg, extends IHThorCompoundAggregateExtra
  2107. {
  2108. COMMON_NEWTHOR_FUNCTIONS
  2109. };
  2110. struct IHThorDiskCountArg : extends IHThorDiskReadBaseArg, extends IHThorCompoundCountExtra, extends IHThorSourceCountLimit
  2111. {
  2112. COMMON_NEWTHOR_FUNCTIONS
  2113. };
  2114. struct IHThorDiskGroupAggregateArg : extends IHThorDiskReadBaseArg, extends IHThorCompoundGroupAggregateExtra
  2115. {
  2116. COMMON_NEWTHOR_FUNCTIONS
  2117. };
  2118. struct IHThorCsvReadArg: public IHThorDiskReadBaseArg
  2119. {
  2120. virtual unsigned getMaxColumns() = 0;
  2121. virtual ICsvParameters * queryCsvParameters() = 0;
  2122. virtual size32_t transform(ARowBuilder & rowBuilder, unsigned * srcLen, const char * * src) = 0;
  2123. virtual unsigned __int64 getChooseNLimit() = 0;
  2124. virtual unsigned __int64 getRowLimit() = 0;
  2125. virtual void onLimitExceeded() = 0;
  2126. };
  2127. struct IHThorXmlReadArg: public IHThorDiskReadBaseArg
  2128. {
  2129. virtual IXmlToRowTransformer * queryTransformer() = 0;
  2130. virtual const char * getXmlIteratorPath() = 0;
  2131. virtual unsigned __int64 getChooseNLimit() = 0;
  2132. virtual unsigned __int64 getRowLimit() = 0;
  2133. virtual void onLimitExceeded() = 0;
  2134. };
  2135. typedef unsigned thor_loop_counter_t;
  2136. struct IHThorLoopArg : public IHThorArg
  2137. {
  2138. enum {
  2139. LFparallel = 1,
  2140. LFcounter = 2,
  2141. LFfiltered = 4,
  2142. LFnewloopagain = 8,
  2143. };
  2144. virtual unsigned getFlags() = 0;
  2145. virtual bool sendToLoop(unsigned counter, const void * in) = 0; // does the input row go to output or round the loop?
  2146. virtual unsigned numIterations() = 0; // 0 if using loopAgain() instead.
  2147. virtual bool loopAgain(unsigned counter, unsigned numRows, const void * * _rows) = 0;
  2148. virtual void createParentExtract(rtlRowBuilder & builder) = 0;
  2149. virtual unsigned defaultParallelIterations() = 0;
  2150. //If new loop again is set the following should be used instead of loopAgain
  2151. virtual bool loopFirstTime() = 0;
  2152. virtual unsigned loopAgainResult() = 0; // which result contains the indication of whether to loop again?
  2153. };
  2154. struct IHThorGraphLoopArg : public IHThorArg
  2155. {
  2156. enum {
  2157. GLFparallel = 1,
  2158. GLFcounter = 2,
  2159. };
  2160. virtual unsigned getFlags() = 0;
  2161. virtual unsigned numIterations() = 0;
  2162. virtual void createParentExtract(rtlRowBuilder & builder) = 0;
  2163. };
  2164. struct IHThorRemoteArg : public IHThorArg
  2165. {
  2166. virtual void createParentExtract(rtlRowBuilder & builder) = 0;
  2167. virtual unsigned __int64 getRowLimit() = 0;
  2168. virtual void onLimitExceeded() = 0;
  2169. };
  2170. struct IHThorLibraryCallArg : public IHThorArg
  2171. {
  2172. virtual void createParentExtract(rtlRowBuilder & builder) = 0;
  2173. virtual IOutputMetaData * queryOutputMeta(unsigned whichOutput) = 0;
  2174. virtual char * getLibraryName() = 0;
  2175. };
  2176. //------ Child varieties ------
  2177. // Child versions are defined separately because
  2178. // i) not all versions are availble,
  2179. // ii) they will never use segment monitors
  2180. // iii) transforms don't have row passed in.
  2181. // iv) Never any need to merge aggregates
  2182. //Normalize
  2183. struct IHThorChildNormalizeArg : public IHThorArg
  2184. {
  2185. virtual bool first() = 0;
  2186. virtual bool next() = 0;
  2187. virtual size32_t transform(ARowBuilder & rowBuilder) = 0;
  2188. //?? virtual bool canMatchAny() { return true; }
  2189. };
  2190. //Aggregate
  2191. struct IHThorChildAggregateArg : public IHThorArg
  2192. {
  2193. virtual size32_t clearAggregate(ARowBuilder & rowBuilder) = 0;
  2194. virtual void processRows(ARowBuilder & rowBuilder) = 0;
  2195. };
  2196. //NormalizedAggregate
  2197. //NB: The child may actually be a grandchild/great-grand child, so need to store some sort of current state in the hash table
  2198. struct IHThorChildGroupAggregateBaseArg : public IHThorArg
  2199. {
  2200. virtual void processRows(IHThorGroupAggregateCallback * tc) = 0;
  2201. };
  2202. struct IHThorChildGroupAggregateArg : extends IHThorChildGroupAggregateBaseArg, extends IHThorHashAggregateExtra, implements IHThorRowAggregator
  2203. {
  2204. COMMON_NEWTHOR_FUNCTIONS
  2205. };
  2206. struct IHThorChildThroughNormalizeBaseArg : public IHThorArg
  2207. {
  2208. };
  2209. struct IHThorChildThroughNormalizeArg : public IHThorChildThroughNormalizeBaseArg, extends IHThorCompoundNormalizeExtra
  2210. {
  2211. COMMON_NEWTHOR_FUNCTIONS
  2212. };
  2213. //------------------------- Smart stepping activities -------------------------
  2214. //Does it make any sense to support these globally in thor?
  2215. struct IHThorNWayInputArg : public IHThorArg
  2216. {
  2217. virtual void getInputSelection(bool & isAll, size32_t & tlen, void * & tgt) = 0;
  2218. };
  2219. struct IHThorNWayGraphLoopResultReadArg : public IHThorArg
  2220. {
  2221. virtual void getInputSelection(bool & isAll, size32_t & tlen, void * & tgt) = 0;
  2222. virtual bool isGrouped() const = 0;
  2223. };
  2224. struct IHThorNWayMergeExtra : public IInterface
  2225. {
  2226. virtual ISteppingMeta * querySteppingMeta() = 0;
  2227. };
  2228. struct IHThorNWayMergeArg : extends IHThorMergeArg, extends IHThorNWayMergeExtra
  2229. {
  2230. COMMON_NEWTHOR_FUNCTIONS
  2231. };
  2232. struct IHThorNWaySelectArg : public IHThorArg
  2233. {
  2234. virtual unsigned getInputIndex() = 0;
  2235. };
  2236. //Notes:
  2237. //Join condition has an equality part, and an optional range part. It can merge or transform to generate output
  2238. //if (transforming, or has a range) then mergeOrder is the join condition, otherwise it can be larger.
  2239. //Stepping information is generated for all fields in the merge order.
  2240. struct IHThorNWayMergeJoinArg : public IHThorArg
  2241. {
  2242. enum
  2243. {
  2244. MJFinner = 0x00000000,
  2245. MJFleftonly = 0x00000001,
  2246. MJFmofn = 0x00000002,
  2247. MJFleftouter = 0x00000003,
  2248. MJFkindmask = 0x0000000F,
  2249. MJFtransform = 0x00000010,
  2250. MJFdedup = 0x00000020,
  2251. MJFhasrange = 0x00000040, // join condition has range component
  2252. MJFstepped = 0x00000080, // ensure that all inputs support stepping.
  2253. MJFhasdistance = 0x00000100,
  2254. MJFassertsorted = 0x00000200,
  2255. MJFglobalcompare = 0x00000400,
  2256. MJFhasclearlow = 0x00000800,
  2257. MJFhaspartition = 0x00001000,
  2258. //top bits may be used for temporary flags to test out optimizations - set using INTERNAL(0xnnnnnn)
  2259. };
  2260. virtual unsigned getJoinFlags() = 0;
  2261. virtual ISteppingMeta * querySteppingMeta() = 0; // meta for
  2262. virtual IOutputMetaData * queryInputMeta() = 0;
  2263. virtual unsigned numEqualFields() = 0;
  2264. virtual unsigned numOrderFields() = 0; // how many fields output is ordered by
  2265. virtual ICompare * queryMergeCompare()=0; // same as querySteepingMeta()->queryCompare(#orderFields)
  2266. virtual ICompare * queryEqualCompare()=0; // same as querySteppingMeta()->queryCompare(#equalFields);
  2267. virtual ICompareEq * queryEqualCompareEq()=0; // same as querySteppingMeta()->queryCompare(#equalFields) == 0;
  2268. virtual ICompareEq * queryNonSteppedCompare() = 0; // non-stepped exact (range) comparison, return NULL if none;
  2269. // requires cross product to be calculated really, so not goof for simple merge join
  2270. //For range comparison
  2271. virtual void adjustRangeValue(ARowBuilder & rowBuilder, const void * input, __int64 delta) = 0; // implementation must ensure field doesn't go -ve.
  2272. virtual unsigned __int64 extractRangeValue(const void * input) = 0; // distance is assumed to be unsigned, code generator must bias if not true.
  2273. virtual __int64 maxRightBeforeLeft() = 0;
  2274. virtual __int64 maxLeftBeforeRight() = 0;
  2275. //MJFtransform
  2276. virtual size32_t transform(ARowBuilder & rowBuilder, unsigned _num, const void * * _rows) = 0;
  2277. //MJFleftonly helper
  2278. virtual bool createNextJoinValue(ARowBuilder & rowBuilder, const void * _value) = 0;
  2279. //MJFmofn helper
  2280. virtual unsigned getMinMatches() = 0;
  2281. virtual unsigned getMaxMatches() = 0;
  2282. //merge join function for comparing all rows.
  2283. virtual INaryCompareEq * queryGlobalCompare() = 0; // for merge join, guarded by flag MJFglobalcompare is set.
  2284. virtual size32_t createLowInputRow(ARowBuilder & rowBuilder) = 0;
  2285. virtual ICompareEq * queryPartitionCompareEq()=0; // only present if MJFhaspartition is defined
  2286. };
  2287. enum
  2288. {
  2289. PPFparallel = 0x0001,
  2290. };
  2291. struct IHThorPrefetchProjectArg : public IHThorArg
  2292. {
  2293. virtual bool canFilter() = 0;
  2294. virtual bool canMatchAny() = 0;
  2295. virtual unsigned getFlags() = 0;
  2296. virtual unsigned getLookahead() = 0;
  2297. virtual IThorChildGraph *queryChild() = 0;
  2298. virtual bool preTransform(rtlRowBuilder & extract, const void * _left, unsigned __int64 _counter) = 0; // returns false if left can be skipped
  2299. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, IEclGraphResults * results, unsigned __int64 _counter) = 0;
  2300. };
  2301. //Combination of filter and [count] project
  2302. struct IHThorFilterProjectArg : public IHThorArg
  2303. {
  2304. virtual bool canFilter() = 0;
  2305. virtual bool canMatchAny() = 0;
  2306. virtual size32_t transform(ARowBuilder & rowBuilder, const void * _left, unsigned __int64 _counter) = 0;
  2307. };
  2308. enum {
  2309. TSFprivate = 0x0001, //contents can't be seen
  2310. TSFdynamicDescription = 0x0002, //has a get description that depends on the context (otherwise blank)
  2311. };
  2312. struct IHThorSectionArg : public IHThorArg
  2313. {
  2314. virtual unsigned getFlags() = 0;
  2315. virtual void getDescription(size32_t & _retLen, char * & _retData) = 0;
  2316. };
  2317. struct IHThorSectionInputArg : public IHThorArg
  2318. {
  2319. virtual unsigned getFlags() = 0;
  2320. };
  2321. struct IHThorStreamedIteratorArg : public IHThorArg
  2322. {
  2323. virtual IRowStream * createInput() = 0;
  2324. };
  2325. interface IPropertyTree;
  2326. interface IThorExternalRowProcessor : public IInterface
  2327. {
  2328. virtual void onCreate(ICodeContext * ctx, IPropertyTree * graph) = 0;
  2329. virtual void addInput(unsigned idx, ITypedRowStream * input) = 0;
  2330. virtual IRowStream * createOutput(unsigned idx) = 0;
  2331. virtual void start() = 0;
  2332. virtual void execute() = 0;
  2333. virtual void stop() = 0;
  2334. virtual void reset() = 0;
  2335. virtual void onDestroy() = 0;
  2336. };
  2337. struct IHThorExternalArg : public IHThorArg
  2338. {
  2339. virtual IThorExternalRowProcessor * createProcessor() = 0;
  2340. };
  2341. //------------------------- Dictionary stuff -------------------------
  2342. interface IHThorHashLookupInfo
  2343. {
  2344. virtual IHash * queryHash() = 0;
  2345. virtual ICompare * queryCompare() = 0;
  2346. virtual IHash * queryHashLookup() = 0;
  2347. virtual ICompare * queryCompareLookup() = 0;
  2348. };
  2349. struct IHThorDictionaryWorkUnitWriteArg : public IHThorArg
  2350. {
  2351. virtual int getSequence() = 0;
  2352. virtual const char * queryName() = 0;
  2353. virtual unsigned getFlags() = 0;
  2354. virtual IHThorHashLookupInfo * queryHashLookupInfo() = 0;
  2355. };
  2356. struct IHThorDictionaryResultWriteArg : public IHThorArg
  2357. {
  2358. virtual unsigned querySequence() = 0;
  2359. virtual bool usedOutsideGraph() = 0;
  2360. virtual IHThorHashLookupInfo * queryHashLookupInfo() = 0;
  2361. };
  2362. struct IHThorTraceArg : public IHThorArg
  2363. {
  2364. virtual bool isValid(const void * _left) = 0;
  2365. virtual bool canMatchAny() = 0;
  2366. virtual unsigned getKeepLimit() = 0;
  2367. virtual unsigned getSample() = 0;
  2368. virtual unsigned getSkip() = 0;
  2369. virtual const char *getName() = 0;
  2370. };
  2371. //------------------------- Other stuff -------------------------
  2372. struct IRemoteConnection;
  2373. struct IGlobalCodeContext
  2374. {
  2375. virtual ICodeContext * queryCodeContext() = 0;
  2376. virtual void fail(int, const char *) = 0;
  2377. virtual bool isResult(const char * name, unsigned sequence) = 0;
  2378. virtual unsigned getWorkflowId() = 0;
  2379. virtual void doNotify(char const * name, char const * text) = 0;
  2380. virtual int queryLastFailCode() = 0;
  2381. virtual void getLastFailMessage(size32_t & outLen, char * & outStr, const char * tag) = 0;
  2382. virtual bool fileExists(const char * filename) = 0;
  2383. virtual void deleteFile(const char * logicalName) = 0;
  2384. virtual void selectCluster(const char * cluster) = 0;
  2385. virtual void restoreCluster() = 0;
  2386. virtual void setWorkflowCondition(bool value) = 0;
  2387. virtual void returnPersistVersion(const char * logicalName, unsigned eclCRC, unsigned __int64 allCRC, bool isFile) = 0;
  2388. virtual void setResultDataset(const char * name, unsigned sequence, size32_t len, const void *val, unsigned numRows, bool extend) = 0;
  2389. virtual void getEventName(size32_t & outLen, char * & outStr) = 0;
  2390. virtual void getEventExtra(size32_t & outLen, char * & outStr, const char * tag) = 0;
  2391. virtual void doNotify(char const * name, char const * text, const char * target) = 0;
  2392. };
  2393. struct IEclProcess : public IInterface
  2394. {
  2395. virtual int perform(IGlobalCodeContext * gctx, unsigned wfid) = 0;
  2396. virtual unsigned getActivityVersion() const = 0;
  2397. };
  2398. //------------------------------------------------------------------------------------------------
  2399. inline bool isLocalFpos(unsigned __int64 rp) { return (rp & I64C(0x8000000000000000)) != 0; }
  2400. inline unsigned getLocalFposPart(unsigned __int64 rp) { return (unsigned) ((rp >> 48) & 0x7fff); }
  2401. inline unsigned __int64 getLocalFposOffset(unsigned __int64 rp) { return rp & I64C(0xffffffffffff); }
  2402. inline unsigned __int64 makeLocalFposOffset(unsigned part, unsigned __int64 offset)
  2403. {
  2404. return (I64C(0x8000000000000000) | ((unsigned __int64)(part) << 48) | (offset));
  2405. }
  2406. static inline unsigned rtlMin(unsigned a, unsigned b) { return a < b ? a : b; }
  2407. static inline unsigned rtlMax(unsigned a, unsigned b) { return a > b ? a : b; }
  2408. class XmlChildIterator
  2409. {
  2410. public:
  2411. inline XmlChildIterator() {};
  2412. inline ~XmlChildIterator() {};
  2413. inline void initOwn(IColumnProviderIterator * _iter) { cur.clear(); iter.setown(_iter); }
  2414. inline IColumnProvider * first() { if (iter) cur.set(iter->first()); return cur; }
  2415. inline IColumnProvider * next() { if (iter) cur.set(iter->next()); return cur; }
  2416. protected:
  2417. Owned<IColumnProviderIterator> iter;
  2418. Owned<IColumnProvider> cur;
  2419. };
  2420. #ifdef STARTQUERY_EXPORTS
  2421. #define STARTQUERY_API DECL_EXPORT
  2422. #else
  2423. #define STARTQUERY_API DECL_IMPORT
  2424. #endif
  2425. int STARTQUERY_API start_query(int argc, const char *argv[]);
  2426. #endif