Coverage Report

Created: 2026-10-29 18:51

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format_v2/table/es_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 <functional>
21
#include <map>
22
#include <memory>
23
#include <string>
24
#include <vector>
25
26
#include "format_v2/file_reader.h"
27
#include "format_v2/table_reader.h"
28
29
namespace doris {
30
class ScrollParser;
31
class SlotDescriptor;
32
} // namespace doris
33
34
namespace doris::format::es {
35
36
// The transport boundary allows reader tests to use real ES responses without a running server.
37
class EsScrollStream {
38
public:
39
23
    virtual ~EsScrollStream() = default;
40
    virtual Status open() = 0;
41
    virtual Status next(bool* eof, std::unique_ptr<ScrollParser>& parser) = 0;
42
    virtual Status close() = 0;
43
};
44
using EsScrollStreamFactory = std::function<std::unique_ptr<EsScrollStream>(
45
        const std::string&, const std::map<std::string, std::string>&, bool)>;
46
47
class EsFileReader final : public FileReader {
48
public:
49
    EsFileReader(std::shared_ptr<io::FileSystemProperties>& system_properties,
50
                 std::unique_ptr<io::FileDescription>& file_description,
51
                 std::shared_ptr<io::IOContext> io_ctx, RuntimeProfile* profile,
52
                 TFileRangeDesc range, const TFileScanRangeParams& params,
53
                 std::vector<SlotDescriptor*> file_slot_descs,
54
                 EsScrollStreamFactory stream_factory = {});
55
    ~EsFileReader() override;
56
57
    Status init(RuntimeState* state) override;
58
    Status get_schema(std::vector<ColumnDefinition>* schema) const override;
59
    std::unique_ptr<TableColumnMapper> create_column_mapper(
60
            TableColumnMapperOptions options) const override;
61
    void set_batch_size(size_t batch_size) override;
62
    Status open(std::shared_ptr<FileScanRequest> request) override;
63
    Status get_block(Block* block, size_t* rows, bool* eof) override;
64
    Status close() override;
65
66
private:
67
    void _init_profile() override;
68
    Status _open_stream();
69
    Status _next_page();
70
    Status _read_block(Block* block, size_t* rows, bool* eof);
71
72
    const TFileRangeDesc _range;
73
    const TFileScanRangeParams& _params;
74
    const std::vector<SlotDescriptor*> _file_slots;
75
    EsScrollStreamFactory _stream_factory;
76
    RuntimeState* _state = nullptr;
77
    size_t _batch_size = 1024;
78
    std::unique_ptr<EsScrollStream> _stream;
79
    std::unique_ptr<ScrollParser> _parser;
80
    std::vector<SlotDescriptor*> _read_slots;
81
    std::vector<size_t> _read_positions;
82
    std::map<std::string, std::string> _docvalue_context;
83
    size_t _page_rows_remaining = 0;
84
    bool _source_eof = false;
85
    RuntimeProfile::Counter* _total_time = nullptr;
86
    RuntimeProfile::Counter* _read_time = nullptr;
87
    RuntimeProfile::Counter* _materialize_time = nullptr;
88
    RuntimeProfile::Counter* _filter_time = nullptr;
89
    RuntimeProfile::Counter* _io_time = nullptr;
90
    RuntimeProfile::Counter* _batches_read = nullptr;
91
    RuntimeProfile::Counter* _rows_read = nullptr;
92
};
93
94
class EsReader final : public TableReader {
95
public:
96
    explicit EsReader(EsScrollStreamFactory stream_factory = {});
97
    Status init(TableReadOptions&& options) override;
98
    Status prepare_split(const SplitReadOptions& options) override;
99
100
protected:
101
    Status create_file_reader(std::unique_ptr<FileReader>* reader) override;
102
103
private:
104
    EsScrollStreamFactory _stream_factory;
105
};
106
107
} // namespace doris::format::es