node_table_reader.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #pragma once
  2. #include "counting_raw_reader.h"
  3. #include <yt/cpp/mapreduce/interface/io.h>
  4. #include <library/cpp/yson/public.h>
  5. #include <util/stream/input.h>
  6. #include <util/generic/buffer.h>
  7. #include <util/system/event.h>
  8. #include <util/system/thread.h>
  9. #include <atomic>
  10. namespace NYT {
  11. class TRawTableReader;
  12. class TRowBuilder;
  13. ////////////////////////////////////////////////////////////////////////////////
  14. struct TRowElement
  15. {
  16. TNode Node;
  17. size_t Size = 0;
  18. void Reset()
  19. {
  20. Node = TNode();
  21. Size = 0;
  22. }
  23. };
  24. ////////////////////////////////////////////////////////////////////////////////
  25. class TNodeTableReader
  26. : public INodeReaderImpl
  27. {
  28. public:
  29. explicit TNodeTableReader(::TIntrusivePtr<TRawTableReader> input);
  30. ~TNodeTableReader() override;
  31. const TNode& GetRow() const override;
  32. void MoveRow(TNode* result) override;
  33. bool IsValid() const override;
  34. void Next() override;
  35. ui32 GetTableIndex() const override;
  36. ui32 GetRangeIndex() const override;
  37. ui64 GetRowIndex() const override;
  38. i64 GetTabletIndex() const override;
  39. void NextKey() override;
  40. TMaybe<size_t> GetReadByteCount() const override;
  41. bool IsEndOfStream() const override;
  42. bool IsRawReaderExhausted() const override;
  43. private:
  44. void NextImpl();
  45. void OnStreamError(std::exception_ptr exception, TString error);
  46. void CheckValidity() const;
  47. void PrepareParsing();
  48. void ParseListFragmentItem();
  49. void ParseFirstListFragmentItem();
  50. private:
  51. NDetail::TCountingRawTableReader Input_;
  52. bool Valid_ = true;
  53. bool Finished_ = false;
  54. ui32 TableIndex_ = 0;
  55. TMaybe<ui64> RowIndex_;
  56. TMaybe<ui32> RangeIndex_;
  57. ui32 RangeIndexShift_ = 0;
  58. TMaybe<i64> TabletIndex_;
  59. bool IsEndOfStream_ = false;
  60. bool AtStart_ = true;
  61. TMaybe<TRowElement> Row_;
  62. TMaybe<TRowElement> NextRow_;
  63. THolder<TRowBuilder> Builder_;
  64. THolder<::NYson::TYsonListParser> Parser_;
  65. std::exception_ptr Exception_;
  66. bool NeedParseFirst_ = true;
  67. bool IsLast_ = false;
  68. };
  69. ////////////////////////////////////////////////////////////////////////////////
  70. } // namespace NYT