eclhelper.hpp 103 KB

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