eclhelper.hpp 104 KB

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