thcodectx.cpp 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems®.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jiface.hpp"
  14. #include "jmisc.hpp"
  15. #include "deftype.hpp"
  16. #include "workunit.hpp"
  17. #include "thexception.hpp"
  18. #include "thormisc.hpp"
  19. #include "eclrtl.hpp"
  20. #include "thcodectx.hpp"
  21. #include "dacoven.hpp"
  22. #include "dasess.hpp"
  23. #include "dadfs.hpp"
  24. #include "thorxmlread.hpp"
  25. #include "thgraph.hpp"
  26. #include "thorxmlwrite.hpp"
  27. #include "roxiehelper.hpp"
  28. CThorCodeContextBase::CThorCodeContextBase(CJobChannel &_jobChannel, ILoadedDllEntry &_querySo, IUserDescriptor &_userDesc) : jobChannel(_jobChannel), querySo(_querySo), userDesc(&_userDesc)
  29. {
  30. }
  31. char *CThorCodeContextBase::getWuid()
  32. {
  33. StringBuffer out;
  34. out.append(jobChannel.queryJob().queryWuid());
  35. return out.detach();
  36. }
  37. char *CThorCodeContextBase::getJobName()
  38. {
  39. throwUnexpected();
  40. return NULL;
  41. }
  42. char *CThorCodeContextBase::getJobOwner()
  43. {
  44. StringBuffer out;
  45. out.append(jobChannel.queryJob().queryUser());
  46. return out.detach();
  47. }
  48. char *CThorCodeContextBase::getClusterName()
  49. {
  50. throwUnexpected();
  51. return NULL;
  52. }
  53. char *CThorCodeContextBase::getGroupName()
  54. {
  55. throwUnexpected();
  56. return NULL;
  57. }
  58. const char *CThorCodeContextBase::loadResource(unsigned id)
  59. {
  60. return (const char *) querySo.getResource(id);
  61. }
  62. char *CThorCodeContextBase::getDaliServers()
  63. {
  64. StringBuffer dali;
  65. IGroup &group = queryCoven().queryComm().queryGroup();
  66. Owned<INodeIterator> coven = group.getIterator();
  67. bool first = true;
  68. ForEach(*coven)
  69. {
  70. if (first)
  71. first = false;
  72. else
  73. dali.append(',');
  74. coven->query().endpoint().getUrlStr(dali);
  75. }
  76. return dali.detach();
  77. }
  78. void CThorCodeContextBase::expandLogicalName(StringBuffer & fullname, const char * logicalName)
  79. {
  80. if (logicalName[0]=='~')
  81. logicalName++;
  82. else
  83. {
  84. if (jobChannel.queryJob().queryScope())
  85. fullname.append(jobChannel.queryJob().queryScope()).append("::");
  86. }
  87. fullname.append(logicalName);
  88. fullname.toLowerCase();
  89. }
  90. char *CThorCodeContextBase::getExpandLogicalName(const char * logicalName)
  91. {
  92. StringBuffer lfn;
  93. expandLogicalName(lfn, logicalName);
  94. return lfn.detach();
  95. }
  96. IEngineRowAllocator * CThorCodeContextBase::getRowAllocator(IOutputMetaData * meta, unsigned activityId) const
  97. {
  98. return jobChannel.getRowAllocator(meta, activityId);
  99. }
  100. IEngineRowAllocator * CThorCodeContextBase::getRowAllocatorEx(IOutputMetaData * meta, unsigned activityId, unsigned heapFlags) const
  101. {
  102. return jobChannel.getRowAllocator(meta, activityId, (roxiemem::RoxieHeapFlags)heapFlags);
  103. }
  104. const char * CThorCodeContextBase::cloneVString(const char * str) const
  105. {
  106. return jobChannel.queryRowManager()->cloneVString(str);
  107. }
  108. const char * CThorCodeContextBase::cloneVString(size32_t len, const char * str) const
  109. {
  110. return jobChannel.queryRowManager()->cloneVString(len, str);
  111. }
  112. IEclGraphResults *CThorCodeContextBase::resolveLocalQuery(__int64 gid)
  113. {
  114. IEclGraphResults *graph = jobChannel.getGraph((graph_id)gid);
  115. graph->Release(); // resolveLocalQuery doesn't own, can't otherwise will be circular ref.
  116. return graph;
  117. }
  118. IThorChildGraph *CThorCodeContextBase::resolveChildQuery(__int64 gid, IHThorArg *colocal)
  119. {
  120. return jobChannel.getGraph((graph_id)gid);
  121. }
  122. void CThorCodeContextBase::getRowXML(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags)
  123. {
  124. convertRowToXML(lenResult, result, info, row, flags);
  125. }
  126. void CThorCodeContextBase::getRowJSON(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags)
  127. {
  128. convertRowToJSON(lenResult, result, info, row, flags);
  129. }
  130. const void * CThorCodeContextBase::fromXml(IEngineRowAllocator * rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace)
  131. {
  132. return createRowFromXml(rowAllocator, len, utf8, xmlTransformer, stripWhitespace);
  133. }
  134. const void * CThorCodeContextBase::fromJson(IEngineRowAllocator * rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace)
  135. {
  136. return createRowFromJson(rowAllocator, len, utf8, xmlTransformer, stripWhitespace);
  137. }
  138. ISectionTimer * CThorCodeContextBase::registerTimer(unsigned activityId, const char * name)
  139. {
  140. return queryNullSectionTimer();
  141. }