fvdisksource.ipp 5.8 KB

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