Coverage Report

Created: 2026-10-30 10:45

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 <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 "core/data_type/define_primitive_type.h"
35
#include "runtime/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
class Block;
46
47
class Dependency;
48
49
struct SchemaScannerCommonParam {
50
    SchemaScannerCommonParam()
51
8
            : db(nullptr),
52
8
              table(nullptr),
53
8
              wild(nullptr),
54
8
              user(nullptr),
55
8
              user_ip(nullptr),
56
8
              current_user_ident(nullptr),
57
8
              frontend_conjuncts(nullptr),
58
8
              ip(nullptr),
59
8
              port(0),
60
8
              catalog(nullptr) {}
61
    const std::string* db = nullptr;
62
    const std::string* table = nullptr;
63
    const std::string* wild = nullptr;
64
    const std::string* user = nullptr;                 // deprecated
65
    const std::string* user_ip = nullptr;              // deprecated
66
    const TUserIdentity* current_user_ident = nullptr; // to replace the user and user ip
67
    const std::string* frontend_conjuncts = nullptr;   // frontend_conjuncts
68
    const std::string* ip = nullptr;                   // frontend ip
69
    int32_t port;                                      // frontend thrift port
70
    int64_t thread_id;
71
    // Whether the session that planned this scan asked for MySQL compatible key metadata.
72
    bool mysql_compatible_index_metadata = false;
73
    const std::string* catalog = nullptr;
74
    std::set<TNetworkAddress> fe_addr_list;
75
    std::set<std::string> required_columns;
76
    // SU narrowing: the session's active role subset (TSchemaScanNode.current_roles), forwarded
77
    // on the BE->FE metadata RPCs so they narrow name visibility. Empty = not narrowed.
78
    std::set<std::string> current_roles;
79
};
80
81
// scanner parameter from frontend
82
struct SchemaScannerParam {
83
    std::shared_ptr<SchemaScannerCommonParam> common_param;
84
    std::unique_ptr<RuntimeProfile> profile;
85
86
8
    SchemaScannerParam() : common_param(new SchemaScannerCommonParam()) {}
87
};
88
89
// virtual scanner for all schema table
90
class SchemaScanner {
91
public:
92
    struct ColumnDesc {
93
        const char* name = nullptr;
94
        PrimitiveType type;
95
        int size;
96
        bool is_null;
97
        /// Only set if type == TYPE_DECIMAL
98
        int precision = -1;
99
        /// Only set if type == TYPE_DECIMAL or DATETIMEV2
100
        int scale = -1;
101
    };
102
    SchemaScanner(const std::vector<ColumnDesc>& columns,
103
                  TSchemaTableType::type type = TSchemaTableType::SCH_INVALID);
104
    virtual ~SchemaScanner();
105
106
    // init object need information, schema etc.
107
    virtual Status init(RuntimeState* state, SchemaScannerParam* param, ObjectPool* pool);
108
    Status get_next_block(RuntimeState* state, Block* block, bool* eos);
109
    // Start to work
110
    virtual Status start(RuntimeState* state);
111
    virtual Status get_next_block_internal(Block* block, bool* eos) = 0;
112
30
    const std::vector<ColumnDesc>& get_column_desc() const { return _columns; }
113
    // factory function
114
    static std::unique_ptr<SchemaScanner> create(TSchemaTableType::type type);
115
    TSchemaTableType::type type() const { return _schema_table_type; }
116
0
    void set_dependency(std::shared_ptr<Dependency> dep) { _dependency = dep; }
117
    Status get_next_block_async(RuntimeState* state);
118
119
protected:
120
    void _init_block(Block* src_block);
121
    Status fill_dest_column_for_range(Block* block, size_t pos, const std::vector<void*>& datas);
122
123
    Status insert_block_column(TCell cell, int col_index, Block* block, PrimitiveType type);
124
125
    // get dbname from catalogname.dbname
126
    // if full_name does not have catalog part, just return origin name.
127
    std::string get_db_from_full_name(const std::string& full_name);
128
129
    bool _is_init;
130
    // this is used for sub class
131
    SchemaScannerParam* _param = nullptr;
132
    // schema table's column desc
133
    std::vector<ColumnDesc> _columns;
134
135
    TSchemaTableType::type _schema_table_type;
136
137
    RuntimeProfile::Counter* _get_db_timer = nullptr;
138
    RuntimeProfile::Counter* _get_table_timer = nullptr;
139
    RuntimeProfile::Counter* _get_describe_timer = nullptr;
140
    RuntimeProfile::Counter* _fill_block_timer = nullptr;
141
142
    std::shared_ptr<Dependency> _dependency = nullptr;
143
144
    std::unique_ptr<Block> _data_block;
145
    AtomicStatus _scanner_status;
146
    std::atomic<bool> _eos = false;
147
    std::atomic<bool> _opened = false;
148
    std::atomic<bool> _async_thread_running = false;
149
    std::string _timezone;
150
    cctz::time_zone _timezone_obj;
151
};
152
153
} // namespace doris