fvwusource.cpp 4.9 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 "platform.h"
  14. #include "jliball.hpp"
  15. #include "eclrtl.hpp"
  16. #include "fvresultset.ipp"
  17. #include "fileview.hpp"
  18. #include "fvwusource.ipp"
  19. #include "eclhelper.hpp"
  20. #include "fvdatasource.hpp"
  21. WorkUnitDataSource::WorkUnitDataSource(IConstWUResult * _wuResult, const char * _wuid)
  22. {
  23. wuResult.set(_wuResult);
  24. wuid.set(_wuid);
  25. totalRows = wuResult->getResultTotalRowCount();
  26. if (totalRows == -1)
  27. totalRows = 0;
  28. totalSize = wuResult->getResultRawSize(NULL, NULL);
  29. }
  30. bool WorkUnitDataSource::init()
  31. {
  32. return setReturnedInfoFromResult();
  33. }
  34. __int64 WorkUnitDataSource::numRows(bool force)
  35. {
  36. return totalRows;
  37. }
  38. //---------------------------------------------------------------------------
  39. FullWorkUnitDataSource::FullWorkUnitDataSource(IConstWUResult * _wuResult, const char * _wuid) : WorkUnitDataSource(_wuResult, _wuid)
  40. {
  41. }
  42. bool FullWorkUnitDataSource::init()
  43. {
  44. bool ok = WorkUnitDataSource::init();
  45. if (ok)
  46. {
  47. MemoryBuffer temp;
  48. MemoryBuffer2IDataVal xxx(temp);
  49. //Nasty. Single sets are represented as the same way as datasets (with an extra flag for all)
  50. //however need to represent as a single row containing a set, which has a different format.
  51. if (wuResult->isResultScalar() && returnedMeta->isSingleSet())
  52. {
  53. temp.append(wuResult->getResultIsAll());
  54. temp.append((size32_t)wuResult->getResultRawSize(0, 0));
  55. }
  56. wuResult->getResultRaw(xxx, NULL, NULL);
  57. if (returnedMeta->isFixedSize())
  58. rows.setown(new FixedRowBlock(temp, 0, 0, returnedMeta->fixedSize()));
  59. else
  60. rows.setown(new VariableRowBlock(temp, 0, 0, returnedRecordSize, true));
  61. }
  62. return ok;
  63. }
  64. bool FullWorkUnitDataSource::fetchRowData(MemoryBuffer & out, __int64 offset)
  65. {
  66. size32_t length;
  67. const void * data = rows->fetchRow(offset, length);
  68. if (!data)
  69. return false;
  70. out.append(length, data);
  71. return true;
  72. }
  73. bool FullWorkUnitDataSource::getRowData(__int64 row, size32_t & length, const void * & data, unsigned __int64 & offset)
  74. {
  75. data = rows->getRow(row, length, offset);
  76. return (data != NULL);
  77. }
  78. //---------------------------------------------------------------------------
  79. PagedWorkUnitDataSource::PagedWorkUnitDataSource(IConstWUResult * _wuResult, const char * _wuid) : WorkUnitDataSource(_wuResult, _wuid)
  80. {
  81. }
  82. bool PagedWorkUnitDataSource::init()
  83. {
  84. return WorkUnitDataSource::init();
  85. }
  86. bool PagedWorkUnitDataSource::getRowData(__int64 row, size32_t & length, const void * & data, unsigned __int64 & offset)
  87. {
  88. if ((row < 0) || ((unsigned __int64)row > totalRows))
  89. return false;
  90. RowLocation location;
  91. for (;;)
  92. {
  93. if (cache.getCacheRow(row, location))
  94. {
  95. length = location.matchLength;
  96. data = location.matchRow;
  97. return true;
  98. }
  99. if (!loadBlock(location.bestRow, location.bestOffset))
  100. return false;
  101. }
  102. }
  103. bool PagedWorkUnitDataSource::fetchRowData(MemoryBuffer & out, __int64 offset)
  104. {
  105. MemoryBuffer temp;
  106. MemoryBuffer2IDataVal wrapper(out);
  107. wuResult->getResultRaw(wrapper, offset, returnedMeta->getMaxRecordSize(), NULL, NULL);
  108. if (temp.length() == 0)
  109. return false;
  110. return true;
  111. }
  112. bool PagedWorkUnitDataSource::loadBlock(__int64 startRow, offset_t startOffset)
  113. {
  114. MemoryBuffer temp;
  115. MemoryBuffer2IDataVal xxx(temp);
  116. RowBlock * rows;
  117. if (returnedMeta->isFixedSize())
  118. {
  119. unsigned fixedSize = returnedMeta->fixedSize();
  120. unsigned readSize = (WU_BLOCK_SIZE / fixedSize) * fixedSize;
  121. wuResult->getResultRaw(xxx, startOffset, readSize, NULL, NULL);
  122. if (temp.length() == 0)
  123. return false;
  124. rows = new FixedRowBlock(temp, startRow, startOffset, fixedSize);
  125. }
  126. else
  127. {
  128. wuResult->getResultRaw(xxx, startOffset, WU_BLOCK_SIZE, NULL, NULL);
  129. if (temp.length() == 0)
  130. return false;
  131. rows = new VariableRowBlock(temp, startRow, startOffset, returnedRecordSize, startOffset + temp.length() == totalSize);
  132. }
  133. cache.addRowsOwn(rows);
  134. return true;
  135. }