Coverage Report

Created: 2026-03-15 18:01

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