Coverage Report

Created: 2026-08-07 16:31

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/exec/schema_scanner.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/Data_types.h>
21
#include <gen_cpp/Descriptors_types.h>
22
23
#include <condition_variable>
24
#include <cstddef>
25
#include <cstdint>
26
#include <memory>
27
#include <set>
28
#include <string>
29
#include <vector>
30
31
#include "cctz/time_zone.h"
32
#include "common/factory_creator.h"
33
#include "common/status.h"
34
#include "runtime/define_primitive_type.h"
35
#include "util/runtime_profile.h"
36
37
namespace doris {
38
39
// forehead declare class, because jni function init in DorisServer.
40
41
class RuntimeState;
42
class ObjectPool;
43
class TUserIdentity;
44
45
namespace vectorized {
46
class Block;
47
}
48
49
namespace pipeline {
50
class Dependency;
51
}
52
53
struct SchemaScannerCommonParam {
54
    SchemaScannerCommonParam()
55
0
            : db(nullptr),
56
0
              table(nullptr),
57
0
              wild(nullptr),
58
0
              user(nullptr),
59
0
              user_ip(nullptr),
60
0
              current_user_ident(nullptr),
61
0
              frontend_conjuncts(nullptr),
62
0
              ip(nullptr),
63
0
              port(0),
64
0
              catalog(nullptr) {}
65
    const std::string* db = nullptr;
66
    const std::string* table = nullptr;
67
    const std::string* wild = nullptr;
68
    const std::string* user = nullptr;                 // deprecated
69
    const std::string* user_ip = nullptr;              // deprecated
70
    const TUserIdentity* current_user_ident = nullptr; // to replace the user and user ip
71
    const std::string* frontend_conjuncts = nullptr;   // frontend_conjuncts
72
    const std::string* ip = nullptr;                   // frontend ip
73
    int32_t port;                                      // frontend thrift port
74
    int64_t thread_id;
75
    const std::string* catalog = nullptr;
76
    std::set<TNetworkAddress> fe_addr_list;
77
    std::set<std::string> required_columns;
78
};
79
80
// scanner parameter from frontend
81
struct SchemaScannerParam {
82
    std::shared_ptr<SchemaScannerCommonParam> common_param;
83
    std::unique_ptr<RuntimeProfile> profile;
84
85
0
    SchemaScannerParam() : common_param(new SchemaScannerCommonParam()) {}
86
};
87
88
// virtual scanner for all schema table
89
class SchemaScanner {
90
public:
91
    struct ColumnDesc {
92
        const char* name = nullptr;
93
        PrimitiveType type;
94
        int size;
95
        bool is_null;
96
        /// Only set if type == TYPE_DECIMAL
97
        int precision = -1;
98
        /// Only set if type == TYPE_DECIMAL or DATETIMEV2
99
        int scale = -1;
100
    };
101
    SchemaScanner(const std::vector<ColumnDesc>& columns,
102
                  TSchemaTableType::type type = TSchemaTableType::SCH_INVALID);
103
    virtual ~SchemaScanner();
104
105
    // init object need information, schema etc.
106
    virtual Status init(RuntimeState* state, SchemaScannerParam* param, ObjectPool* pool);
107
    Status get_next_block(RuntimeState* state, vectorized::Block* block, bool* eos);
108
    // Start to work
109
    virtual Status start(RuntimeState* state);
110
    virtual Status get_next_block_internal(vectorized::Block* block, bool* eos) = 0;
111
3
    const std::vector<ColumnDesc>& get_column_desc() const { return _columns; }
112
    // factory function
113
    static std::unique_ptr<SchemaScanner> create(TSchemaTableType::type type);
114
0
    TSchemaTableType::type type() const { return _schema_table_type; }
115
0
    void set_dependency(std::shared_ptr<pipeline::Dependency> dep) { _dependency = dep; }
116
    Status get_next_block_async(RuntimeState* state);
117
118
protected:
119
    void _init_block(vectorized::Block* src_block);
120
    Status fill_dest_column_for_range(vectorized::Block* block, size_t pos,
121
                                      const std::vector<void*>& datas);
122
123
    Status insert_block_column(TCell cell, int col_index, vectorized::Block* block,
124
                               PrimitiveType type);
125
126
    // get dbname from catalogname.dbname
127
    // if full_name does not have catalog part, just return origin name.
128
    std::string get_db_from_full_name(const std::string& full_name);
129
130
    bool _is_init;
131
    // this is used for sub class
132
    SchemaScannerParam* _param = nullptr;
133
    // schema table's column desc
134
    std::vector<ColumnDesc> _columns;
135
136
    TSchemaTableType::type _schema_table_type;
137
138
    RuntimeProfile::Counter* _get_db_timer = nullptr;
139
    RuntimeProfile::Counter* _get_table_timer = nullptr;
140
    RuntimeProfile::Counter* _get_describe_timer = nullptr;
141
    RuntimeProfile::Counter* _fill_block_timer = nullptr;
142
143
    std::shared_ptr<pipeline::Dependency> _dependency = nullptr;
144
145
    std::unique_ptr<vectorized::Block> _data_block;
146
    AtomicStatus _scanner_status;
147
    std::atomic<bool> _eos = false;
148
    std::atomic<bool> _opened = false;
149
    std::atomic<bool> _async_thread_running = false;
150
    std::string _timezone;
151
    cctz::time_zone _timezone_obj;
152
};
153
154
} // namespace doris