eclhelper.hpp 112 KB

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