eclhelper.hpp 108 KB

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