fvidxsource.ipp 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 FVIDXSOURCE_IPP
  14. #define FVIDXSOURCE_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. #include "rtlkey.hpp"
  23. #include "jhtree.hpp"
  24. //---------------------------------------------------------------------------
  25. //An initial simple implementation
  26. class IndexPageCache
  27. {
  28. public:
  29. IndexPageCache();
  30. void addRow(__int64 row, size32_t len, const void * data);
  31. bool getRow(__int64 row, size32_t & len, const void * & data);
  32. inline unsigned numRowsCached() { return offsets.ordinality()-1; }
  33. protected:
  34. MemoryBuffer saved;
  35. UInt64Array offsets;
  36. __int64 firstRow;
  37. unsigned __int64 offsetDelta;
  38. };
  39. class IndexDataSource : public FVDataSource
  40. {
  41. public:
  42. IndexDataSource(const char * _logicalName, IHqlExpression * _indexRecord, const char* _username, const char* _password);
  43. IndexDataSource(IndexDataSource * _other);
  44. virtual void applyFilter();
  45. virtual IFvDataSource * cloneForFilter();
  46. virtual __int64 numRows(bool force = false);
  47. virtual bool addFilter(unsigned offset, unsigned matchLen, unsigned len, const void * data);
  48. virtual bool init();
  49. virtual bool fetchRowData(MemoryBuffer & out, __int64 offset) { return false; }
  50. virtual bool getRowData(__int64 row, size32_t & length, const void * & data, unsigned __int64 & offset);
  51. virtual bool isIndex() { return true; }
  52. protected:
  53. inline unsigned fieldSize(unsigned column) { return keyedOffsets.item(column+1) - keyedOffsets.item(column); }
  54. bool getNextRow(MemoryBuffer & out, bool extractRow);
  55. void resetCursor();
  56. void translateKeyedValues(byte * row);
  57. protected:
  58. StringAttr logicalName;
  59. IArrayOf<IKeySegmentMonitor> segMonitors;
  60. IArrayOf<IStringSet> values;
  61. Owned<DataSourceMetaData> diskMeta;
  62. HqlExprAttr diskRecord;
  63. Owned<IRtlFieldTypeDeserializer> deserializer; // Must be destroyed after diskRecordMeta
  64. Owned<IOutputMetaData> diskRecordMeta;
  65. Owned<IDistributedFile> df;
  66. Linked<FVDataSource> original;
  67. unsigned __int64 totalRows = 0;
  68. unsigned __int64 nextRowToRead = 0;
  69. unsigned keyedSize = 0;
  70. UnsignedArray keyedOffsets;
  71. TypeInfoArray keyedTypes;
  72. Owned<IKeyIndex> tlk;
  73. Owned<IKeyManager> manager;
  74. Owned<IKeyIndex> curPart;
  75. int curPartIndex = 0;
  76. UnsignedArray matchingParts;
  77. unsigned numParts = 0;
  78. bool singlePart = false;
  79. bool filtered = false;
  80. bool isLocal = false;
  81. bool ignoreSkippedRows = false;
  82. IndexPageCache cache;
  83. };
  84. #endif