thcodectx.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. CThorCodeContextBase::CThorCodeContextBase(CJobChannel &_jobChannel, ILoadedDllEntry &_querySo, IUserDescriptor &_userDesc) : jobChannel(_jobChannel), querySo(_querySo), userDesc(&_userDesc)
  28. {
  29. }
  30. char *CThorCodeContextBase::getWuid()
  31. {
  32. StringBuffer out;
  33. out.append(jobChannel.queryJob().queryWuid());
  34. return out.detach();
  35. }
  36. char *CThorCodeContextBase::getJobName()
  37. {
  38. throwUnexpected();
  39. return NULL;
  40. }
  41. char *CThorCodeContextBase::getJobOwner()
  42. {
  43. StringBuffer out;
  44. out.append(jobChannel.queryJob().queryUser());
  45. return out.detach();
  46. }
  47. char *CThorCodeContextBase::getClusterName()
  48. {
  49. throwUnexpected();
  50. return NULL;
  51. }
  52. char *CThorCodeContextBase::getGroupName()
  53. {
  54. throwUnexpected();
  55. return NULL;
  56. }
  57. const char *CThorCodeContextBase::loadResource(unsigned id)
  58. {
  59. return (const char *) querySo.getResource(id);
  60. }
  61. char *CThorCodeContextBase::getDaliServers()
  62. {
  63. StringBuffer dali;
  64. IGroup &group = queryCoven().queryComm().queryGroup();
  65. Owned<INodeIterator> coven = group.getIterator();
  66. bool first = true;
  67. ForEach(*coven)
  68. {
  69. if (first)
  70. first = false;
  71. else
  72. dali.append(',');
  73. coven->query().endpoint().getUrlStr(dali);
  74. }
  75. return dali.detach();
  76. }
  77. void CThorCodeContextBase::expandLogicalName(StringBuffer & fullname, const char * logicalName)
  78. {
  79. if (logicalName[0]=='~')
  80. logicalName++;
  81. else
  82. {
  83. if (jobChannel.queryJob().queryScope())
  84. fullname.append(jobChannel.queryJob().queryScope()).append("::");
  85. }
  86. fullname.append(logicalName);
  87. fullname.toLowerCase();
  88. }
  89. char *CThorCodeContextBase::getExpandLogicalName(const char * logicalName)
  90. {
  91. StringBuffer lfn;
  92. expandLogicalName(lfn, logicalName);
  93. return lfn.detach();
  94. }
  95. IEngineRowAllocator * CThorCodeContextBase::getRowAllocator(IOutputMetaData * meta, unsigned activityId) const
  96. {
  97. return jobChannel.getRowAllocator(meta, activityId);
  98. }
  99. const char * CThorCodeContextBase::cloneVString(const char * str) const
  100. {
  101. return jobChannel.queryRowManager().cloneVString(str);
  102. }
  103. const char * CThorCodeContextBase::cloneVString(size32_t len, const char * str) const
  104. {
  105. return jobChannel.queryRowManager().cloneVString(len, str);
  106. }
  107. IEclGraphResults *CThorCodeContextBase::resolveLocalQuery(__int64 gid)
  108. {
  109. IEclGraphResults *graph = jobChannel.getGraph((graph_id)gid);
  110. graph->Release(); // resolveLocalQuery doesn't own, can't otherwise will be circular ref.
  111. return graph;
  112. }
  113. IThorChildGraph *CThorCodeContextBase::resolveChildQuery(__int64 gid, IHThorArg *colocal)
  114. {
  115. return jobChannel.getGraph((graph_id)gid);
  116. }
  117. void CThorCodeContextBase::getRowXML(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags)
  118. {
  119. convertRowToXML(lenResult, result, info, row, flags);
  120. }
  121. void CThorCodeContextBase::getRowJSON(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags)
  122. {
  123. convertRowToJSON(lenResult, result, info, row, flags);
  124. }
  125. const void * CThorCodeContextBase::fromXml(IEngineRowAllocator * rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace)
  126. {
  127. return createRowFromXml(rowAllocator, len, utf8, xmlTransformer, stripWhitespace);
  128. }
  129. const void * CThorCodeContextBase::fromJson(IEngineRowAllocator * rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace)
  130. {
  131. return createRowFromJson(rowAllocator, len, utf8, xmlTransformer, stripWhitespace);
  132. }