Coverage Report

Created: 2026-03-15 22:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/information_schema/schema_schemata_scanner.cpp
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
#include "information_schema/schema_schemata_scanner.h"
19
20
#include <gen_cpp/Descriptors_types.h>
21
#include <gen_cpp/FrontendService_types.h>
22
23
#include <string>
24
25
#include "core/data_type/define_primitive_type.h"
26
#include "core/string_ref.h"
27
#include "information_schema/schema_helper.h"
28
#include "runtime/runtime_profile.h"
29
30
namespace doris {
31
class RuntimeState;
32
class Block;
33
34
std::vector<SchemaScanner::ColumnDesc> SchemaSchemataScanner::_s_columns = {
35
        //   name,       type,          size
36
        {"CATALOG_NAME", TYPE_VARCHAR, sizeof(StringRef), true},
37
        {"SCHEMA_NAME", TYPE_VARCHAR, sizeof(StringRef), false},
38
        {"DEFAULT_CHARACTER_SET_NAME", TYPE_VARCHAR, sizeof(StringRef), false},
39
        {"DEFAULT_COLLATION_NAME", TYPE_VARCHAR, sizeof(StringRef), false},
40
        {"SQL_PATH", TYPE_VARCHAR, sizeof(StringRef), true},
41
        {"DEFAULT_ENCRYPTION", TYPE_VARCHAR, sizeof(StringRef), true},
42
};
43
44
SchemaSchemataScanner::SchemaSchemataScanner()
45
0
        : SchemaScanner(_s_columns, TSchemaTableType::SCH_SCHEMATA) {}
46
47
0
SchemaSchemataScanner::~SchemaSchemataScanner() = default;
48
49
0
Status SchemaSchemataScanner::start(RuntimeState* state) {
50
0
    SCOPED_TIMER(_get_db_timer);
51
0
    if (!_is_init) {
52
0
        return Status::InternalError("used before initial.");
53
0
    }
54
0
    TGetDbsParams db_params;
55
0
    if (nullptr != _param->common_param->wild) {
56
0
        db_params.__set_pattern(*(_param->common_param->wild));
57
0
    }
58
0
    if (nullptr != _param->common_param->catalog) {
59
0
        db_params.__set_catalog(*(_param->common_param->catalog));
60
0
    }
61
0
    if (nullptr != _param->common_param->current_user_ident) {
62
0
        db_params.__set_current_user_ident(*(_param->common_param->current_user_ident));
63
0
    } else {
64
0
        if (nullptr != _param->common_param->user) {
65
0
            db_params.__set_user(*(_param->common_param->user));
66
0
        }
67
0
        if (nullptr != _param->common_param->user_ip) {
68
0
            db_params.__set_user_ip(*(_param->common_param->user_ip));
69
0
        }
70
0
    }
71
72
0
    if (nullptr != _param->common_param->ip && 0 != _param->common_param->port) {
73
0
        RETURN_IF_ERROR(SchemaHelper::get_db_names(
74
0
                *(_param->common_param->ip), _param->common_param->port, db_params, &_db_result));
75
0
    } else {
76
0
        return Status::InternalError("IP or port doesn't exists");
77
0
    }
78
79
0
    return Status::OK();
80
0
}
81
82
0
Status SchemaSchemataScanner::get_next_block_internal(Block* block, bool* eos) {
83
0
    if (!_is_init) {
84
0
        return Status::InternalError("Used before Initialized.");
85
0
    }
86
0
    if (nullptr == block || nullptr == eos) {
87
0
        return Status::InternalError("input pointer is nullptr.");
88
0
    }
89
90
0
    *eos = true;
91
0
    if (!_db_result.dbs.size()) {
92
0
        return Status::OK();
93
0
    }
94
0
    return _fill_block_impl(block);
95
0
}
96
97
0
Status SchemaSchemataScanner::_fill_block_impl(Block* block) {
98
0
    SCOPED_TIMER(_fill_block_timer);
99
0
    auto dbs_num = _db_result.dbs.size();
100
0
    std::vector<void*> null_datas(dbs_num, nullptr);
101
0
    std::vector<void*> datas(dbs_num);
102
103
    // catalog
104
0
    {
105
0
        if (!_db_result.__isset.catalogs) {
106
0
            RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, null_datas));
107
0
        } else {
108
0
            std::vector<StringRef> strs(dbs_num);
109
0
            for (int i = 0; i < dbs_num; ++i) {
110
0
                strs[i] = StringRef(_db_result.catalogs[i].c_str(), _db_result.catalogs[i].size());
111
0
                datas[i] = strs.data() + i;
112
0
            }
113
0
            RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, datas));
114
0
        }
115
0
    }
116
    // schema
117
0
    {
118
0
        std::vector<std::string> db_names(dbs_num);
119
0
        std::vector<StringRef> strs(dbs_num);
120
0
        for (int i = 0; i < dbs_num; ++i) {
121
0
            db_names[i] = SchemaHelper::extract_db_name(_db_result.dbs[i]);
122
0
            strs[i] = StringRef(db_names[i].c_str(), db_names[i].size());
123
0
            datas[i] = strs.data() + i;
124
0
        }
125
0
        RETURN_IF_ERROR(fill_dest_column_for_range(block, 1, datas));
126
0
    }
127
    // DEFAULT_CHARACTER_SET_NAME
128
0
    {
129
0
        std::string src = "utf8mb4";
130
0
        StringRef str = StringRef(src.c_str(), src.size());
131
0
        for (int i = 0; i < dbs_num; ++i) {
132
0
            datas[i] = &str;
133
0
        }
134
0
        RETURN_IF_ERROR(fill_dest_column_for_range(block, 2, datas));
135
0
    }
136
    // DEFAULT_COLLATION_NAME
137
0
    {
138
0
        std::string src = "utf8mb4_0900_bin";
139
0
        StringRef str = StringRef(src.c_str(), src.size());
140
0
        for (int i = 0; i < dbs_num; ++i) {
141
0
            datas[i] = &str;
142
0
        }
143
0
        RETURN_IF_ERROR(fill_dest_column_for_range(block, 3, datas));
144
0
    }
145
    // SQL_PATH
146
0
    { RETURN_IF_ERROR(fill_dest_column_for_range(block, 4, null_datas)); }
147
148
    // DEFAULT_ENCRYPTION
149
0
    {
150
0
        std::string src = "NO";
151
0
        StringRef str = StringRef(src.c_str(), src.size());
152
0
        for (int i = 0; i < dbs_num; ++i) {
153
0
            datas[i] = &str;
154
0
        }
155
0
        RETURN_IF_ERROR(fill_dest_column_for_range(block, 5, datas));
156
0
    }
157
0
    return Status::OK();
158
0
}
159
160
} // namespace doris