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