eclhelper.hpp 112 KB

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