fvdisksource.ipp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. #ifndef FVDISKSOURCE_IPP
  15. #define FVDISKSOURCE_IPP
  16. #include "junicode.hpp"
  17. #include "fvdatasource.hpp"
  18. #include "dllserver.hpp"
  19. #include "hqlexpr.hpp"
  20. #include "eclhelper.hpp"
  21. #include "fvsource.ipp"
  22. #include "dadfs.hpp"
  23. class PhysicalFileInfo
  24. {
  25. public:
  26. PhysicalFileInfo();
  27. void close();
  28. offset_t getOptimizedOffset(offset_t offset, unsigned copyLength);
  29. void init(IDistributedFile * _df);
  30. bool readData(MemoryBuffer & out, __int64 offset, size32_t length);
  31. public:
  32. Owned<IDistributedFile> df;
  33. CriticalSection cs;
  34. unsigned __int64 totalSize;
  35. unsigned cachedPart;
  36. OwnedIFile cachedFile;
  37. OwnedIFileIO cachedIO;
  38. Int64Array partSizes;
  39. };
  40. class DiskDataSource : public PagedDataSource
  41. {
  42. public:
  43. DiskDataSource(const char * _logicalName, IHqlExpression * _diskRecord, const char* _username, const char* _password);
  44. protected:
  45. StringAttr logicalName;
  46. Owned<DataSourceMetaData> diskMeta;
  47. HqlExprAttr diskRecord;
  48. Owned<IDistributedFile> df;
  49. };
  50. class DirectDiskDataSource : public DiskDataSource
  51. {
  52. public:
  53. DirectDiskDataSource(const char * _logicalName, IHqlExpression * _diskRecord, const char* _username, const char* _password);
  54. virtual bool init();
  55. virtual void onClose();
  56. virtual bool fetchRowData(MemoryBuffer & out, __int64 offset);
  57. virtual bool isIndex() { return false; }
  58. protected:
  59. size32_t getCopyLength();
  60. virtual bool loadBlock(__int64 startRow, offset_t startOffset);
  61. void improveLocation(__int64 row, RowLocation & location);
  62. protected:
  63. PhysicalFileInfo physical;
  64. size32_t readBlockSize;
  65. };
  66. class CsvRecordSize : public CInterface, implements IRecordSizeEx
  67. {
  68. public:
  69. IMPLEMENT_IINTERFACE
  70. void init(IDistributedFile * df);
  71. virtual size32_t getRecordSize(const void *rec);
  72. virtual size32_t getRecordSize(unsigned maxLength, const void *rec);
  73. virtual size32_t getFixedSize() const;
  74. size32_t getRecordLength(size32_t maxLength, const void * start, bool includeTerminator);
  75. protected:
  76. StringMatcher matcher;
  77. size32_t unitSize;
  78. size32_t maxRecordSize;
  79. };
  80. class DirectCsvDiskDataSource : public PagedDataSource
  81. {
  82. public:
  83. DirectCsvDiskDataSource(IDistributedFile * _df, const char * _format);
  84. virtual bool init();
  85. virtual bool isIndex() { return false; }
  86. virtual bool fetchRowData(MemoryBuffer & out, __int64 offset);
  87. virtual bool loadBlock(__int64 startRow, offset_t startOffset);
  88. virtual bool getRow(MemoryBuffer & out, __int64 row);
  89. protected:
  90. void copyRow(MemoryBuffer & out, size32_t length, const void * data);
  91. protected:
  92. Owned<IDistributedFile> df;
  93. bool isUnicode;
  94. UtfReader::UtfFormat utfFormat;
  95. PhysicalFileInfo physical;
  96. CsvRecordSize recordSizer;
  97. size32_t readBlockSize;
  98. };
  99. class WorkunitDiskDataSource : public DirectDiskDataSource
  100. {
  101. public:
  102. WorkunitDiskDataSource(const char * _logicalName, IConstWUResult * _wuResult, const char * _wuid, const char * _username, const char * _password);
  103. virtual bool init();
  104. };
  105. class TranslatedDiskDataSource : public ADataSource
  106. {
  107. public:
  108. TranslatedDiskDataSource(const char * _logicalName, IHqlExpression * _diskRecord, const char * _cluster, const char * _username, const char * _password);
  109. ~TranslatedDiskDataSource();
  110. virtual bool init();
  111. virtual IFvDataSourceMetaData * queryMetaData() { return directSource->queryMetaData(); }
  112. virtual __int64 numRows(bool force = false) { return directSource->numRows(force); }
  113. virtual bool fetchRow(MemoryBuffer & out, __int64 offset) { return directSource->fetchRow(out, offset); }
  114. virtual bool fetchRawRow(MemoryBuffer & out, __int64 offset) { return directSource->fetchRawRow(out, offset); }
  115. virtual bool getRow(MemoryBuffer & out, __int64 row) { return directSource->getRow(out, row); }
  116. virtual bool getRawRow(MemoryBuffer & out, __int64 row) { return directSource->getRawRow(out, row); }
  117. virtual bool isIndex() { return false; }
  118. virtual void onClose() { openCount--; }
  119. virtual void onOpen() { openCount++; }
  120. protected:
  121. bool createHelperWU();
  122. bool compileHelperWU();
  123. protected:
  124. StringAttr helperWuid;
  125. StringAttr logicalName;
  126. StringAttr cluster;
  127. StringAttr username;
  128. StringAttr password;
  129. HqlExprAttr diskRecord;
  130. Owned<ADataSource> directSource;
  131. unsigned openCount;
  132. };
  133. class IndirectDiskDataSource : public DiskDataSource
  134. {
  135. public:
  136. IndirectDiskDataSource(const char * _logicalName, IHqlExpression * _diskRecord, const char * _cluster, const char * _username, const char * _password);
  137. ~IndirectDiskDataSource();
  138. virtual bool init();
  139. protected:
  140. bool createBrowseWU();
  141. virtual bool loadBlock(__int64 startRow, offset_t startOffset);
  142. protected:
  143. StringAttr browseWuid;
  144. StringAttr queue;
  145. StringAttr cluster;
  146. StringAttr username;
  147. StringAttr password;
  148. unsigned __int64 totalSize;
  149. };
  150. #endif