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