eclhelper.hpp 108 KB

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