eclhelper.hpp 102 KB

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