eclhelper.hpp 105 KB

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