thcodectx.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #include "jiface.hpp"
  15. #include "jmisc.hpp"
  16. #include "deftype.hpp"
  17. #include "workunit.hpp"
  18. #include "thexception.hpp"
  19. #include "thormisc.hpp"
  20. #include "eclrtl.hpp"
  21. #include "thcodectx.hpp"
  22. #include "dacoven.hpp"
  23. #include "dasess.hpp"
  24. #include "dadfs.hpp"
  25. #include "thorxmlread.hpp"
  26. #include "thgraph.hpp"
  27. #include "thorxmlwrite.hpp"
  28. CThorCodeContextBase::CThorCodeContextBase(CJobBase &_job, ILoadedDllEntry &_querySo, IUserDescriptor &_userDesc) : job(_job), querySo(_querySo), userDesc(&_userDesc)
  29. {
  30. }
  31. char *CThorCodeContextBase::getWuid()
  32. {
  33. StringBuffer out;
  34. out.append(job.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(job.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. char *CThorCodeContextBase::getDaliServers()
  59. {
  60. StringBuffer dali;
  61. IGroup &group = queryCoven().queryComm().queryGroup();
  62. Owned<INodeIterator> coven = group.getIterator();
  63. bool first = true;
  64. ForEach(*coven)
  65. {
  66. if (first)
  67. first = false;
  68. else
  69. dali.append(',');
  70. coven->query().endpoint().getUrlStr(dali);
  71. }
  72. return dali.detach();
  73. }
  74. const char *CThorCodeContextBase::loadResource(unsigned id)
  75. {
  76. return (const char *) querySo.getResource(id);
  77. }
  78. void CThorCodeContextBase::expandLogicalName(StringBuffer & fullname, const char * logicalName)
  79. {
  80. if (logicalName[0]=='~')
  81. logicalName++;
  82. else
  83. {
  84. if (job.queryScope())
  85. fullname.append(job.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 job.getRowAllocator(meta, activityId);
  99. }
  100. ILocalGraph *CThorCodeContextBase::resolveLocalQuery(__int64 gid)
  101. {
  102. ILocalGraph *graph = job.getGraph((graph_id)gid);
  103. graph->Release(); // resolveLocalQuery doesn't own, can't otherwise will be circular ref.
  104. return graph;
  105. }
  106. IThorChildGraph *CThorCodeContextBase::resolveChildQuery(__int64 gid, IHThorArg *colocal)
  107. {
  108. return job.getGraph((graph_id)gid);
  109. }
  110. void CThorCodeContextBase::getRowXML(size32_t & lenResult, char * & result, IOutputMetaData & info, const void * row, unsigned flags)
  111. {
  112. convertRowToXML(lenResult, result, info, row, flags);
  113. }
  114. const void * CThorCodeContextBase::fromXml(IEngineRowAllocator * rowAllocator, size32_t len, const char * utf8, IXmlToRowTransformer * xmlTransformer, bool stripWhitespace)
  115. {
  116. return createRowFromXml(rowAllocator, len, utf8, xmlTransformer, stripWhitespace);
  117. }