aboutsummaryrefslogtreecommitdiffstats
path: root/yt/cpp/mapreduce/io/skiff_row_table_reader.h
blob: 1f623570bb95f81d9a5ebb74942305333697f223 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once

#include "counting_raw_reader.h"

#include <yt/cpp/mapreduce/client/skiff.h>

#include <yt/cpp/mapreduce/interface/io.h>

#include <yt/cpp/mapreduce/skiff/unchecked_parser.h>

#include <util/stream/buffered.h>

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

class TSkiffRowTableReader
    : public ISkiffRowReaderImpl
{
public:
    explicit TSkiffRowTableReader(
        ::TIntrusivePtr<TRawTableReader> input,
        const NSkiff::TSkiffSchemaPtr& schema,
        TVector<ISkiffRowSkipperPtr>&& skippers,
        NDetail::TCreateSkiffSchemaOptions&& options);

    ~TSkiffRowTableReader() override;

    void ReadRow(const ISkiffRowParserPtr& parser) override;

    bool IsValid() const override;
    void Next() override;
    ui32 GetTableIndex() const override;
    ui32 GetRangeIndex() const override;
    ui64 GetRowIndex() const override;
    void NextKey() override;
    TMaybe<size_t> GetReadByteCount() const override;
    bool IsEndOfStream() const override;
    bool IsRawReaderExhausted() const override;

private:
    bool Retry(const std::exception_ptr& error);
    void SkipRow();
    void CheckValidity() const;
    bool PrepareRetry(const std::exception_ptr& error);

private:
    NDetail::TCountingRawTableReader Input_;
    TBufferedInput BufferedInput_;
    std::optional<NSkiff::TCheckedInDebugSkiffParser> Parser_;
    TVector<ISkiffRowSkipperPtr> Skippers_;
    NDetail::TCreateSkiffSchemaOptions Options_;

    bool RowTaken_ = true;
    bool Valid_ = true;
    bool Finished_ = false;
    bool AfterKeySwitch_ = false;
    bool IsEndOfStream_ = false;

    TMaybe<ui64> RowIndex_;
    TMaybe<ui32> RangeIndex_;
    ui32 RangeIndexShift_ = 0;
    ui32 TableIndex_ = 0;
};

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT