job_writer.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #pragma once
  2. #include <yt/cpp/mapreduce/interface/io.h>
  3. #include <util/generic/vector.h>
  4. #include <util/generic/ptr.h>
  5. #include <util/stream/file.h>
  6. #include <util/stream/buffered.h>
  7. namespace NYT {
  8. ////////////////////////////////////////////////////////////////////////////////
  9. namespace NDetail {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. class TJobWriterStream
  12. {
  13. public:
  14. explicit TJobWriterStream(int fd);
  15. explicit TJobWriterStream(const TFile& file);
  16. ~TJobWriterStream() = default;
  17. public:
  18. static constexpr size_t BufferSize = 1 << 20;
  19. TFile FDFile;
  20. TUnbufferedFileOutput FDOutput;
  21. TBufferedOutput BufferedOutput;
  22. };
  23. ////////////////////////////////////////////////////////////////////////////////
  24. } // namespace NDetail
  25. ////////////////////////////////////////////////////////////////////////////////
  26. class TJobWriter
  27. : public IProxyOutput
  28. {
  29. public:
  30. explicit TJobWriter(size_t outputTableCount);
  31. explicit TJobWriter(const TVector<TFile>& fileList);
  32. size_t GetBufferMemoryUsage() const override;
  33. size_t GetStreamCount() const override;
  34. IOutputStream* GetStream(size_t tableIndex) const override;
  35. void OnRowFinished(size_t tableIndex) override;
  36. private:
  37. TVector<std::unique_ptr<NDetail::TJobWriterStream>> Streams_;
  38. };
  39. ////////////////////////////////////////////////////////////////////////////////
  40. class TSingleStreamJobWriter
  41. : public IProxyOutput
  42. {
  43. public:
  44. explicit TSingleStreamJobWriter(size_t tableIndex);
  45. size_t GetBufferMemoryUsage() const override;
  46. size_t GetStreamCount() const override;
  47. IOutputStream* GetStream(size_t tableIndex) const override;
  48. void OnRowFinished(size_t tableIndex) override;
  49. private:
  50. const size_t TableIndex_;
  51. std::unique_ptr<NDetail::TJobWriterStream> Stream_;
  52. };
  53. ////////////////////////////////////////////////////////////////////////////////
  54. } // namespace NYT