eclhelper.hpp 107 KB

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