Coverage Report

Created: 2026-04-14 13:42

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/native/native_reader.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <gen_cpp/PlanNodes_types.h>
21
22
#include <cstddef>
23
#include <string>
24
#include <unordered_map>
25
#include <unordered_set>
26
27
#include "common/status.h"
28
#include "format/generic_reader.h"
29
#include "io/fs/file_reader_writer_fwd.h"
30
31
namespace doris {
32
class RuntimeProfile;
33
class RuntimeState;
34
35
namespace io {
36
struct IOContext;
37
} // namespace io
38
} // namespace doris
39
40
namespace doris {
41
class Block;
42
43
// Doris Native format reader.
44
// it will read a sequence of Blocks encoded in Doris Native binary format.
45
//
46
// NOTE: current implementation is just a skeleton and will be filled step by step.
47
class NativeReader : public GenericReader {
48
public:
49
    ENABLE_FACTORY_CREATOR(NativeReader);
50
51
    NativeReader(RuntimeProfile* profile, const TFileScanRangeParams& params,
52
                 const TFileRangeDesc& range, io::IOContext* io_ctx, RuntimeState* state);
53
54
    ~NativeReader() override;
55
56
    // Initialize underlying file reader and any format specific state.
57
    Status init_reader();
58
59
    Status get_next_block(Block* block, size_t* read_rows, bool* eof) override;
60
61
    Status get_columns(std::unordered_map<std::string, DataTypePtr>* name_to_type,
62
                       std::unordered_set<std::string>* missing_cols) override;
63
64
    Status init_schema_reader() override;
65
66
    Status get_parsed_schema(std::vector<std::string>* col_names,
67
                             std::vector<DataTypePtr>* col_types) override;
68
69
    Status close() override;
70
71
0
    bool count_read_rows() override { return true; }
72
73
protected:
74
0
    void _collect_profile_before_close() override {}
75
76
private:
77
    RuntimeProfile* _profile = nullptr;
78
    const TFileScanRangeParams& _scan_params;
79
    const TFileRangeDesc& _scan_range;
80
81
    io::FileReaderSPtr _file_reader;
82
    io::IOContext* _io_ctx = nullptr;
83
    RuntimeState* _state = nullptr;
84
85
    bool _eof = false;
86
87
    // Current read offset in the underlying file.
88
    int64_t _current_offset = 0;
89
    int64_t _file_size = 0;
90
91
    // Cached schema information from the first PBlock.
92
    bool _schema_inited = false;
93
    std::vector<std::string> _schema_col_names;
94
    std::vector<DataTypePtr> _schema_col_types;
95
96
    // Cached first block (serialized) to allow schema probing before data scan.
97
    std::string _first_block_buf;
98
    bool _first_block_loaded = false;
99
    bool _first_block_consumed = false;
100
101
    Status _read_next_pblock(std::string* buff, bool* eof);
102
    Status _init_schema_from_pblock(const PBlock& pblock);
103
};
104
105
} // namespace doris