be/src/information_schema/schema_collations_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_collations_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> SchemaCollationsScanner::_s_cols_columns = { |
32 | | // name, type, size |
33 | | {"COLLATION_NAME", TYPE_VARCHAR, sizeof(StringRef), false}, |
34 | | {"CHARACTER_SET_NAME", TYPE_VARCHAR, sizeof(StringRef), false}, |
35 | | {"ID", TYPE_BIGINT, sizeof(int64_t), false}, |
36 | | {"IS_DEFAULT", TYPE_VARCHAR, sizeof(StringRef), false}, |
37 | | {"IS_COMPILED", TYPE_VARCHAR, sizeof(StringRef), false}, |
38 | | {"SORTLEN", TYPE_BIGINT, sizeof(int64_t), false}, |
39 | | }; |
40 | | |
41 | | SchemaCollationsScanner::CollationStruct SchemaCollationsScanner::_s_collations[] = { |
42 | | {"utf8mb4_0900_bin", "utf8mb4", 309, "Yes", "Yes", 1}, |
43 | | {nullptr, nullptr, 0, nullptr, nullptr, 0}, |
44 | | }; |
45 | | |
46 | | SchemaCollationsScanner::SchemaCollationsScanner() |
47 | 0 | : SchemaScanner(_s_cols_columns, TSchemaTableType::SCH_COLLATIONS) {} |
48 | | |
49 | 0 | SchemaCollationsScanner::~SchemaCollationsScanner() {} |
50 | | |
51 | 0 | Status SchemaCollationsScanner::get_next_block_internal(Block* block, bool* eos) { |
52 | 0 | if (!_is_init) { |
53 | 0 | return Status::InternalError("call this before initial."); |
54 | 0 | } |
55 | 0 | if (nullptr == block || nullptr == eos) { |
56 | 0 | return Status::InternalError("invalid parameter."); |
57 | 0 | } |
58 | | |
59 | 0 | *eos = true; |
60 | 0 | return _fill_block_impl(block); |
61 | 0 | } |
62 | | |
63 | 0 | Status SchemaCollationsScanner::_fill_block_impl(Block* block) { |
64 | 0 | SCOPED_TIMER(_fill_block_timer); |
65 | 0 | auto row_num = 0; |
66 | 0 | while (nullptr != _s_collations[row_num].name) { |
67 | 0 | ++row_num; |
68 | 0 | } |
69 | 0 | std::vector<void*> datas(row_num); |
70 | | |
71 | | // COLLATION_NAME |
72 | 0 | { |
73 | 0 | std::vector<StringRef> strs(row_num); |
74 | 0 | for (int i = 0; i < row_num; ++i) { |
75 | 0 | strs[i] = StringRef(_s_collations[i].name, strlen(_s_collations[i].name)); |
76 | 0 | datas[i] = strs.data() + i; |
77 | 0 | } |
78 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 0, datas)); |
79 | 0 | } |
80 | | // charset |
81 | 0 | { |
82 | 0 | std::vector<StringRef> strs(row_num); |
83 | 0 | for (int i = 0; i < row_num; ++i) { |
84 | 0 | strs[i] = StringRef(_s_collations[i].charset, strlen(_s_collations[i].charset)); |
85 | 0 | datas[i] = strs.data() + i; |
86 | 0 | } |
87 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 1, datas)); |
88 | 0 | } |
89 | | // id |
90 | 0 | { |
91 | 0 | std::vector<int64_t> srcs(row_num); |
92 | 0 | for (int i = 0; i < row_num; ++i) { |
93 | 0 | srcs[i] = _s_collations[i].id; |
94 | 0 | datas[i] = srcs.data() + i; |
95 | 0 | } |
96 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 2, datas)); |
97 | 0 | } |
98 | | // is_default |
99 | 0 | { |
100 | 0 | std::vector<StringRef> strs(row_num); |
101 | 0 | for (int i = 0; i < row_num; ++i) { |
102 | 0 | strs[i] = StringRef(_s_collations[i].is_default, strlen(_s_collations[i].is_default)); |
103 | 0 | datas[i] = strs.data() + i; |
104 | 0 | } |
105 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 3, datas)); |
106 | 0 | } |
107 | | // IS_COMPILED |
108 | 0 | { |
109 | 0 | std::vector<StringRef> strs(row_num); |
110 | 0 | for (int i = 0; i < row_num; ++i) { |
111 | 0 | strs[i] = StringRef(_s_collations[i].is_compile, strlen(_s_collations[i].is_compile)); |
112 | 0 | datas[i] = strs.data() + i; |
113 | 0 | } |
114 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 4, datas)); |
115 | 0 | } |
116 | | // sortlen |
117 | 0 | { |
118 | 0 | std::vector<int64_t> srcs(row_num); |
119 | 0 | for (int i = 0; i < row_num; ++i) { |
120 | 0 | srcs[i] = _s_collations[i].sortlen; |
121 | 0 | datas[i] = srcs.data() + i; |
122 | 0 | } |
123 | 0 | RETURN_IF_ERROR(fill_dest_column_for_range(block, 5, datas)); |
124 | 0 | } |
125 | 0 | return Status::OK(); |
126 | 0 | } |
127 | | |
128 | | } // namespace doris |