be/src/information_schema/schema_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_scanner.h" |
19 | | |
20 | | #include <gen_cpp/Descriptors_types.h> |
21 | | #include <gen_cpp/Types_types.h> |
22 | | #include <glog/logging.h> |
23 | | #include <string.h> |
24 | | |
25 | | #include <new> |
26 | | #include <ostream> |
27 | | #include <utility> |
28 | | |
29 | | #include "core/block/block.h" |
30 | | #include "core/block/column_with_type_and_name.h" |
31 | | #include "core/column/column.h" |
32 | | #include "core/column/column_complex.h" |
33 | | #include "core/column/column_nullable.h" |
34 | | #include "core/column/column_string.h" |
35 | | #include "core/column/column_vector.h" |
36 | | #include "core/data_type/data_type.h" |
37 | | #include "core/data_type/data_type_factory.hpp" |
38 | | #include "core/data_type/define_primitive_type.h" |
39 | | #include "core/data_type/primitive_type.h" |
40 | | #include "core/packed_int128.h" |
41 | | #include "core/string_ref.h" |
42 | | #include "core/types.h" |
43 | | #include "core/value/hll.h" |
44 | | #include "exec/pipeline/dependency.h" |
45 | | #include "information_schema/schema_active_queries_scanner.h" |
46 | | #include "information_schema/schema_backend_active_tasks.h" |
47 | | #include "information_schema/schema_backend_configuration_scanner.h" |
48 | | #include "information_schema/schema_backend_kerberos_ticket_cache.h" |
49 | | #include "information_schema/schema_backend_ms_rpc_table_throttlers_scanner.h" |
50 | | #include "information_schema/schema_catalog_meta_cache_stats_scanner.h" |
51 | | #include "information_schema/schema_charsets_scanner.h" |
52 | | #include "information_schema/schema_cluster_snapshot_properties_scanner.h" |
53 | | #include "information_schema/schema_cluster_snapshots_scanner.h" |
54 | | #include "information_schema/schema_collations_scanner.h" |
55 | | #include "information_schema/schema_column_data_sizes_scanner.h" |
56 | | #include "information_schema/schema_columns_scanner.h" |
57 | | #include "information_schema/schema_database_properties_scanner.h" |
58 | | #include "information_schema/schema_dummy_scanner.h" |
59 | | #include "information_schema/schema_encryption_keys_scanner.h" |
60 | | #include "information_schema/schema_file_cache_info_scanner.h" |
61 | | #include "information_schema/schema_file_cache_statistics.h" |
62 | | #include "information_schema/schema_files_scanner.h" |
63 | | #include "information_schema/schema_load_job_scanner.h" |
64 | | #include "information_schema/schema_metadata_name_ids_scanner.h" |
65 | | #include "information_schema/schema_partitions_scanner.h" |
66 | | #include "information_schema/schema_processlist_scanner.h" |
67 | | #include "information_schema/schema_profiling_scanner.h" |
68 | | #include "information_schema/schema_routine_load_job_scanner.h" |
69 | | #include "information_schema/schema_rowsets_scanner.h" |
70 | | #include "information_schema/schema_schema_privileges_scanner.h" |
71 | | #include "information_schema/schema_schemata_scanner.h" |
72 | | #include "information_schema/schema_sql_block_rule_status_scanner.h" |
73 | | #include "information_schema/schema_table_options_scanner.h" |
74 | | #include "information_schema/schema_table_privileges_scanner.h" |
75 | | #include "information_schema/schema_table_properties_scanner.h" |
76 | | #include "information_schema/schema_tables_scanner.h" |
77 | | #include "information_schema/schema_tablets_scanner.h" |
78 | | #include "information_schema/schema_user_privileges_scanner.h" |
79 | | #include "information_schema/schema_user_scanner.h" |
80 | | #include "information_schema/schema_variables_scanner.h" |
81 | | #include "information_schema/schema_view_dependency_scanner.h" |
82 | | #include "information_schema/schema_views_scanner.h" |
83 | | #include "information_schema/schema_workload_group_privileges.h" |
84 | | #include "information_schema/schema_workload_group_resource_usage_scanner.h" |
85 | | #include "information_schema/schema_workload_groups_scanner.h" |
86 | | #include "information_schema/schema_workload_sched_policy_scanner.h" |
87 | | #include "runtime/fragment_mgr.h" |
88 | | #include "util/string_util.h" |
89 | | |
90 | | namespace doris { |
91 | | class ObjectPool; |
92 | | |
93 | | SchemaScanner::SchemaScanner(const std::vector<ColumnDesc>& columns, TSchemaTableType::type type) |
94 | 4.59k | : _is_init(false), _columns(columns), _schema_table_type(type) {} |
95 | | |
96 | 4.59k | SchemaScanner::~SchemaScanner() = default; |
97 | | |
98 | 6 | Status SchemaScanner::start(RuntimeState* state) { |
99 | 6 | if (!_is_init) { |
100 | 0 | return Status::InternalError("call Start before Init."); |
101 | 0 | } |
102 | | |
103 | 6 | return Status::OK(); |
104 | 6 | } |
105 | | |
106 | 12.4k | Status SchemaScanner::get_next_block(RuntimeState* state, Block* block, bool* eos) { |
107 | 12.4k | if (_data_block == nullptr) { |
108 | 0 | return Status::InternalError("No data left!"); |
109 | 0 | } |
110 | 12.4k | DCHECK(_async_thread_running == false); |
111 | 12.4k | RETURN_IF_ERROR(_scanner_status.status()); |
112 | 218k | for (size_t i = 0; i < block->columns(); i++) { |
113 | 205k | std::move(*block->get_by_position(i).column) |
114 | 205k | .mutate() |
115 | 205k | ->insert_range_from(*_data_block->get_by_position(i).column, 0, |
116 | 205k | _data_block->rows()); |
117 | 205k | } |
118 | 12.4k | _data_block->clear_column_data(); |
119 | 12.4k | *eos = _eos; |
120 | 12.4k | if (!*eos) { |
121 | 10.2k | RETURN_IF_ERROR(get_next_block_async(state)); |
122 | 10.2k | } |
123 | 12.4k | return Status::OK(); |
124 | 12.4k | } |
125 | | |
126 | 12.5k | Status SchemaScanner::get_next_block_async(RuntimeState* state) { |
127 | 12.5k | _dependency->block(); |
128 | 12.5k | auto task_ctx = state->get_task_execution_context(); |
129 | 12.5k | RETURN_IF_ERROR(ExecEnv::GetInstance()->fragment_mgr()->get_thread_pool()->submit_func( |
130 | 12.5k | [this, task_ctx, state]() { |
131 | 12.5k | auto task_lock = task_ctx.lock(); |
132 | 12.5k | if (task_lock == nullptr) { |
133 | 12.5k | return; |
134 | 12.5k | } |
135 | 12.5k | DCHECK(_async_thread_running == false); |
136 | 12.5k | SCOPED_ATTACH_TASK(state); |
137 | 12.5k | _async_thread_running = true; |
138 | 12.5k | if (!_opened) { |
139 | 12.5k | _data_block = Block::create_unique(); |
140 | 12.5k | _init_block(_data_block.get()); |
141 | 12.5k | _scanner_status.update(start(state)); |
142 | 12.5k | _opened = true; |
143 | 12.5k | } |
144 | 12.5k | bool eos = false; |
145 | 12.5k | auto call_next_block_internal = [&]() -> Status { |
146 | 12.5k | RETURN_IF_CATCH_EXCEPTION( |
147 | 12.5k | { return get_next_block_internal(_data_block.get(), &eos); }); |
148 | 12.5k | }; |
149 | 12.5k | _scanner_status.update(call_next_block_internal()); |
150 | 12.5k | _eos = eos; |
151 | 12.5k | _async_thread_running = false; |
152 | 12.5k | _dependency->set_ready(); |
153 | 12.5k | })); |
154 | 12.5k | return Status::OK(); |
155 | 12.5k | } |
156 | | |
157 | 2.29k | Status SchemaScanner::init(RuntimeState* state, SchemaScannerParam* param, ObjectPool* pool) { |
158 | 2.29k | if (_is_init) { |
159 | 0 | return Status::OK(); |
160 | 0 | } |
161 | 2.29k | if (nullptr == param || nullptr == pool) { |
162 | 0 | return Status::InternalError("invalid parameter"); |
163 | 0 | } |
164 | | |
165 | 2.29k | _param = param; |
166 | 2.29k | _timezone = state->timezone(); |
167 | 2.29k | _timezone_obj = state->timezone_obj(); |
168 | 2.29k | _is_init = true; |
169 | | |
170 | 2.29k | if (_param->profile) { |
171 | 2.29k | _get_db_timer = ADD_TIMER(_param->profile, "GetDbTime"); |
172 | 2.29k | _get_table_timer = ADD_TIMER(_param->profile, "GetTableTime"); |
173 | 2.29k | _get_describe_timer = ADD_TIMER(_param->profile, "GetDescribeTime"); |
174 | 2.29k | _fill_block_timer = ADD_TIMER(_param->profile, "FillBlockTime"); |
175 | 2.29k | } |
176 | | |
177 | 2.29k | return Status::OK(); |
178 | 2.29k | } |
179 | | |
180 | 4.59k | std::unique_ptr<SchemaScanner> SchemaScanner::create(TSchemaTableType::type type) { |
181 | 4.59k | switch (type) { |
182 | 808 | case TSchemaTableType::SCH_TABLES: |
183 | 808 | return SchemaTablesScanner::create_unique(); |
184 | 54 | case TSchemaTableType::SCH_SCHEMATA: |
185 | 54 | return SchemaSchemataScanner::create_unique(); |
186 | 162 | case TSchemaTableType::SCH_COLUMNS: |
187 | 162 | return SchemaColumnsScanner::create_unique(); |
188 | 6 | case TSchemaTableType::SCH_CHARSETS: |
189 | 6 | return SchemaCharsetsScanner::create_unique(); |
190 | 6 | case TSchemaTableType::SCH_COLLATIONS: |
191 | 6 | return SchemaCollationsScanner::create_unique(); |
192 | 6 | case TSchemaTableType::SCH_GLOBAL_VARIABLES: |
193 | 6 | return SchemaVariablesScanner::create_unique(TVarType::GLOBAL); |
194 | 72 | case TSchemaTableType::SCH_SESSION_VARIABLES: |
195 | 72 | case TSchemaTableType::SCH_VARIABLES: |
196 | 72 | return SchemaVariablesScanner::create_unique(TVarType::SESSION); |
197 | 16 | case TSchemaTableType::SCH_VIEWS: |
198 | 16 | return SchemaViewsScanner::create_unique(); |
199 | 12 | case TSchemaTableType::SCH_TABLE_PRIVILEGES: |
200 | 12 | return SchemaTablePrivilegesScanner::create_unique(); |
201 | 8 | case TSchemaTableType::SCH_SCHEMA_PRIVILEGES: |
202 | 8 | return SchemaSchemaPrivilegesScanner::create_unique(); |
203 | 6 | case TSchemaTableType::SCH_USER_PRIVILEGES: |
204 | 6 | return SchemaUserPrivilegesScanner::create_unique(); |
205 | 4 | case TSchemaTableType::SCH_FILES: |
206 | 4 | return SchemaFilesScanner::create_unique(); |
207 | 44 | case TSchemaTableType::SCH_PARTITIONS: |
208 | 44 | return SchemaPartitionsScanner::create_unique(); |
209 | 2 | case TSchemaTableType::SCH_BACKEND_CONFIGURATION: |
210 | 2 | return SchemaBackendConfigurationScanner::create_unique(); |
211 | 18 | case TSchemaTableType::SCH_ROWSETS: |
212 | 18 | return SchemaRowsetsScanner::create_unique(); |
213 | 14 | case TSchemaTableType::SCH_METADATA_NAME_IDS: |
214 | 14 | return SchemaMetadataNameIdsScanner::create_unique(); |
215 | 4 | case TSchemaTableType::SCH_PROFILING: |
216 | 4 | return SchemaProfilingScanner::create_unique(); |
217 | 1.21k | case TSchemaTableType::SCH_BACKEND_ACTIVE_TASKS: |
218 | 1.21k | return SchemaBackendActiveTasksScanner::create_unique(); |
219 | 1.22k | case TSchemaTableType::SCH_ACTIVE_QUERIES: |
220 | 1.22k | return SchemaActiveQueriesScanner::create_unique(); |
221 | 52 | case TSchemaTableType::SCH_WORKLOAD_GROUPS: |
222 | 52 | return SchemaWorkloadGroupsScanner::create_unique(); |
223 | 20 | case TSchemaTableType::SCH_PROCESSLIST: |
224 | 20 | return SchemaProcessListScanner::create_unique(); |
225 | 2 | case TSchemaTableType::SCH_USER: |
226 | 2 | return SchemaUserScanner::create_unique(); |
227 | 16 | case TSchemaTableType::SCH_WORKLOAD_POLICY: |
228 | 16 | return SchemaWorkloadSchedulePolicyScanner::create_unique(); |
229 | 12 | case TSchemaTableType::SCH_TABLE_OPTIONS: |
230 | 12 | return SchemaTableOptionsScanner::create_unique(); |
231 | 26 | case TSchemaTableType::SCH_WORKLOAD_GROUP_PRIVILEGES: |
232 | 26 | return SchemaWorkloadGroupPrivilegesScanner::create_unique(); |
233 | 6 | case TSchemaTableType::SCH_WORKLOAD_GROUP_RESOURCE_USAGE: |
234 | 6 | return SchemaBackendWorkloadGroupResourceUsage::create_unique(); |
235 | 16 | case TSchemaTableType::SCH_TABLE_PROPERTIES: |
236 | 16 | return SchemaTablePropertiesScanner::create_unique(); |
237 | 12 | case TSchemaTableType::SCH_DATABASE_PROPERTIES: |
238 | 12 | return SchemaDatabasePropertiesScanner::create_unique(); |
239 | 66 | case TSchemaTableType::SCH_FILE_CACHE_STATISTICS: |
240 | 66 | return SchemaFileCacheStatisticsScanner::create_unique(); |
241 | 26 | case TSchemaTableType::SCH_CATALOG_META_CACHE_STATISTICS: |
242 | 26 | return SchemaCatalogMetaCacheStatsScanner::create_unique(); |
243 | 2 | case TSchemaTableType::SCH_BACKEND_KERBEROS_TICKET_CACHE: |
244 | 2 | return SchemaBackendKerberosTicketCacheScanner::create_unique(); |
245 | 6 | case TSchemaTableType::SCH_ROUTINE_LOAD_JOBS: |
246 | 6 | return SchemaRoutineLoadJobScanner::create_unique(); |
247 | 4 | case TSchemaTableType::SCH_LOAD_JOBS: |
248 | 4 | return SchemaLoadJobScanner::create_unique(); |
249 | 2 | case TSchemaTableType::SCH_BACKEND_TABLETS: |
250 | 2 | return SchemaTabletsScanner::create_unique(); |
251 | 16 | case TSchemaTableType::SCH_VIEW_DEPENDENCY: |
252 | 16 | return SchemaViewDependencyScanner::create_unique(); |
253 | 6 | case TSchemaTableType::SCH_SQL_BLOCK_RULE_STATUS: |
254 | 6 | return SchemaSqlBlockRuleStatusScanner::create_unique(); |
255 | 0 | case TSchemaTableType::SCH_ENCRYPTION_KEYS: |
256 | 0 | return SchemaEncryptionKeysScanner::create_unique(); |
257 | 4 | case TSchemaTableType::SCH_CLUSTER_SNAPSHOTS: |
258 | 4 | return SchemaClusterSnapshotsScanner::create_unique(); |
259 | 2 | case TSchemaTableType::SCH_CLUSTER_SNAPSHOT_PROPERTIES: |
260 | 2 | return SchemaClusterSnapshotPropertiesScanner::create_unique(); |
261 | 6 | case TSchemaTableType::SCH_COLUMN_DATA_SIZES: |
262 | 6 | return SchemaColumnDataSizesScanner::create_unique(); |
263 | 2 | case TSchemaTableType::SCH_FILE_CACHE_INFO: |
264 | 2 | return SchemaFileCacheInfoScanner::create_unique(); |
265 | 2 | case TSchemaTableType::SCH_BACKEND_MS_RPC_TABLE_THROTTLERS: |
266 | 2 | return SchemaBackendMsRpcTableThrottlersScanner::create_unique(); |
267 | 604 | default: |
268 | 604 | return SchemaDummyScanner::create_unique(); |
269 | 0 | break; |
270 | 4.59k | } |
271 | 4.59k | } |
272 | | |
273 | 2.30k | void SchemaScanner::_init_block(Block* src_block) { |
274 | 2.30k | const std::vector<SchemaScanner::ColumnDesc>& columns_desc(get_column_desc()); |
275 | 31.7k | for (int i = 0; i < columns_desc.size(); ++i) { |
276 | 29.4k | auto data_type = DataTypeFactory::instance().create_data_type(columns_desc[i].type, true); |
277 | 29.4k | src_block->insert( |
278 | 29.4k | ColumnWithTypeAndName(data_type->create_column(), data_type, columns_desc[i].name)); |
279 | 29.4k | } |
280 | 2.30k | } |
281 | | |
282 | | Status SchemaScanner::fill_dest_column_for_range(Block* block, size_t pos, |
283 | 91.7k | const std::vector<void*>& datas) { |
284 | 91.7k | const ColumnDesc& col_desc = _columns[pos]; |
285 | 91.7k | MutableColumnPtr column_ptr; |
286 | 91.7k | column_ptr = std::move(*block->get_by_position(pos).column).assume_mutable(); |
287 | 91.7k | IColumn* col_ptr = column_ptr.get(); |
288 | | |
289 | 91.7k | auto* nullable_column = reinterpret_cast<ColumnNullable*>(col_ptr); |
290 | | |
291 | | // Resize in advance to improve insertion efficiency. |
292 | 91.7k | size_t fill_num = datas.size(); |
293 | 91.7k | col_ptr = &nullable_column->get_nested_column(); |
294 | 6.13M | for (int i = 0; i < fill_num; ++i) { |
295 | 6.03M | auto* data = datas[i]; |
296 | 6.03M | if (data == nullptr) { |
297 | | // For nested column need not insert default. |
298 | 684k | nullable_column->insert_data(nullptr, 0); |
299 | 684k | continue; |
300 | 5.35M | } else { |
301 | 5.35M | nullable_column->push_false_to_nullmap(1); |
302 | 5.35M | } |
303 | 5.35M | switch (col_desc.type) { |
304 | 0 | case TYPE_HLL: { |
305 | 0 | auto* hll_slot = reinterpret_cast<HyperLogLog*>(data); |
306 | 0 | assert_cast<ColumnHLL*>(col_ptr)->get_data().emplace_back(*hll_slot); |
307 | 0 | break; |
308 | 0 | } |
309 | 1.63M | case TYPE_VARCHAR: |
310 | 1.63M | case TYPE_CHAR: |
311 | 1.70M | case TYPE_STRING: { |
312 | 1.70M | auto* str_slot = reinterpret_cast<StringRef*>(data); |
313 | 1.70M | assert_cast<ColumnString*>(col_ptr)->insert_data(str_slot->data, str_slot->size); |
314 | 1.70M | break; |
315 | 1.63M | } |
316 | | |
317 | 906 | case TYPE_BOOLEAN: { |
318 | 906 | uint8_t num = *reinterpret_cast<bool*>(data); |
319 | 906 | assert_cast<ColumnBool*>(col_ptr)->insert_value(num); |
320 | 906 | break; |
321 | 1.63M | } |
322 | | |
323 | 0 | case TYPE_TINYINT: { |
324 | 0 | int8_t num = *reinterpret_cast<int8_t*>(data); |
325 | 0 | assert_cast<ColumnInt8*>(col_ptr)->insert_value(num); |
326 | 0 | break; |
327 | 1.63M | } |
328 | | |
329 | 0 | case TYPE_SMALLINT: { |
330 | 0 | int16_t num = *reinterpret_cast<int16_t*>(data); |
331 | 0 | assert_cast<ColumnInt16*>(col_ptr)->insert_value(num); |
332 | 0 | break; |
333 | 1.63M | } |
334 | | |
335 | 325k | case TYPE_INT: { |
336 | 325k | int32_t num = *reinterpret_cast<int32_t*>(data); |
337 | 325k | assert_cast<ColumnInt32*>(col_ptr)->insert_value(num); |
338 | 325k | break; |
339 | 1.63M | } |
340 | | |
341 | 3.05M | case TYPE_BIGINT: { |
342 | 3.05M | int64_t num = *reinterpret_cast<int64_t*>(data); |
343 | 3.05M | assert_cast<ColumnInt64*>(col_ptr)->insert_value(num); |
344 | 3.05M | break; |
345 | 1.63M | } |
346 | | |
347 | 287 | case TYPE_LARGEINT: { |
348 | 287 | __int128 num; |
349 | 287 | memcpy(&num, data, sizeof(__int128)); |
350 | 287 | assert_cast<ColumnInt128*>(col_ptr)->insert_value(num); |
351 | 287 | break; |
352 | 1.63M | } |
353 | | |
354 | 0 | case TYPE_FLOAT: { |
355 | 0 | float num = *reinterpret_cast<float*>(data); |
356 | 0 | assert_cast<ColumnFloat32*>(col_ptr)->insert_value(num); |
357 | 0 | break; |
358 | 1.63M | } |
359 | | |
360 | 0 | case TYPE_DOUBLE: { |
361 | 0 | double num = *reinterpret_cast<double*>(data); |
362 | 0 | assert_cast<ColumnFloat64*>(col_ptr)->insert_value(num); |
363 | 0 | break; |
364 | 1.63M | } |
365 | | |
366 | 0 | case TYPE_DATE: { |
367 | 0 | assert_cast<ColumnDate*>(col_ptr)->insert_data(reinterpret_cast<char*>(data), 0); |
368 | 0 | break; |
369 | 1.63M | } |
370 | | |
371 | 0 | case TYPE_DATEV2: { |
372 | 0 | assert_cast<ColumnDateV2*>(col_ptr)->insert_value( |
373 | 0 | *reinterpret_cast<DateV2Value<DateV2ValueType>*>(data)); |
374 | 0 | break; |
375 | 1.63M | } |
376 | | |
377 | 279k | case TYPE_DATETIME: { |
378 | 279k | assert_cast<ColumnDateTime*>(col_ptr)->insert_data(reinterpret_cast<char*>(data), 0); |
379 | 279k | break; |
380 | 1.63M | } |
381 | | |
382 | 291 | case TYPE_DATETIMEV2: { |
383 | 291 | assert_cast<ColumnDateTimeV2*>(col_ptr)->insert_value( |
384 | 291 | *reinterpret_cast<DateV2Value<DateTimeV2ValueType>*>(data)); |
385 | 291 | break; |
386 | 1.63M | } |
387 | | |
388 | 0 | case TYPE_TIMESTAMPTZ: { |
389 | 0 | assert_cast<ColumnTimeStampTz*>(col_ptr)->insert_value( |
390 | 0 | *reinterpret_cast<TimestampTzValue*>(data)); |
391 | 0 | break; |
392 | 1.63M | } |
393 | | |
394 | 0 | case TYPE_DECIMALV2: { |
395 | 0 | const Int128 num = (reinterpret_cast<PackedInt128*>(data))->value; |
396 | 0 | assert_cast<ColumnDecimal128V2*>(col_ptr)->insert_data( |
397 | 0 | reinterpret_cast<const char*>(&num), 0); |
398 | 0 | break; |
399 | 1.63M | } |
400 | 0 | case TYPE_DECIMAL128I: { |
401 | 0 | const Int128 num = (reinterpret_cast<PackedInt128*>(data))->value; |
402 | 0 | assert_cast<ColumnDecimal128V3*>(col_ptr)->insert_data( |
403 | 0 | reinterpret_cast<const char*>(&num), 0); |
404 | 0 | break; |
405 | 1.63M | } |
406 | | |
407 | 0 | case TYPE_DECIMAL32: { |
408 | 0 | const int32_t num = *reinterpret_cast<int32_t*>(data); |
409 | 0 | assert_cast<ColumnDecimal32*>(col_ptr)->insert_data(reinterpret_cast<const char*>(&num), |
410 | 0 | 0); |
411 | 0 | break; |
412 | 1.63M | } |
413 | | |
414 | 0 | case TYPE_DECIMAL64: { |
415 | 0 | const int64_t num = *reinterpret_cast<int64_t*>(data); |
416 | 0 | assert_cast<ColumnDecimal64*>(col_ptr)->insert_data(reinterpret_cast<const char*>(&num), |
417 | 0 | 0); |
418 | 0 | break; |
419 | 1.63M | } |
420 | | |
421 | 0 | default: { |
422 | 0 | DCHECK(false) << "bad slot type: " << col_desc.type; |
423 | 0 | std::stringstream ss; |
424 | 0 | ss << "Fail to convert schema type:'" << col_desc.type << " on column:`" |
425 | 0 | << std::string(col_desc.name) + "`"; |
426 | 0 | return Status::InternalError(ss.str()); |
427 | 1.63M | } |
428 | 5.35M | } |
429 | 5.35M | } |
430 | 96.5k | return Status::OK(); |
431 | 91.7k | } |
432 | | |
433 | 0 | std::string SchemaScanner::get_db_from_full_name(const std::string& full_name) { |
434 | 0 | std::vector<std::string> part = split(full_name, "."); |
435 | 0 | if (part.size() == 2) { |
436 | 0 | return part[1]; |
437 | 0 | } |
438 | 0 | return full_name; |
439 | 0 | } |
440 | | |
441 | | Status SchemaScanner::insert_block_column(TCell cell, int col_index, Block* block, |
442 | 1.82M | PrimitiveType type) { |
443 | 1.82M | MutableColumnPtr mutable_col_ptr; |
444 | 1.82M | mutable_col_ptr = std::move(*block->get_by_position(col_index).column).assume_mutable(); |
445 | 1.82M | auto* nullable_column = reinterpret_cast<ColumnNullable*>(mutable_col_ptr.get()); |
446 | 1.82M | IColumn* col_ptr = &nullable_column->get_nested_column(); |
447 | | |
448 | 1.82M | switch (type) { |
449 | 209k | case TYPE_BIGINT: { |
450 | 209k | reinterpret_cast<ColumnInt64*>(col_ptr)->insert_value(cell.longVal); |
451 | 209k | break; |
452 | 0 | } |
453 | | |
454 | 87.7k | case TYPE_INT: { |
455 | 87.7k | reinterpret_cast<ColumnInt32*>(col_ptr)->insert_value(cell.intVal); |
456 | 87.7k | break; |
457 | 0 | } |
458 | | |
459 | 31 | case TYPE_BOOLEAN: { |
460 | 31 | reinterpret_cast<ColumnUInt8*>(col_ptr)->insert_value(cell.boolVal); |
461 | 31 | break; |
462 | 0 | } |
463 | | |
464 | 700k | case TYPE_STRING: |
465 | 1.49M | case TYPE_VARCHAR: |
466 | 1.49M | case TYPE_CHAR: { |
467 | 1.49M | reinterpret_cast<ColumnString*>(col_ptr)->insert_data(cell.stringVal.data(), |
468 | 1.49M | cell.stringVal.size()); |
469 | 1.49M | break; |
470 | 1.49M | } |
471 | | |
472 | 35.1k | case TYPE_DATETIME: { |
473 | 35.1k | std::vector<void*> datas(1); |
474 | 35.1k | VecDateTimeValue src[1]; |
475 | 35.1k | src[0].from_date_str(cell.stringVal.data(), cell.stringVal.size()); |
476 | 35.1k | datas[0] = src; |
477 | 35.1k | auto data = datas[0]; |
478 | 35.1k | reinterpret_cast<ColumnDateTime*>(col_ptr)->insert_data(reinterpret_cast<char*>(data), 0); |
479 | 35.1k | break; |
480 | 1.49M | } |
481 | 0 | default: { |
482 | 0 | std::stringstream ss; |
483 | 0 | ss << "unsupported column type:" << type; |
484 | 0 | return Status::InternalError(ss.str()); |
485 | 1.49M | } |
486 | 1.82M | } |
487 | 1.82M | nullable_column->push_false_to_nullmap(1); |
488 | 1.82M | return Status::OK(); |
489 | 1.82M | } |
490 | | |
491 | | } // namespace doris |