Coverage Report

Created: 2026-03-15 20:53

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/information_schema/schema_charsets_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_charsets_scanner.h"
19
20
#include <gen_cpp/Descriptors_types.h>
21
#include <string.h>
22
23
#include "common/status.h"
24
#include "core/data_type/define_primitive_type.h"
25
#include "core/string_ref.h"
26
#include "runtime/runtime_profile.h"
27
28
namespace doris {
29
class Block;
30
31
std::vector<SchemaScanner::ColumnDesc> SchemaCharsetsScanner::_s_css_columns = {
32
        //   name,       type,          size
33
        {"CHARACTER_SET_NAME", TYPE_VARCHAR, sizeof(StringRef), false},
34
        {"DEFAULT_COLLATE_NAME", TYPE_VARCHAR, sizeof(StringRef), false},
35
        {"DESCRIPTION", TYPE_VARCHAR, sizeof(StringRef), false},
36
        {"MAXLEN", TYPE_BIGINT, sizeof(int64_t), false},
37
};
38
39
SchemaCharsetsScanner::CharsetStruct SchemaCharsetsScanner::_s_charsets[] = {
40
        {"utf8mb4", "utf8mb4_0900_bin", "UTF-8 Unicode", 4},
41
        {nullptr, nullptr, nullptr, 0},
42
};
43
44
SchemaCharsetsScanner::SchemaCharsetsScanner()
45
0
        : SchemaScanner(_s_css_columns, TSchemaTableType::SCH_CHARSETS) {}
46
47
0
SchemaCharsetsScanner::~SchemaCharsetsScanner() {}
48
49
0
Status SchemaCharsetsScanner::get_next_block_internal(Block* block, bool* eos) {
50
0
    if (!_is_init) {
51
0
        return Status::InternalError("call this before initial.");
52
0
    }
53
0
    if (nullptr == block || nullptr == eos) {
54
0
        return Status::InternalError("invalid parameter.");
55
0
    }
56
0
    *eos = true;
57
0
    return _fill_block_impl(block);
58
0
}
59
60
0
Status SchemaCharsetsScanner::_fill_block_impl(Block* block) {
61
0
    SCOPED_TIMER(_fill_block_timer);
62
0
    auto row_num = 0;
63
0
    while (nullptr != _s_charsets[row_num].charset) {
64
0
        ++row_num;
65
0
    }
66
0
    std::vector<void*> datas(row_num);
67
68
    // variables names
69
0
    {
70
0
        std::vector<StringRef> strs(row_num);
71
0
        for (int i = 0; i < row_num; ++i) {
72
0
            strs[i] = StringRef(_s_charsets[i].charset, strlen(_s_charsets[i].charset));
73
0
            datas[i] = strs.data() + i;
74
0
        }
75
0
        RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, datas));
76
0
    }
77
    // DEFAULT_COLLATE_NAME
78
0
    {
79
0
        std::vector<StringRef> strs(row_num);
80
0
        for (int i = 0; i < row_num; ++i) {
81
0
            strs[i] = StringRef(_s_charsets[i].default_collation,
82
0
                                strlen(_s_charsets[i].default_collation));
83
0
            datas[i] = strs.data() + i;
84
0
        }
85
0
        RETURN_IF_ERROR(fill_dest_column_for_range(block, 1, datas));
86
0
    }
87
    // DESCRIPTION
88
0
    {
89
0
        std::vector<StringRef> strs(row_num);
90
0
        for (int i = 0; i < row_num; ++i) {
91
0
            strs[i] = StringRef(_s_charsets[i].description, strlen(_s_charsets[i].description));
92
0
            datas[i] = strs.data() + i;
93
0
        }
94
0
        RETURN_IF_ERROR(fill_dest_column_for_range(block, 2, datas));
95
0
    }
96
    // maxlen
97
0
    {
98
0
        std::vector<int64_t> srcs(row_num);
99
0
        for (int i = 0; i < row_num; ++i) {
100
0
            srcs[i] = _s_charsets[i].maxlen;
101
0
            datas[i] = srcs.data() + i;
102
0
        }
103
0
        RETURN_IF_ERROR(fill_dest_column_for_range(block, 3, datas));
104
0
    }
105
0
    return Status::OK();
106
0
}
107
108
} // namespace doris