eclhelper.hpp 107 KB

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