aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/providers/common/codec/arrow/yql_codec_buf_input_stream.h
blob: fce7742fb063aaa065bec7150a404791c52d25b5 (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
#include <yql/essentials/providers/common/codec/yql_codec_buf.h>

#include <arrow/io/interfaces.h>
#include <arrow/result.h>

namespace NYql {
namespace NCommon {

class TInputBufArrowInputStream : public arrow::io::InputStream {
public:
    explicit TInputBufArrowInputStream(TInputBuf& buffer, arrow::MemoryPool* pool)
        : Buffer_(buffer)
        , Pool_(pool)
    {
    }

    arrow::Result<int64_t> Read(int64_t bytesToRead, void* outBuffer) override;
    arrow::Result<std::shared_ptr<arrow::Buffer>> Read(int64_t nbytes) override;

    void Reset() {
        BytesRead_ = 0;
        EOSReached_ = false;
    }

    arrow::Status Close() override {
        return arrow::Status::OK();
    }

    arrow::Result<int64_t> Tell() const override {
        return BytesRead_;
    }

    bool closed() const override {
        return false;
    }

    bool EOSReached() const {
        return EOSReached_;
    }

private:
    TInputBuf& Buffer_;
    int64_t BytesRead_ = 0;
    bool EOSReached_ = false;

    arrow::MemoryPool* Pool_;
};

} // NCommon
} // NYql