eclhelper.hpp 101 KB

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