eclhelper.hpp 110 KB

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