#pragma once /// /// @file yt/cpp/mapreduce/interface/skiff_row.h /// Header containing interfaces that you need to define for using TSkiffRowTableReader /// What you need to do for your struct type TMyType: /// 1. Write `true` specialization TIsSkiffRow; /// 2. Write specialization GetSkiffSchema(); /// 3. Write your own parser derived from ISkiffRowParser and write specialization GetSkiffParser() which returns this parser. #include "fwd.h" #include #include #include #include namespace NYT { //////////////////////////////////////////////////////////////////////////////// //! Need to write `true_type` specialization for your row type `T`. /// And implement two functions: `GetSkiffSchema` and `CreateSkiffParser`. /// /// Example: /// /// template <> /// struct TIsSkiffRow /// : std::true_type /// { }; /// template struct TIsSkiffRow : std::false_type { }; //////////////////////////////////////////////////////////////////////////////// //! Return skiff schema for row type `T`. /// Need to write its specialization. template NSkiff::TSkiffSchemaPtr GetSkiffSchema(const TMaybe& /*hints*/) { static_assert(TDependentFalse, "Unimplemented `GetSkiffSchema` method"); } //////////////////////////////////////////////////////////////////////////////// //! Allow to parse rows as user's structs from stream (TCheckedInDebugSkiffParser). /// Need to write derived class for your own row type. /// /// Example: /// /// class TMySkiffRowParser : public ISkiffRowParser /// { /// public: /// TMySkiffRowParser(TMySkiffRow* row) /// : Row_(row) /// {} /// /// void Parse(NSkiff::TCheckedInDebugSkiffParser* parser) /// . { /// Row_->SomeInt64Field = parser->ParseInt64(); /// } /// /// private: /// TMySkiffRow* Row_; /// } /// class ISkiffRowParser : public TThrRefBase { public: //! Read one row from parser virtual void Parse(NSkiff::TCheckedInDebugSkiffParser* /*parser*/) = 0; }; //! Creates a parser for row type `T`. template ISkiffRowParserPtr CreateSkiffParser(T* /*row*/, const TMaybe& /*hints*/) { static_assert(TDependentFalse, "Unimplemented `CreateSkiffParser` function"); } //////////////////////////////////////////////////////////////////////////////// //! Allow to skip row content without getting row. /// By default row will be parsed using your parser derived from ISkiffRowParser. /// If you want, you can write more optimal skipper, but it isn't required. class ISkiffRowSkipper : public TThrRefBase { public: virtual void SkipRow(NSkiff::TCheckedInDebugSkiffParser* /*parser*/) = 0; }; //! Default ISkiffRowSkipper implementation. template class TSkiffRowSkipper : public ISkiffRowSkipper { public: explicit TSkiffRowSkipper(const TMaybe& hints) : Parser_(CreateSkiffParser(&Row_, hints)) { } void SkipRow(NSkiff::TCheckedInDebugSkiffParser* parser) { Parser_->Parse(parser); } private: T Row_; ISkiffRowParserPtr Parser_; }; //! Creates a skipper for row type 'T'. /// You don't need to write its specialization. template ISkiffRowSkipperPtr CreateSkiffSkipper(const TMaybe& hints) { return ::MakeIntrusive>(hints); } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT