eclhelper.hpp 101 KB

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