lenval_table_reader.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #pragma once
  2. #include "counting_raw_reader.h"
  3. #include <yt/cpp/mapreduce/interface/io.h>
  4. namespace NYT {
  5. ////////////////////////////////////////////////////////////////////////////////
  6. class TLenvalTableReader
  7. {
  8. public:
  9. explicit TLenvalTableReader(::TIntrusivePtr<TRawTableReader> input);
  10. virtual ~TLenvalTableReader();
  11. protected:
  12. bool IsValid() const;
  13. void Next();
  14. ui32 GetTableIndex() const;
  15. ui32 GetRangeIndex() const;
  16. ui64 GetRowIndex() const;
  17. void NextKey();
  18. TMaybe<size_t> GetReadByteCount() const;
  19. bool IsEndOfStream() const;
  20. bool IsRawReaderExhausted() const;
  21. void CheckValidity() const;
  22. bool Retry(const std::exception_ptr& error);
  23. template <class T>
  24. bool ReadInteger(T* result, bool acceptEndOfStream = false)
  25. {
  26. size_t count = Input_.Load(result, sizeof(T));
  27. if (acceptEndOfStream && count == 0) {
  28. Finished_ = true;
  29. Valid_ = false;
  30. return false;
  31. }
  32. Y_ENSURE(count == sizeof(T), "Premature end of stream");
  33. return true;
  34. }
  35. virtual void SkipRow() = 0;
  36. protected:
  37. NDetail::TCountingRawTableReader Input_;
  38. bool Valid_ = true;
  39. bool Finished_ = false;
  40. ui32 TableIndex_ = 0;
  41. TMaybe<ui64> RowIndex_;
  42. TMaybe<ui32> RangeIndex_;
  43. ui32 RangeIndexShift_ = 0;
  44. TMaybe<ui64> TabletIndex_;
  45. bool IsEndOfStream_ = false;
  46. bool AtStart_ = true;
  47. bool RowTaken_ = true;
  48. ui32 Length_ = 0;
  49. private:
  50. bool PrepareRetry(const std::exception_ptr& error);
  51. };
  52. ////////////////////////////////////////////////////////////////////////////////
  53. } // namespace NYT