eclhelper.hpp 108 KB

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