be/src/exec/scan/file_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 "exec/scan/file_scanner.h" |
19 | | |
20 | | #include <fmt/format.h> |
21 | | #include <gen_cpp/Exprs_types.h> |
22 | | #include <gen_cpp/Metrics_types.h> |
23 | | #include <gen_cpp/Opcodes_types.h> |
24 | | #include <gen_cpp/PaloInternalService_types.h> |
25 | | #include <gen_cpp/PlanNodes_types.h> |
26 | | #include <glog/logging.h> |
27 | | |
28 | | #include <algorithm> |
29 | | #include <boost/iterator/iterator_facade.hpp> |
30 | | #include <map> |
31 | | #include <ranges> |
32 | | #include <tuple> |
33 | | #include <unordered_map> |
34 | | #include <utility> |
35 | | |
36 | | #include "common/compiler_util.h" // IWYU pragma: keep |
37 | | #include "common/config.h" |
38 | | #include "common/consts.h" |
39 | | #include "common/logging.h" |
40 | | #include "common/status.h" |
41 | | #include "core/block/column_with_type_and_name.h" |
42 | | #include "core/block/columns_with_type_and_name.h" |
43 | | #include "core/column/column.h" |
44 | | #include "core/column/column_nullable.h" |
45 | | #include "core/column/column_vector.h" |
46 | | #include "core/data_type/data_type.h" |
47 | | #include "core/data_type/data_type_nullable.h" |
48 | | #include "core/data_type/data_type_string.h" |
49 | | #include "core/string_ref.h" |
50 | | #include "exec/common/stringop_substring.h" |
51 | | #include "exec/rowid_fetcher.h" |
52 | | #include "exec/scan/scan_node.h" |
53 | | #include "exprs/aggregate/aggregate_function.h" |
54 | | #include "exprs/function/function.h" |
55 | | #include "exprs/function/simple_function_factory.h" |
56 | | #include "exprs/vexpr.h" |
57 | | #include "exprs/vexpr_context.h" |
58 | | #include "exprs/vexpr_fwd.h" |
59 | | #include "exprs/vslot_ref.h" |
60 | | #include "format/arrow/arrow_stream_reader.h" |
61 | | #include "format/csv/csv_reader.h" |
62 | | #include "format/json/new_json_reader.h" |
63 | | #include "format/native/native_reader.h" |
64 | | #include "format/orc/vorc_reader.h" |
65 | | #include "format/parquet/vparquet_reader.h" |
66 | | #include "format/table/hive_reader.h" |
67 | | #include "format/table/hudi_jni_reader.h" |
68 | | #include "format/table/hudi_reader.h" |
69 | | #include "format/table/iceberg_reader.h" |
70 | | #include "format/table/iceberg_sys_table_jni_reader.h" |
71 | | #include "format/table/jdbc_jni_reader.h" |
72 | | #include "format/table/max_compute_jni_reader.h" |
73 | | #include "format/table/paimon_cpp_reader.h" |
74 | | #include "format/table/paimon_jni_reader.h" |
75 | | #include "format/table/paimon_predicate_converter.h" |
76 | | #include "format/table/paimon_reader.h" |
77 | | #include "format/table/remote_doris_reader.h" |
78 | | #include "format/table/transactional_hive_reader.h" |
79 | | #include "format/table/trino_connector_jni_reader.h" |
80 | | #include "format/text/text_reader.h" |
81 | | #include "io/cache/block_file_cache_profile.h" |
82 | | #include "load/group_commit/wal/wal_reader.h" |
83 | | #include "runtime/descriptors.h" |
84 | | #include "runtime/runtime_profile.h" |
85 | | #include "runtime/runtime_state.h" |
86 | | |
87 | | namespace cctz { |
88 | | class time_zone; |
89 | | } // namespace cctz |
90 | | namespace doris { |
91 | | class ShardedKVCache; |
92 | | } // namespace doris |
93 | | |
94 | | namespace doris { |
95 | | using namespace ErrorCode; |
96 | | |
97 | | const std::string FileScanner::FileReadBytesProfile = "FileReadBytes"; |
98 | | const std::string FileScanner::FileReadTimeProfile = "FileReadTime"; |
99 | | |
100 | | FileScanner::FileScanner(RuntimeState* state, FileScanLocalState* local_state, int64_t limit, |
101 | | std::shared_ptr<SplitSourceConnector> split_source, |
102 | | RuntimeProfile* profile, ShardedKVCache* kv_cache, |
103 | | const std::unordered_map<std::string, int>* colname_to_slot_id) |
104 | 2.65k | : Scanner(state, local_state, limit, profile), |
105 | 2.65k | _split_source(split_source), |
106 | 2.65k | _cur_reader(nullptr), |
107 | 2.65k | _cur_reader_eof(false), |
108 | 2.65k | _kv_cache(kv_cache), |
109 | 2.65k | _strict_mode(false), |
110 | 2.65k | _col_name_to_slot_id(colname_to_slot_id) { |
111 | 2.65k | if (state->get_query_ctx() != nullptr && |
112 | 2.65k | state->get_query_ctx()->file_scan_range_params_map.count(local_state->parent_id()) > 0) { |
113 | 536 | _params = &(state->get_query_ctx()->file_scan_range_params_map[local_state->parent_id()]); |
114 | 2.12k | } else { |
115 | | // old fe thrift protocol |
116 | 2.12k | _params = _split_source->get_params(); |
117 | 2.12k | } |
118 | 2.65k | if (_params->__isset.strict_mode) { |
119 | 2.12k | _strict_mode = _params->strict_mode; |
120 | 2.12k | } |
121 | | |
122 | | // For load scanner, there are input and output tuple. |
123 | | // For query scanner, there is only output tuple |
124 | 2.65k | _input_tuple_desc = state->desc_tbl().get_tuple_descriptor(_params->src_tuple_id); |
125 | 2.65k | _real_tuple_desc = _input_tuple_desc == nullptr ? _output_tuple_desc : _input_tuple_desc; |
126 | 2.65k | _is_load = (_input_tuple_desc != nullptr); |
127 | 2.65k | } |
128 | | |
129 | 2.65k | Status FileScanner::init(RuntimeState* state, const VExprContextSPtrs& conjuncts) { |
130 | 2.65k | RETURN_IF_ERROR(Scanner::init(state, conjuncts)); |
131 | 2.65k | _get_block_timer = |
132 | 2.65k | ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), "FileScannerGetBlockTime", 1); |
133 | 2.65k | _cast_to_input_block_timer = ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), |
134 | 2.65k | "FileScannerCastInputBlockTime", 1); |
135 | 2.65k | _fill_missing_columns_timer = ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), |
136 | 2.65k | "FileScannerFillMissingColumnTime", 1); |
137 | 2.65k | _pre_filter_timer = |
138 | 2.65k | ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), "FileScannerPreFilterTimer", 1); |
139 | 2.65k | _convert_to_output_block_timer = ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), |
140 | 2.65k | "FileScannerConvertOuputBlockTime", 1); |
141 | 2.65k | _runtime_filter_partition_prune_timer = ADD_TIMER_WITH_LEVEL( |
142 | 2.65k | _local_state->scanner_profile(), "FileScannerRuntimeFilterPartitionPruningTime", 1); |
143 | 2.65k | _empty_file_counter = |
144 | 2.65k | ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), "EmptyFileNum", TUnit::UNIT, 1); |
145 | 2.65k | _not_found_file_counter = ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), |
146 | 2.65k | "NotFoundFileNum", TUnit::UNIT, 1); |
147 | 2.65k | _fully_skipped_file_counter = ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), |
148 | 2.65k | "FullySkippedFileNum", TUnit::UNIT, 1); |
149 | 2.65k | _file_counter = |
150 | 2.65k | ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), "FileNumber", TUnit::UNIT, 1); |
151 | | |
152 | 2.65k | _file_read_bytes_counter = ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), |
153 | 2.65k | FileReadBytesProfile, TUnit::BYTES, 1); |
154 | 2.65k | _file_read_calls_counter = ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), |
155 | 2.65k | "FileReadCalls", TUnit::UNIT, 1); |
156 | 2.65k | _file_read_time_counter = |
157 | 2.65k | ADD_TIMER_WITH_LEVEL(_local_state->scanner_profile(), FileReadTimeProfile, 1); |
158 | | |
159 | 2.65k | _runtime_filter_partition_pruned_range_counter = |
160 | 2.65k | ADD_COUNTER_WITH_LEVEL(_local_state->scanner_profile(), |
161 | 2.65k | "RuntimeFilterPartitionPrunedRangeNum", TUnit::UNIT, 1); |
162 | | |
163 | 2.65k | _file_cache_statistics.reset(new io::FileCacheStatistics()); |
164 | 2.65k | _file_reader_stats.reset(new io::FileReaderStats()); |
165 | | |
166 | 2.65k | RETURN_IF_ERROR(_init_io_ctx()); |
167 | 2.65k | _io_ctx->file_cache_stats = _file_cache_statistics.get(); |
168 | 2.65k | _io_ctx->file_reader_stats = _file_reader_stats.get(); |
169 | 2.65k | _io_ctx->is_disposable = _state->query_options().disable_file_cache; |
170 | | |
171 | 2.65k | if (_is_load) { |
172 | 2.12k | _src_row_desc.reset(new RowDescriptor(_state->desc_tbl(), |
173 | 2.12k | std::vector<TupleId>({_input_tuple_desc->id()}))); |
174 | | // prepare pre filters |
175 | 2.12k | if (_params->__isset.pre_filter_exprs_list) { |
176 | 4 | RETURN_IF_ERROR(doris::VExpr::create_expr_trees(_params->pre_filter_exprs_list, |
177 | 4 | _pre_conjunct_ctxs)); |
178 | 2.11k | } else if (_params->__isset.pre_filter_exprs) { |
179 | 0 | VExprContextSPtr context; |
180 | 0 | RETURN_IF_ERROR(doris::VExpr::create_expr_tree(_params->pre_filter_exprs, context)); |
181 | 0 | _pre_conjunct_ctxs.emplace_back(context); |
182 | 0 | } |
183 | | |
184 | 2.12k | for (auto& conjunct : _pre_conjunct_ctxs) { |
185 | 5 | RETURN_IF_ERROR(conjunct->prepare(_state, *_src_row_desc)); |
186 | 5 | RETURN_IF_ERROR(conjunct->open(_state)); |
187 | 5 | } |
188 | | |
189 | 2.12k | _dest_row_desc.reset(new RowDescriptor(_state->desc_tbl(), |
190 | 2.12k | std::vector<TupleId>({_output_tuple_desc->id()}))); |
191 | 2.12k | } |
192 | | |
193 | 2.65k | _default_val_row_desc.reset( |
194 | 2.65k | new RowDescriptor(_state->desc_tbl(), std::vector<TupleId>({_real_tuple_desc->id()}))); |
195 | | |
196 | 2.65k | return Status::OK(); |
197 | 2.65k | } |
198 | | |
199 | | // check if the expr is a partition pruning expr |
200 | 0 | bool FileScanner::_check_partition_prune_expr(const VExprSPtr& expr) { |
201 | 0 | if (expr->is_slot_ref()) { |
202 | 0 | auto* slot_ref = static_cast<VSlotRef*>(expr.get()); |
203 | 0 | return _partition_slot_index_map.find(slot_ref->slot_id()) != |
204 | 0 | _partition_slot_index_map.end(); |
205 | 0 | } |
206 | 0 | if (expr->is_literal()) { |
207 | 0 | return true; |
208 | 0 | } |
209 | 0 | return std::ranges::all_of(expr->children(), [this](const auto& child) { |
210 | 0 | return _check_partition_prune_expr(child); |
211 | 0 | }); |
212 | 0 | } |
213 | | |
214 | 6 | void FileScanner::_init_runtime_filter_partition_prune_ctxs() { |
215 | 6 | _runtime_filter_partition_prune_ctxs.clear(); |
216 | 6 | for (auto& conjunct : _conjuncts) { |
217 | 0 | auto impl = conjunct->root()->get_impl(); |
218 | | // If impl is not null, which means this a conjuncts from runtime filter. |
219 | 0 | auto expr = impl ? impl : conjunct->root(); |
220 | 0 | if (_check_partition_prune_expr(expr)) { |
221 | 0 | _runtime_filter_partition_prune_ctxs.emplace_back(conjunct); |
222 | 0 | } |
223 | 0 | } |
224 | 6 | } |
225 | | |
226 | 6 | void FileScanner::_init_runtime_filter_partition_prune_block() { |
227 | | // init block with empty column |
228 | 22 | for (auto const* slot_desc : _real_tuple_desc->slots()) { |
229 | 22 | _runtime_filter_partition_prune_block.insert( |
230 | 22 | ColumnWithTypeAndName(slot_desc->get_empty_mutable_column(), |
231 | 22 | slot_desc->get_data_type_ptr(), slot_desc->col_name())); |
232 | 22 | } |
233 | 6 | } |
234 | | |
235 | 6 | Status FileScanner::_process_runtime_filters_partition_prune(bool& can_filter_all) { |
236 | 6 | SCOPED_TIMER(_runtime_filter_partition_prune_timer); |
237 | 6 | if (_runtime_filter_partition_prune_ctxs.empty() || _partition_col_descs.empty()) { |
238 | 6 | return Status::OK(); |
239 | 6 | } |
240 | 0 | size_t partition_value_column_size = 1; |
241 | | |
242 | | // 1. Get partition key values to string columns. |
243 | 0 | std::unordered_map<SlotId, MutableColumnPtr> partition_slot_id_to_column; |
244 | 0 | for (auto const& partition_col_desc : _partition_col_descs) { |
245 | 0 | const auto& [partition_value, partition_slot_desc] = partition_col_desc.second; |
246 | 0 | auto data_type = partition_slot_desc->get_data_type_ptr(); |
247 | 0 | auto test_serde = data_type->get_serde(); |
248 | 0 | auto partition_value_column = data_type->create_column(); |
249 | 0 | auto* col_ptr = static_cast<IColumn*>(partition_value_column.get()); |
250 | 0 | Slice slice(partition_value.data(), partition_value.size()); |
251 | 0 | uint64_t num_deserialized = 0; |
252 | 0 | DataTypeSerDe::FormatOptions options {}; |
253 | 0 | if (_partition_value_is_null.contains(partition_slot_desc->col_name())) { |
254 | | // for iceberg/paimon table |
255 | | // NOTICE: column is always be nullable for iceberg/paimon table now |
256 | 0 | DCHECK(data_type->is_nullable()); |
257 | 0 | test_serde = test_serde->get_nested_serdes()[0]; |
258 | 0 | auto* null_column = assert_cast<ColumnNullable*>(col_ptr); |
259 | 0 | if (_partition_value_is_null[partition_slot_desc->col_name()]) { |
260 | 0 | null_column->insert_many_defaults(partition_value_column_size); |
261 | 0 | } else { |
262 | | // If the partition value is not null, we set null map to 0 and deserialize it normally. |
263 | 0 | null_column->get_null_map_column().insert_many_vals(0, partition_value_column_size); |
264 | 0 | RETURN_IF_ERROR(test_serde->deserialize_column_from_fixed_json( |
265 | 0 | null_column->get_nested_column(), slice, partition_value_column_size, |
266 | 0 | &num_deserialized, options)); |
267 | 0 | } |
268 | 0 | } else { |
269 | | // for hive/hudi table, the null value is set as "\\N" |
270 | | // TODO: this will be unified as iceberg/paimon table in the future |
271 | 0 | RETURN_IF_ERROR(test_serde->deserialize_column_from_fixed_json( |
272 | 0 | *col_ptr, slice, partition_value_column_size, &num_deserialized, options)); |
273 | 0 | } |
274 | | |
275 | 0 | partition_slot_id_to_column[partition_slot_desc->id()] = std::move(partition_value_column); |
276 | 0 | } |
277 | | |
278 | | // 2. Fill _runtime_filter_partition_prune_block from the partition column, then execute conjuncts and filter block. |
279 | | // 2.1 Fill _runtime_filter_partition_prune_block from the partition column to match the conjuncts executing. |
280 | 0 | size_t index = 0; |
281 | 0 | bool first_column_filled = false; |
282 | 0 | for (auto const* slot_desc : _real_tuple_desc->slots()) { |
283 | 0 | if (partition_slot_id_to_column.find(slot_desc->id()) != |
284 | 0 | partition_slot_id_to_column.end()) { |
285 | 0 | auto data_type = slot_desc->get_data_type_ptr(); |
286 | 0 | auto partition_value_column = std::move(partition_slot_id_to_column[slot_desc->id()]); |
287 | 0 | if (data_type->is_nullable()) { |
288 | 0 | _runtime_filter_partition_prune_block.insert( |
289 | 0 | index, ColumnWithTypeAndName( |
290 | 0 | ColumnNullable::create( |
291 | 0 | std::move(partition_value_column), |
292 | 0 | ColumnUInt8::create(partition_value_column_size, 0)), |
293 | 0 | data_type, slot_desc->col_name())); |
294 | 0 | } else { |
295 | 0 | _runtime_filter_partition_prune_block.insert( |
296 | 0 | index, ColumnWithTypeAndName(std::move(partition_value_column), data_type, |
297 | 0 | slot_desc->col_name())); |
298 | 0 | } |
299 | 0 | if (index == 0) { |
300 | 0 | first_column_filled = true; |
301 | 0 | } |
302 | 0 | } |
303 | 0 | index++; |
304 | 0 | } |
305 | | |
306 | | // 2.2 Execute conjuncts. |
307 | 0 | if (!first_column_filled) { |
308 | | // VExprContext.execute has an optimization, the filtering is executed when block->rows() > 0 |
309 | | // The following process may be tricky and time-consuming, but we have no other way. |
310 | 0 | _runtime_filter_partition_prune_block.get_by_position(0).column->assume_mutable()->resize( |
311 | 0 | partition_value_column_size); |
312 | 0 | } |
313 | 0 | IColumn::Filter result_filter(_runtime_filter_partition_prune_block.rows(), 1); |
314 | 0 | RETURN_IF_ERROR(VExprContext::execute_conjuncts(_runtime_filter_partition_prune_ctxs, nullptr, |
315 | 0 | &_runtime_filter_partition_prune_block, |
316 | 0 | &result_filter, &can_filter_all)); |
317 | 0 | return Status::OK(); |
318 | 0 | } |
319 | | |
320 | 2 | Status FileScanner::_process_conjuncts() { |
321 | 2 | _slot_id_to_filter_conjuncts.clear(); |
322 | 2 | _not_single_slot_filter_conjuncts.clear(); |
323 | 2 | for (auto& conjunct : _push_down_conjuncts) { |
324 | 2 | auto impl = conjunct->root()->get_impl(); |
325 | | // If impl is not null, which means this a conjuncts from runtime filter. |
326 | 2 | auto cur_expr = impl ? impl : conjunct->root(); |
327 | | |
328 | 2 | std::vector<int> slot_ids; |
329 | 2 | _get_slot_ids(cur_expr.get(), &slot_ids); |
330 | 2 | if (slot_ids.empty()) { |
331 | 1 | _not_single_slot_filter_conjuncts.emplace_back(conjunct); |
332 | 1 | continue; |
333 | 1 | } |
334 | 1 | bool single_slot = true; |
335 | 1 | for (int i = 1; i < slot_ids.size(); i++) { |
336 | 0 | if (slot_ids[i] != slot_ids[0]) { |
337 | 0 | single_slot = false; |
338 | 0 | break; |
339 | 0 | } |
340 | 0 | } |
341 | 1 | if (single_slot) { |
342 | 1 | SlotId slot_id = slot_ids[0]; |
343 | 1 | _slot_id_to_filter_conjuncts[slot_id].emplace_back(conjunct); |
344 | 1 | } else { |
345 | 0 | _not_single_slot_filter_conjuncts.emplace_back(conjunct); |
346 | 0 | } |
347 | 1 | } |
348 | 2 | return Status::OK(); |
349 | 2 | } |
350 | | |
351 | 196 | Status FileScanner::_process_late_arrival_conjuncts() { |
352 | 196 | if (_push_down_conjuncts.size() < _conjuncts.size()) { |
353 | 2 | _push_down_conjuncts = _conjuncts; |
354 | | // Do not clear _conjuncts here! |
355 | | // We must keep it for fallback filtering, especially when mixing |
356 | | // Native readers (which use _push_down_conjuncts) and JNI readers (which rely on _conjuncts). |
357 | | // _conjuncts.clear(); |
358 | 2 | RETURN_IF_ERROR(_process_conjuncts()); |
359 | 2 | } |
360 | 196 | if (_applied_rf_num == _total_rf_num) { |
361 | 196 | _local_state->scanner_profile()->add_info_string("ApplyAllRuntimeFilters", "True"); |
362 | 196 | } |
363 | 196 | return Status::OK(); |
364 | 196 | } |
365 | | |
366 | 2 | void FileScanner::_get_slot_ids(VExpr* expr, std::vector<int>* slot_ids) { |
367 | 2 | for (auto& child_expr : expr->children()) { |
368 | 1 | if (child_expr->is_slot_ref()) { |
369 | 1 | VSlotRef* slot_ref = reinterpret_cast<VSlotRef*>(child_expr.get()); |
370 | 1 | SlotDescriptor* slot_desc = _state->desc_tbl().get_slot_descriptor(slot_ref->slot_id()); |
371 | 1 | slot_desc->set_is_predicate(true); |
372 | 1 | slot_ids->emplace_back(slot_ref->slot_id()); |
373 | 1 | } else { |
374 | 0 | _get_slot_ids(child_expr.get(), slot_ids); |
375 | 0 | } |
376 | 1 | } |
377 | 2 | } |
378 | | |
379 | 2.65k | Status FileScanner::_open_impl(RuntimeState* state) { |
380 | 2.65k | RETURN_IF_CANCELLED(state); |
381 | 2.65k | RETURN_IF_ERROR(Scanner::_open_impl(state)); |
382 | 2.65k | if (_local_state) { |
383 | 2.65k | _condition_cache_digest = _local_state->get_condition_cache_digest(); |
384 | 2.65k | } |
385 | 2.65k | RETURN_IF_ERROR(_split_source->get_next(&_first_scan_range, &_current_range)); |
386 | 2.65k | if (_first_scan_range) { |
387 | 2.65k | RETURN_IF_ERROR(_init_expr_ctxes()); |
388 | 2.65k | if (_state->query_options().enable_runtime_filter_partition_prune && |
389 | 2.65k | !_partition_slot_index_map.empty()) { |
390 | 6 | _init_runtime_filter_partition_prune_ctxs(); |
391 | 6 | _init_runtime_filter_partition_prune_block(); |
392 | 6 | } |
393 | 2.65k | } else { |
394 | | // there's no scan range in split source. stop scanner directly. |
395 | 2 | _scanner_eof = true; |
396 | 2 | } |
397 | | |
398 | 2.65k | return Status::OK(); |
399 | 2.65k | } |
400 | | |
401 | 10.9k | Status FileScanner::_get_block_impl(RuntimeState* state, Block* block, bool* eof) { |
402 | 10.9k | Status st = _get_block_wrapped(state, block, eof); |
403 | | |
404 | 10.9k | if (!st.ok()) { |
405 | | // add cur path in error msg for easy debugging |
406 | 14 | return std::move(st.append(". cur path: " + get_current_scan_range_name())); |
407 | 14 | } |
408 | 10.9k | return st; |
409 | 10.9k | } |
410 | | |
411 | | // For query: |
412 | | // [exist cols] [non-exist cols] [col from path] input output |
413 | | // A B C D E |
414 | | // _init_src_block x x x x x - x |
415 | | // get_next_block x x x - - - x |
416 | | // _cast_to_input_block - - - - - - - |
417 | | // _fill_columns_from_path - - - - x - x |
418 | | // _fill_missing_columns - - - x - - x |
419 | | // _convert_to_output_block - - - - - - - |
420 | | // |
421 | | // For load: |
422 | | // [exist cols] [non-exist cols] [col from path] input output |
423 | | // A B C D E |
424 | | // _init_src_block x x x x x x - |
425 | | // get_next_block x x x - - x - |
426 | | // _cast_to_input_block x x x - - x - |
427 | | // _fill_columns_from_path - - - - x x - |
428 | | // _fill_missing_columns - - - x - x - |
429 | | // _convert_to_output_block - - - - - - x |
430 | 10.9k | Status FileScanner::_get_block_wrapped(RuntimeState* state, Block* block, bool* eof) { |
431 | 10.9k | do { |
432 | 10.9k | RETURN_IF_CANCELLED(state); |
433 | 10.9k | if (_cur_reader == nullptr || _cur_reader_eof) { |
434 | 5.30k | _finalize_reader_condition_cache(); |
435 | | // The file may not exist because the file list is got from meta cache, |
436 | | // And the file may already be removed from storage. |
437 | | // Just ignore not found files. |
438 | 5.30k | Status st = _get_next_reader(); |
439 | 5.30k | if (st.is<ErrorCode::NOT_FOUND>() && config::ignore_not_found_file_in_external_table) { |
440 | 0 | _cur_reader_eof = true; |
441 | 0 | COUNTER_UPDATE(_not_found_file_counter, 1); |
442 | 0 | continue; |
443 | 5.30k | } else if (st.is<ErrorCode::END_OF_FILE>()) { |
444 | 0 | _cur_reader_eof = true; |
445 | 0 | COUNTER_UPDATE(_fully_skipped_file_counter, 1); |
446 | 0 | continue; |
447 | 5.30k | } else if (!st) { |
448 | 2 | return st; |
449 | 2 | } |
450 | 5.30k | _init_reader_condition_cache(); |
451 | 5.30k | } |
452 | | |
453 | 10.9k | if (_scanner_eof) { |
454 | 2.64k | *eof = true; |
455 | 2.64k | return Status::OK(); |
456 | 2.64k | } |
457 | | |
458 | | // Init src block for load job based on the data file schema (e.g. parquet) |
459 | | // For query job, simply set _src_block_ptr to block. |
460 | 8.30k | size_t read_rows = 0; |
461 | 8.30k | RETURN_IF_ERROR(_init_src_block(block)); |
462 | 8.30k | if (_need_iceberg_rowid_column && _current_range.__isset.table_format_params && |
463 | 8.30k | _current_range.table_format_params.table_format_type == "iceberg") { |
464 | 0 | if (auto* iceberg_reader = dynamic_cast<IcebergTableReader*>(_cur_reader.get())) { |
465 | 0 | iceberg_reader->set_row_id_column_position(_iceberg_rowid_column_pos); |
466 | 0 | } |
467 | 0 | } |
468 | 8.30k | { |
469 | 8.30k | SCOPED_TIMER(_get_block_timer); |
470 | | |
471 | | // Read next block. |
472 | | // Some of column in block may not be filled (column not exist in file) |
473 | 8.30k | RETURN_IF_ERROR( |
474 | 8.30k | _cur_reader->get_next_block(_src_block_ptr, &read_rows, &_cur_reader_eof)); |
475 | 8.30k | } |
476 | | // use read_rows instead of _src_block_ptr->rows(), because the first column of _src_block_ptr |
477 | | // may not be filled after calling `get_next_block()`, so _src_block_ptr->rows() may return wrong result. |
478 | 8.29k | if (read_rows > 0) { |
479 | 5.74k | if ((!_cur_reader->count_read_rows()) && _io_ctx) { |
480 | 5.45k | _io_ctx->file_reader_stats->read_rows += read_rows; |
481 | 5.45k | } |
482 | | // If the push_down_agg_type is COUNT, no need to do the rest, |
483 | | // because we only save a number in block. |
484 | 5.74k | if (_get_push_down_agg_type() != TPushAggOp::type::COUNT) { |
485 | | // Convert the src block columns type to string in-place. |
486 | 5.74k | RETURN_IF_ERROR(_cast_to_input_block(block)); |
487 | | // FileReader can fill partition and missing columns itself |
488 | 5.74k | if (!_cur_reader->fill_all_columns()) { |
489 | | // Fill rows in src block with partition columns from path. (e.g. Hive partition columns) |
490 | 5.47k | RETURN_IF_ERROR(_fill_columns_from_path(read_rows)); |
491 | | // Fill columns not exist in file with null or default value |
492 | 5.47k | RETURN_IF_ERROR(_fill_missing_columns(read_rows)); |
493 | 5.47k | } |
494 | | // Apply _pre_conjunct_ctxs to filter src block. |
495 | 5.74k | RETURN_IF_ERROR(_pre_filter_src_block()); |
496 | | |
497 | | // Convert src block to output block (dest block), string to dest data type and apply filters. |
498 | 5.74k | RETURN_IF_ERROR(_convert_to_output_block(block)); |
499 | | // Truncate char columns or varchar columns if size is smaller than file columns |
500 | | // or not found in the file column schema. |
501 | 5.74k | RETURN_IF_ERROR(_truncate_char_or_varchar_columns(block)); |
502 | 5.74k | } |
503 | 5.74k | } |
504 | 8.29k | break; |
505 | 8.29k | } while (true); |
506 | | |
507 | | // Update filtered rows and unselected rows for load, reset counter. |
508 | | // { |
509 | | // state->update_num_rows_load_filtered(_counter.num_rows_filtered); |
510 | | // state->update_num_rows_load_unselected(_counter.num_rows_unselected); |
511 | | // _reset_counter(); |
512 | | // } |
513 | 8.29k | return Status::OK(); |
514 | 10.9k | } |
515 | | |
516 | | /** |
517 | | * Check whether there are complex types in parquet/orc reader in broker/stream load. |
518 | | * Broker/stream load will cast any type as string type, and complex types will be casted wrong. |
519 | | * This is a temporary method, and will be replaced by tvf. |
520 | | */ |
521 | 7.11k | Status FileScanner::_check_output_block_types() { |
522 | 7.11k | if (_is_load) { |
523 | 7.11k | TFileFormatType::type format_type = _params->format_type; |
524 | 7.11k | if (format_type == TFileFormatType::FORMAT_PARQUET || |
525 | 7.11k | format_type == TFileFormatType::FORMAT_ORC) { |
526 | 1.21k | for (auto slot : _output_tuple_desc->slots()) { |
527 | 1.21k | if (is_complex_type(slot->type()->get_primitive_type())) { |
528 | 0 | return Status::InternalError( |
529 | 0 | "Parquet/orc doesn't support complex types in broker/stream load, " |
530 | 0 | "please use tvf(table value function) to insert complex types."); |
531 | 0 | } |
532 | 1.21k | } |
533 | 42 | } |
534 | 7.11k | } |
535 | 7.11k | return Status::OK(); |
536 | 7.11k | } |
537 | | |
538 | 8.30k | Status FileScanner::_init_src_block(Block* block) { |
539 | 8.30k | if (!_is_load) { |
540 | 1.18k | _src_block_ptr = block; |
541 | | |
542 | 1.18k | bool update_name_to_idx = _src_block_name_to_idx.empty(); |
543 | 1.18k | _iceberg_rowid_column_pos = -1; |
544 | 1.18k | if (_need_iceberg_rowid_column && _current_range.__isset.table_format_params && |
545 | 1.18k | _current_range.table_format_params.table_format_type == "iceberg") { |
546 | 0 | int row_id_idx = block->get_position_by_name(BeConsts::ICEBERG_ROWID_COL); |
547 | 0 | if (row_id_idx >= 0) { |
548 | 0 | _iceberg_rowid_column_pos = row_id_idx; |
549 | 0 | if (!update_name_to_idx && |
550 | 0 | !_src_block_name_to_idx.contains(BeConsts::ICEBERG_ROWID_COL)) { |
551 | 0 | update_name_to_idx = true; |
552 | 0 | } |
553 | 0 | } |
554 | 0 | } |
555 | | |
556 | | // Build name to index map only once on first call |
557 | 1.18k | if (update_name_to_idx) { |
558 | 563 | _src_block_name_to_idx = block->get_name_to_pos_map(); |
559 | 563 | } |
560 | 1.18k | return Status::OK(); |
561 | 1.18k | } |
562 | 7.11k | RETURN_IF_ERROR(_check_output_block_types()); |
563 | | |
564 | | // if (_src_block_init) { |
565 | | // _src_block.clear_column_data(); |
566 | | // _src_block_ptr = &_src_block; |
567 | | // return Status::OK(); |
568 | | // } |
569 | | |
570 | 7.11k | _src_block.clear(); |
571 | 7.11k | uint32_t idx = 0; |
572 | | // slots in _input_tuple_desc contains all slots describe in load statement, eg: |
573 | | // -H "columns: k1, k2, tmp1, k3 = tmp1 + 1" |
574 | | // _input_tuple_desc will contains: k1, k2, tmp1 |
575 | | // and some of them are from file, such as k1 and k2, and some of them may not exist in file, such as tmp1 |
576 | | // _input_tuple_desc also contains columns from path |
577 | 79.0k | for (auto& slot : _input_tuple_desc->slots()) { |
578 | 79.0k | DataTypePtr data_type; |
579 | 79.0k | auto it = _slot_lower_name_to_col_type.find(slot->col_name()); |
580 | 79.0k | if (slot->is_skip_bitmap_col()) { |
581 | 314 | _skip_bitmap_col_idx = idx; |
582 | 314 | } |
583 | 79.0k | if (_params->__isset.sequence_map_col) { |
584 | 1.25k | if (_params->sequence_map_col == slot->col_name()) { |
585 | 198 | _sequence_map_col_uid = slot->col_unique_id(); |
586 | 198 | } |
587 | 1.25k | } |
588 | 79.0k | data_type = |
589 | 79.0k | it == _slot_lower_name_to_col_type.end() ? slot->type() : make_nullable(it->second); |
590 | 79.0k | MutableColumnPtr data_column = data_type->create_column(); |
591 | 79.0k | _src_block.insert( |
592 | 79.0k | ColumnWithTypeAndName(std::move(data_column), data_type, slot->col_name())); |
593 | 79.0k | _src_block_name_to_idx.emplace(slot->col_name(), idx++); |
594 | 79.0k | } |
595 | 7.11k | if (_params->__isset.sequence_map_col) { |
596 | 1.76k | for (const auto& slot : _output_tuple_desc->slots()) { |
597 | | // When the target table has seqeunce map column, _input_tuple_desc will not contains __DORIS_SEQUENCE_COL__, |
598 | | // so we should get its column unique id from _output_tuple_desc |
599 | 1.76k | if (slot->is_sequence_col()) { |
600 | 206 | _sequence_col_uid = slot->col_unique_id(); |
601 | 206 | } |
602 | 1.76k | } |
603 | 242 | } |
604 | 7.11k | _src_block_ptr = &_src_block; |
605 | 7.11k | _src_block_init = true; |
606 | 7.11k | return Status::OK(); |
607 | 7.11k | } |
608 | | |
609 | 5.74k | Status FileScanner::_cast_to_input_block(Block* block) { |
610 | 5.74k | if (!_is_load) { |
611 | 740 | return Status::OK(); |
612 | 740 | } |
613 | 5.00k | SCOPED_TIMER(_cast_to_input_block_timer); |
614 | | // cast primitive type(PT0) to primitive type(PT1) |
615 | 5.00k | uint32_t idx = 0; |
616 | 61.3k | for (auto& slot_desc : _input_tuple_desc->slots()) { |
617 | 61.3k | if (_slot_lower_name_to_col_type.find(slot_desc->col_name()) == |
618 | 61.3k | _slot_lower_name_to_col_type.end()) { |
619 | | // skip columns which does not exist in file |
620 | 336 | continue; |
621 | 336 | } |
622 | 61.0k | auto& arg = _src_block_ptr->get_by_position(_src_block_name_to_idx[slot_desc->col_name()]); |
623 | 61.0k | auto return_type = slot_desc->get_data_type_ptr(); |
624 | | // remove nullable here, let the get_function decide whether nullable |
625 | 61.0k | auto data_type = get_data_type_with_default_argument(remove_nullable(return_type)); |
626 | 61.0k | ColumnsWithTypeAndName arguments { |
627 | 61.0k | arg, {data_type->create_column(), data_type, slot_desc->col_name()}}; |
628 | 61.0k | auto func_cast = |
629 | 61.0k | SimpleFunctionFactory::instance().get_function("CAST", arguments, return_type, {}); |
630 | 61.0k | if (!func_cast) { |
631 | 0 | return Status::InternalError("Function CAST[arg={}, col name={}, return={}] not found!", |
632 | 0 | arg.type->get_name(), slot_desc->col_name(), |
633 | 0 | return_type->get_name()); |
634 | 0 | } |
635 | 61.0k | idx = _src_block_name_to_idx[slot_desc->col_name()]; |
636 | 61.0k | DCHECK(_state != nullptr); |
637 | 61.0k | auto ctx = FunctionContext::create_context(_state, {}, {}); |
638 | 61.0k | RETURN_IF_ERROR( |
639 | 61.0k | func_cast->execute(ctx.get(), *_src_block_ptr, {idx}, idx, arg.column->size())); |
640 | 61.0k | _src_block_ptr->get_by_position(idx).type = std::move(return_type); |
641 | 61.0k | } |
642 | 5.00k | return Status::OK(); |
643 | 5.00k | } |
644 | | |
645 | 5.47k | Status FileScanner::_fill_columns_from_path(size_t rows) { |
646 | 5.47k | if (!_fill_partition_from_path) { |
647 | 0 | return Status::OK(); |
648 | 0 | } |
649 | 5.47k | DataTypeSerDe::FormatOptions _text_formatOptions; |
650 | 5.47k | for (auto& kv : _partition_col_descs) { |
651 | 7 | auto doris_column = |
652 | 7 | _src_block_ptr->get_by_position(_src_block_name_to_idx[kv.first]).column; |
653 | | // _src_block_ptr points to a mutable block created by this class itself, so const_cast can be used here. |
654 | 7 | IColumn* col_ptr = const_cast<IColumn*>(doris_column.get()); |
655 | 7 | auto& [value, slot_desc] = kv.second; |
656 | 7 | auto _text_serde = slot_desc->get_data_type_ptr()->get_serde(); |
657 | 7 | Slice slice(value.data(), value.size()); |
658 | 7 | uint64_t num_deserialized = 0; |
659 | 7 | if (_text_serde->deserialize_column_from_fixed_json(*col_ptr, slice, rows, |
660 | 7 | &num_deserialized, |
661 | 7 | _text_formatOptions) != Status::OK()) { |
662 | 0 | return Status::InternalError("Failed to fill partition column: {}={}", |
663 | 0 | slot_desc->col_name(), value); |
664 | 0 | } |
665 | 7 | if (num_deserialized != rows) { |
666 | 0 | return Status::InternalError( |
667 | 0 | "Failed to fill partition column: {}={} ." |
668 | 0 | "Number of rows expected to be written : {}, number of rows actually written : " |
669 | 0 | "{}", |
670 | 0 | slot_desc->col_name(), value, num_deserialized, rows); |
671 | 0 | } |
672 | 7 | } |
673 | 5.47k | return Status::OK(); |
674 | 5.47k | } |
675 | | |
676 | 5.47k | Status FileScanner::_fill_missing_columns(size_t rows) { |
677 | 5.47k | if (_missing_cols.empty()) { |
678 | 5.47k | return Status::OK(); |
679 | 5.47k | } |
680 | | |
681 | 0 | SCOPED_TIMER(_fill_missing_columns_timer); |
682 | 0 | for (auto& kv : _missing_col_descs) { |
683 | 0 | if (kv.second == nullptr) { |
684 | | // no default column, fill with null |
685 | 0 | auto mutable_column = _src_block_ptr->get_by_position(_src_block_name_to_idx[kv.first]) |
686 | 0 | .column->assume_mutable(); |
687 | 0 | auto* nullable_column = static_cast<ColumnNullable*>(mutable_column.get()); |
688 | 0 | nullable_column->insert_many_defaults(rows); |
689 | 0 | } else { |
690 | | // fill with default value |
691 | 0 | auto& ctx = kv.second; |
692 | 0 | ColumnPtr result_column_ptr; |
693 | | // PT1 => dest primitive type |
694 | 0 | RETURN_IF_ERROR(ctx->execute(_src_block_ptr, result_column_ptr)); |
695 | 0 | if (result_column_ptr->use_count() == 1) { |
696 | | // call resize because the first column of _src_block_ptr may not be filled by reader, |
697 | | // so _src_block_ptr->rows() may return wrong result, cause the column created by `ctx->execute()` |
698 | | // has only one row. |
699 | 0 | auto mutable_column = result_column_ptr->assume_mutable(); |
700 | 0 | mutable_column->resize(rows); |
701 | | // result_column_ptr maybe a ColumnConst, convert it to a normal column |
702 | 0 | result_column_ptr = result_column_ptr->convert_to_full_column_if_const(); |
703 | 0 | auto origin_column_type = |
704 | 0 | _src_block_ptr->get_by_position(_src_block_name_to_idx[kv.first]).type; |
705 | 0 | bool is_nullable = origin_column_type->is_nullable(); |
706 | 0 | if (!_src_block_name_to_idx.contains(kv.first)) { |
707 | 0 | return Status::InternalError("Column {} not found in src block {}", kv.first, |
708 | 0 | _src_block_ptr->dump_structure()); |
709 | 0 | } |
710 | 0 | _src_block_ptr->replace_by_position( |
711 | 0 | _src_block_name_to_idx[kv.first], |
712 | 0 | is_nullable ? make_nullable(result_column_ptr) : result_column_ptr); |
713 | 0 | } |
714 | 0 | } |
715 | 0 | } |
716 | 0 | return Status::OK(); |
717 | 0 | } |
718 | | |
719 | 5.74k | Status FileScanner::_pre_filter_src_block() { |
720 | 5.74k | if (!_is_load) { |
721 | 740 | return Status::OK(); |
722 | 740 | } |
723 | 5.00k | if (!_pre_conjunct_ctxs.empty()) { |
724 | 28 | SCOPED_TIMER(_pre_filter_timer); |
725 | 28 | auto origin_column_num = _src_block_ptr->columns(); |
726 | 28 | auto old_rows = _src_block_ptr->rows(); |
727 | 28 | RETURN_IF_ERROR( |
728 | 28 | VExprContext::filter_block(_pre_conjunct_ctxs, _src_block_ptr, origin_column_num)); |
729 | 28 | _counter.num_rows_unselected += old_rows - _src_block_ptr->rows(); |
730 | 28 | } |
731 | 5.00k | return Status::OK(); |
732 | 5.00k | } |
733 | | |
734 | 5.74k | Status FileScanner::_convert_to_output_block(Block* block) { |
735 | 5.74k | if (!_is_load) { |
736 | 740 | return Status::OK(); |
737 | 740 | } |
738 | 5.00k | SCOPED_TIMER(_convert_to_output_block_timer); |
739 | | // The block is passed from scanner context's free blocks, |
740 | | // which is initialized by output columns |
741 | | // so no need to clear it |
742 | | // block->clear(); |
743 | | |
744 | 5.00k | int ctx_idx = 0; |
745 | 5.00k | size_t rows = _src_block_ptr->rows(); |
746 | 5.00k | auto filter_column = ColumnUInt8::create(rows, 1); |
747 | 5.00k | auto& filter_map = filter_column->get_data(); |
748 | | |
749 | | // After convert, the column_ptr should be copied into output block. |
750 | | // Can not use block->insert() because it may cause use_count() non-zero bug |
751 | 5.00k | MutableBlock mutable_output_block = |
752 | 5.00k | VectorizedUtils::build_mutable_mem_reuse_block(block, *_dest_row_desc); |
753 | 5.00k | auto& mutable_output_columns = mutable_output_block.mutable_columns(); |
754 | | |
755 | 5.00k | std::vector<BitmapValue>* skip_bitmaps {nullptr}; |
756 | 5.00k | if (_should_process_skip_bitmap_col()) { |
757 | 157 | auto* skip_bitmap_nullable_col_ptr = |
758 | 157 | assert_cast<ColumnNullable*>(_src_block_ptr->get_by_position(_skip_bitmap_col_idx) |
759 | 157 | .column->assume_mutable() |
760 | 157 | .get()); |
761 | 157 | skip_bitmaps = &(assert_cast<ColumnBitmap*>( |
762 | 157 | skip_bitmap_nullable_col_ptr->get_nested_column_ptr().get()) |
763 | 157 | ->get_data()); |
764 | | // NOTE: |
765 | | // - If the table has sequence type column, __DORIS_SEQUENCE_COL__ will be put in _input_tuple_desc, so whether |
766 | | // __DORIS_SEQUENCE_COL__ will be marked in skip bitmap depends on whether it's specified in that row |
767 | | // - If the table has sequence map column, __DORIS_SEQUENCE_COL__ will not be put in _input_tuple_desc, |
768 | | // so __DORIS_SEQUENCE_COL__ will be ommited if it't specified in a row and will not be marked in skip bitmap. |
769 | | // So we should mark __DORIS_SEQUENCE_COL__ in skip bitmap here if the corresponding sequence map column us marked |
770 | 157 | if (_sequence_map_col_uid != -1) { |
771 | 347 | for (int j = 0; j < rows; ++j) { |
772 | 328 | if ((*skip_bitmaps)[j].contains(_sequence_map_col_uid)) { |
773 | 137 | (*skip_bitmaps)[j].add(_sequence_col_uid); |
774 | 137 | } |
775 | 328 | } |
776 | 19 | } |
777 | 157 | } |
778 | | |
779 | | // for (auto slot_desc : _output_tuple_desc->slots()) { |
780 | 71.6k | for (int j = 0; j < mutable_output_columns.size(); ++j) { |
781 | 66.6k | auto* slot_desc = _output_tuple_desc->slots()[j]; |
782 | 66.6k | int dest_index = ctx_idx; |
783 | 66.6k | ColumnPtr column_ptr; |
784 | | |
785 | 66.6k | auto& ctx = _dest_vexpr_ctx[dest_index]; |
786 | | // PT1 => dest primitive type |
787 | 66.6k | RETURN_IF_ERROR(ctx->execute(_src_block_ptr, column_ptr)); |
788 | | // column_ptr maybe a ColumnConst, convert it to a normal column |
789 | 66.6k | column_ptr = column_ptr->convert_to_full_column_if_const(); |
790 | 66.6k | DCHECK(column_ptr); |
791 | | |
792 | | // because of src_slot_desc is always be nullable, so the column_ptr after do dest_expr |
793 | | // is likely to be nullable |
794 | 66.6k | if (LIKELY(column_ptr->is_nullable())) { |
795 | 61.6k | const auto* nullable_column = reinterpret_cast<const ColumnNullable*>(column_ptr.get()); |
796 | 172M | for (int i = 0; i < rows; ++i) { |
797 | 172M | if (filter_map[i] && nullable_column->is_null_at(i)) { |
798 | | // skip checks for non-mentioned columns in flexible partial update |
799 | 1.79M | if (skip_bitmaps == nullptr || |
800 | 1.79M | !skip_bitmaps->at(i).contains(slot_desc->col_unique_id())) { |
801 | | // clang-format off |
802 | 1.74M | if (_strict_mode && (_src_slot_descs_order_by_dest[dest_index]) && |
803 | 1.74M | !_src_block_ptr->get_by_position(_dest_slot_to_src_slot_index[dest_index]).column->is_null_at(i)) { |
804 | 5.48k | filter_map[i] = false; |
805 | 5.48k | RETURN_IF_ERROR(_state->append_error_msg_to_file( |
806 | 5.48k | [&]() -> std::string { |
807 | 5.48k | return _src_block_ptr->dump_one_line(i, _num_of_columns_from_file); |
808 | 5.48k | }, |
809 | 5.48k | [&]() -> std::string { |
810 | 5.48k | auto raw_value = |
811 | 5.48k | _src_block_ptr->get_by_position(_dest_slot_to_src_slot_index[dest_index]).column->get_data_at(i); |
812 | 5.48k | std::string raw_string = raw_value.to_string(); |
813 | 5.48k | fmt::memory_buffer error_msg; |
814 | 5.48k | fmt::format_to(error_msg,"column({}) value is incorrect while strict mode is {}, src value is {}", |
815 | 5.48k | slot_desc->col_name(), _strict_mode, raw_string); |
816 | 5.48k | return fmt::to_string(error_msg); |
817 | 5.48k | })); |
818 | 1.73M | } else if (!slot_desc->is_nullable()) { |
819 | 638 | filter_map[i] = false; |
820 | 638 | RETURN_IF_ERROR(_state->append_error_msg_to_file( |
821 | 638 | [&]() -> std::string { |
822 | 638 | return _src_block_ptr->dump_one_line(i, _num_of_columns_from_file); |
823 | 638 | }, |
824 | 638 | [&]() -> std::string { |
825 | 638 | fmt::memory_buffer error_msg; |
826 | 638 | fmt::format_to(error_msg, "column({}) values is null while columns is not nullable", slot_desc->col_name()); |
827 | 638 | return fmt::to_string(error_msg); |
828 | 638 | })); |
829 | 638 | } |
830 | | // clang-format on |
831 | 1.74M | } |
832 | 1.79M | } |
833 | 172M | } |
834 | 61.6k | if (!slot_desc->is_nullable()) { |
835 | 41.8k | column_ptr = remove_nullable(column_ptr); |
836 | 41.8k | } |
837 | 61.6k | } else if (slot_desc->is_nullable()) { |
838 | 115 | column_ptr = make_nullable(column_ptr); |
839 | 115 | } |
840 | 66.6k | mutable_output_columns[j]->insert_range_from(*column_ptr, 0, rows); |
841 | 66.6k | ctx_idx++; |
842 | 66.6k | } |
843 | | |
844 | | // after do the dest block insert operation, clear _src_block to remove the reference of origin column |
845 | 5.00k | _src_block_ptr->clear(); |
846 | | |
847 | 5.00k | size_t dest_size = block->columns(); |
848 | | // do filter |
849 | 5.00k | block->insert(ColumnWithTypeAndName(std::move(filter_column), std::make_shared<DataTypeUInt8>(), |
850 | 5.00k | "filter column")); |
851 | 5.00k | RETURN_IF_ERROR(Block::filter_block(block, dest_size, dest_size)); |
852 | | |
853 | 5.00k | _counter.num_rows_filtered += rows - block->rows(); |
854 | 5.00k | return Status::OK(); |
855 | 5.00k | } |
856 | | |
857 | 5.74k | Status FileScanner::_truncate_char_or_varchar_columns(Block* block) { |
858 | | // Truncate char columns or varchar columns if size is smaller than file columns |
859 | | // or not found in the file column schema. |
860 | 5.74k | if (!_state->query_options().truncate_char_or_varchar_columns) { |
861 | 5.74k | return Status::OK(); |
862 | 5.74k | } |
863 | 1 | int idx = 0; |
864 | 1 | for (auto* slot_desc : _real_tuple_desc->slots()) { |
865 | 0 | const auto& type = slot_desc->type(); |
866 | 0 | if (type->get_primitive_type() != TYPE_VARCHAR && type->get_primitive_type() != TYPE_CHAR) { |
867 | 0 | ++idx; |
868 | 0 | continue; |
869 | 0 | } |
870 | 0 | auto iter = _source_file_col_name_types.find(slot_desc->col_name()); |
871 | 0 | if (iter != _source_file_col_name_types.end()) { |
872 | 0 | const auto file_type_desc = _source_file_col_name_types[slot_desc->col_name()]; |
873 | 0 | int l = -1; |
874 | 0 | if (auto* ftype = check_and_get_data_type<DataTypeString>( |
875 | 0 | remove_nullable(file_type_desc).get())) { |
876 | 0 | l = ftype->len(); |
877 | 0 | } |
878 | 0 | if ((assert_cast<const DataTypeString*>(remove_nullable(type).get())->len() > 0) && |
879 | 0 | (assert_cast<const DataTypeString*>(remove_nullable(type).get())->len() < l || |
880 | 0 | l < 0)) { |
881 | 0 | _truncate_char_or_varchar_column( |
882 | 0 | block, idx, |
883 | 0 | assert_cast<const DataTypeString*>(remove_nullable(type).get())->len()); |
884 | 0 | } |
885 | 0 | } else { |
886 | 0 | _truncate_char_or_varchar_column( |
887 | 0 | block, idx, |
888 | 0 | assert_cast<const DataTypeString*>(remove_nullable(type).get())->len()); |
889 | 0 | } |
890 | 0 | ++idx; |
891 | 0 | } |
892 | 1 | return Status::OK(); |
893 | 5.74k | } |
894 | | |
895 | | // VARCHAR substring(VARCHAR str, INT pos[, INT len]) |
896 | 0 | void FileScanner::_truncate_char_or_varchar_column(Block* block, int idx, int len) { |
897 | 0 | auto int_type = std::make_shared<DataTypeInt32>(); |
898 | 0 | uint32_t num_columns_without_result = block->columns(); |
899 | 0 | const ColumnNullable* col_nullable = |
900 | 0 | assert_cast<const ColumnNullable*>(block->get_by_position(idx).column.get()); |
901 | 0 | const ColumnPtr& string_column_ptr = col_nullable->get_nested_column_ptr(); |
902 | 0 | ColumnPtr null_map_column_ptr = col_nullable->get_null_map_column_ptr(); |
903 | 0 | block->replace_by_position(idx, std::move(string_column_ptr)); |
904 | 0 | block->insert({int_type->create_column_const(block->rows(), to_field<TYPE_INT>(1)), int_type, |
905 | 0 | "const 1"}); // pos is 1 |
906 | 0 | block->insert({int_type->create_column_const(block->rows(), to_field<TYPE_INT>(len)), int_type, |
907 | 0 | fmt::format("const {}", len)}); // len |
908 | 0 | block->insert({nullptr, std::make_shared<DataTypeString>(), "result"}); // result column |
909 | 0 | ColumnNumbers temp_arguments(3); |
910 | 0 | temp_arguments[0] = idx; // str column |
911 | 0 | temp_arguments[1] = num_columns_without_result; // pos |
912 | 0 | temp_arguments[2] = num_columns_without_result + 1; // len |
913 | 0 | uint32_t result_column_id = num_columns_without_result + 2; |
914 | |
|
915 | 0 | SubstringUtil::substring_execute(*block, temp_arguments, result_column_id, block->rows()); |
916 | 0 | auto res = ColumnNullable::create(block->get_by_position(result_column_id).column, |
917 | 0 | null_map_column_ptr); |
918 | 0 | block->replace_by_position(idx, std::move(res)); |
919 | 0 | Block::erase_useless_column(block, num_columns_without_result); |
920 | 0 | } |
921 | | |
922 | 13 | Status FileScanner::_create_row_id_column_iterator() { |
923 | 13 | auto& id_file_map = _state->get_id_file_map(); |
924 | 13 | auto file_id = id_file_map->get_file_mapping_id( |
925 | 13 | std::make_shared<FileMapping>(((FileScanLocalState*)_local_state)->parent_id(), |
926 | 13 | _current_range, _should_enable_file_meta_cache())); |
927 | 13 | _row_id_column_iterator_pair.first = std::make_shared<RowIdColumnIteratorV2>( |
928 | 13 | IdManager::ID_VERSION, BackendOptions::get_backend_id(), file_id); |
929 | 13 | return Status::OK(); |
930 | 13 | } |
931 | | |
932 | 5.30k | Status FileScanner::_get_next_reader() { |
933 | 5.30k | while (true) { |
934 | 5.30k | if (_cur_reader) { |
935 | 2.64k | _cur_reader->collect_profile_before_close(); |
936 | 2.64k | RETURN_IF_ERROR(_cur_reader->close()); |
937 | 2.64k | _state->update_num_finished_scan_range(1); |
938 | 2.64k | } |
939 | 5.30k | _cur_reader.reset(nullptr); |
940 | 5.30k | _src_block_init = false; |
941 | 5.30k | bool has_next = _first_scan_range; |
942 | 5.30k | if (!_first_scan_range) { |
943 | 2.64k | RETURN_IF_ERROR(_split_source->get_next(&has_next, &_current_range)); |
944 | 2.64k | } |
945 | 5.30k | _first_scan_range = false; |
946 | 5.30k | if (!has_next || _should_stop) { |
947 | 2.64k | _scanner_eof = true; |
948 | 2.64k | return Status::OK(); |
949 | 2.64k | } |
950 | | |
951 | 2.65k | const TFileRangeDesc& range = _current_range; |
952 | 2.65k | _current_range_path = range.path; |
953 | | |
954 | 2.65k | if (!_partition_slot_descs.empty()) { |
955 | | // we need get partition columns first for runtime filter partition pruning |
956 | 6 | RETURN_IF_ERROR(_generate_partition_columns()); |
957 | | |
958 | 6 | if (_state->query_options().enable_runtime_filter_partition_prune) { |
959 | | // if enable_runtime_filter_partition_prune is true, we need to check whether this range can be filtered out |
960 | | // by runtime filter partition prune |
961 | 6 | if (_push_down_conjuncts.size() < _conjuncts.size()) { |
962 | | // there are new runtime filters, need to re-init runtime filter partition pruning ctxs |
963 | 0 | _init_runtime_filter_partition_prune_ctxs(); |
964 | 0 | } |
965 | | |
966 | 6 | bool can_filter_all = false; |
967 | 6 | RETURN_IF_ERROR(_process_runtime_filters_partition_prune(can_filter_all)); |
968 | 6 | if (can_filter_all) { |
969 | | // this range can be filtered out by runtime filter partition pruning |
970 | | // so we need to skip this range |
971 | 0 | COUNTER_UPDATE(_runtime_filter_partition_pruned_range_counter, 1); |
972 | 0 | continue; |
973 | 0 | } |
974 | 6 | } |
975 | 6 | } |
976 | | |
977 | | // create reader for specific format |
978 | 2.65k | Status init_status = Status::OK(); |
979 | 2.65k | TFileFormatType::type format_type = _get_current_format_type(); |
980 | | // for compatibility, this logic is deprecated in 3.1 |
981 | 2.65k | if (format_type == TFileFormatType::FORMAT_JNI && range.__isset.table_format_params) { |
982 | 4 | if (range.table_format_params.table_format_type == "paimon" && |
983 | 4 | !range.table_format_params.paimon_params.__isset.paimon_split) { |
984 | | // use native reader |
985 | 0 | auto format = range.table_format_params.paimon_params.file_format; |
986 | 0 | if (format == "orc") { |
987 | 0 | format_type = TFileFormatType::FORMAT_ORC; |
988 | 0 | } else if (format == "parquet") { |
989 | 0 | format_type = TFileFormatType::FORMAT_PARQUET; |
990 | 0 | } else { |
991 | 0 | return Status::InternalError("Not supported paimon file format: {}", format); |
992 | 0 | } |
993 | 0 | } |
994 | 4 | } |
995 | | |
996 | | // JNI reader can only push down column value range |
997 | 2.65k | bool push_down_predicates = !_is_load && format_type != TFileFormatType::FORMAT_JNI; |
998 | 2.65k | bool need_to_get_parsed_schema = false; |
999 | 2.65k | switch (format_type) { |
1000 | 5 | case TFileFormatType::FORMAT_JNI: { |
1001 | 5 | if (range.__isset.table_format_params && |
1002 | 5 | range.table_format_params.table_format_type == "max_compute") { |
1003 | 0 | const auto* mc_desc = static_cast<const MaxComputeTableDescriptor*>( |
1004 | 0 | _real_tuple_desc->table_desc()); |
1005 | 0 | if (!mc_desc->init_status()) { |
1006 | 0 | return mc_desc->init_status(); |
1007 | 0 | } |
1008 | 0 | std::unique_ptr<MaxComputeJniReader> mc_reader = MaxComputeJniReader::create_unique( |
1009 | 0 | mc_desc, range.table_format_params.max_compute_params, _file_slot_descs, |
1010 | 0 | range, _state, _profile); |
1011 | 0 | init_status = mc_reader->init_reader(); |
1012 | 0 | _cur_reader = std::move(mc_reader); |
1013 | 5 | } else if (range.__isset.table_format_params && |
1014 | 5 | range.table_format_params.table_format_type == "paimon") { |
1015 | 0 | if (_state->query_options().__isset.enable_paimon_cpp_reader && |
1016 | 0 | _state->query_options().enable_paimon_cpp_reader) { |
1017 | 0 | auto cpp_reader = PaimonCppReader::create_unique(_file_slot_descs, _state, |
1018 | 0 | _profile, range, _params); |
1019 | 0 | cpp_reader->set_push_down_agg_type(_get_push_down_agg_type()); |
1020 | 0 | if (!_is_load && !_push_down_conjuncts.empty()) { |
1021 | 0 | PaimonPredicateConverter predicate_converter(_file_slot_descs, _state); |
1022 | 0 | auto predicate = predicate_converter.build(_push_down_conjuncts); |
1023 | 0 | if (predicate) { |
1024 | 0 | cpp_reader->set_predicate(std::move(predicate)); |
1025 | 0 | } |
1026 | 0 | } |
1027 | 0 | init_status = cpp_reader->init_reader(); |
1028 | 0 | _cur_reader = std::move(cpp_reader); |
1029 | 0 | } else { |
1030 | 0 | _cur_reader = PaimonJniReader::create_unique(_file_slot_descs, _state, _profile, |
1031 | 0 | range, _params); |
1032 | 0 | init_status = ((PaimonJniReader*)(_cur_reader.get()))->init_reader(); |
1033 | 0 | } |
1034 | 5 | } else if (range.__isset.table_format_params && |
1035 | 5 | range.table_format_params.table_format_type == "hudi") { |
1036 | 0 | _cur_reader = HudiJniReader::create_unique(*_params, |
1037 | 0 | range.table_format_params.hudi_params, |
1038 | 0 | _file_slot_descs, _state, _profile); |
1039 | 0 | init_status = ((HudiJniReader*)_cur_reader.get())->init_reader(); |
1040 | |
|
1041 | 5 | } else if (range.__isset.table_format_params && |
1042 | 5 | range.table_format_params.table_format_type == "trino_connector") { |
1043 | 0 | _cur_reader = TrinoConnectorJniReader::create_unique(_file_slot_descs, _state, |
1044 | 0 | _profile, range); |
1045 | 0 | init_status = ((TrinoConnectorJniReader*)(_cur_reader.get()))->init_reader(); |
1046 | 5 | } else if (range.__isset.table_format_params && |
1047 | 5 | range.table_format_params.table_format_type == "jdbc") { |
1048 | | // Extract jdbc params from table_format_params |
1049 | 4 | std::map<std::string, std::string> jdbc_params( |
1050 | 4 | range.table_format_params.jdbc_params.begin(), |
1051 | 4 | range.table_format_params.jdbc_params.end()); |
1052 | 4 | _cur_reader = JdbcJniReader::create_unique(_file_slot_descs, _state, _profile, |
1053 | 4 | jdbc_params); |
1054 | 4 | init_status = ((JdbcJniReader*)(_cur_reader.get()))->init_reader(); |
1055 | 4 | } else if (range.__isset.table_format_params && |
1056 | 1 | range.table_format_params.table_format_type == "iceberg") { |
1057 | 0 | _cur_reader = IcebergSysTableJniReader::create_unique(_file_slot_descs, _state, |
1058 | 0 | _profile, range, _params); |
1059 | 0 | init_status = ((IcebergSysTableJniReader*)(_cur_reader.get()))->init_reader(); |
1060 | 0 | } |
1061 | | // Set col_name_to_block_idx for JNI readers to avoid repeated map creation |
1062 | 5 | if (_cur_reader) { |
1063 | 4 | if (auto* jni_reader = dynamic_cast<JniReader*>(_cur_reader.get())) { |
1064 | 4 | jni_reader->set_col_name_to_block_idx(&_src_block_name_to_idx); |
1065 | 4 | } |
1066 | 4 | } |
1067 | 5 | break; |
1068 | 5 | } |
1069 | 122 | case TFileFormatType::FORMAT_PARQUET: { |
1070 | 122 | auto file_meta_cache_ptr = _should_enable_file_meta_cache() |
1071 | 122 | ? ExecEnv::GetInstance()->file_meta_cache() |
1072 | 122 | : nullptr; |
1073 | 122 | std::unique_ptr<ParquetReader> parquet_reader = ParquetReader::create_unique( |
1074 | 122 | _profile, *_params, range, _state->query_options().batch_size, |
1075 | 122 | &_state->timezone_obj(), _io_ctx.get(), _state, file_meta_cache_ptr, |
1076 | 122 | _state->query_options().enable_parquet_lazy_mat); |
1077 | | |
1078 | 122 | if (_row_id_column_iterator_pair.second != -1) { |
1079 | 8 | RETURN_IF_ERROR(_create_row_id_column_iterator()); |
1080 | 8 | parquet_reader->set_row_id_column_iterator(_row_id_column_iterator_pair); |
1081 | 8 | } |
1082 | | |
1083 | | // ATTN: the push down agg type may be set back to NONE, |
1084 | | // see IcebergTableReader::init_row_filters for example. |
1085 | 122 | parquet_reader->set_push_down_agg_type(_get_push_down_agg_type()); |
1086 | 122 | if (push_down_predicates) { |
1087 | 104 | RETURN_IF_ERROR(_process_late_arrival_conjuncts()); |
1088 | 104 | } |
1089 | 122 | RETURN_IF_ERROR(_init_parquet_reader(std::move(parquet_reader), file_meta_cache_ptr)); |
1090 | | |
1091 | 122 | need_to_get_parsed_schema = true; |
1092 | 122 | break; |
1093 | 122 | } |
1094 | 102 | case TFileFormatType::FORMAT_ORC: { |
1095 | 102 | auto file_meta_cache_ptr = _should_enable_file_meta_cache() |
1096 | 102 | ? ExecEnv::GetInstance()->file_meta_cache() |
1097 | 102 | : nullptr; |
1098 | 102 | std::unique_ptr<OrcReader> orc_reader = OrcReader::create_unique( |
1099 | 102 | _profile, _state, *_params, range, _state->query_options().batch_size, |
1100 | 102 | _state->timezone(), _io_ctx.get(), file_meta_cache_ptr, |
1101 | 102 | _state->query_options().enable_orc_lazy_mat); |
1102 | 102 | if (_row_id_column_iterator_pair.second != -1) { |
1103 | 5 | RETURN_IF_ERROR(_create_row_id_column_iterator()); |
1104 | 5 | orc_reader->set_row_id_column_iterator(_row_id_column_iterator_pair); |
1105 | 5 | } |
1106 | | |
1107 | 102 | orc_reader->set_push_down_agg_type(_get_push_down_agg_type()); |
1108 | 102 | if (push_down_predicates) { |
1109 | 91 | RETURN_IF_ERROR(_process_late_arrival_conjuncts()); |
1110 | 91 | } |
1111 | 102 | RETURN_IF_ERROR(_init_orc_reader(std::move(orc_reader), file_meta_cache_ptr)); |
1112 | | |
1113 | 102 | need_to_get_parsed_schema = true; |
1114 | 102 | break; |
1115 | 102 | } |
1116 | 1.91k | case TFileFormatType::FORMAT_CSV_PLAIN: |
1117 | 1.91k | case TFileFormatType::FORMAT_CSV_GZ: |
1118 | 1.91k | case TFileFormatType::FORMAT_CSV_BZ2: |
1119 | 1.91k | case TFileFormatType::FORMAT_CSV_LZ4FRAME: |
1120 | 1.91k | case TFileFormatType::FORMAT_CSV_LZ4BLOCK: |
1121 | 1.91k | case TFileFormatType::FORMAT_CSV_LZOP: |
1122 | 1.91k | case TFileFormatType::FORMAT_CSV_DEFLATE: |
1123 | 1.91k | case TFileFormatType::FORMAT_CSV_SNAPPYBLOCK: |
1124 | 1.98k | case TFileFormatType::FORMAT_PROTO: { |
1125 | 1.98k | auto reader = CsvReader::create_unique(_state, _profile, &_counter, *_params, range, |
1126 | 1.98k | _file_slot_descs, _io_ctx.get()); |
1127 | | |
1128 | 1.98k | init_status = reader->init_reader(_is_load); |
1129 | 1.98k | _cur_reader = std::move(reader); |
1130 | 1.98k | break; |
1131 | 1.91k | } |
1132 | 3 | case TFileFormatType::FORMAT_TEXT: { |
1133 | 3 | auto reader = TextReader::create_unique(_state, _profile, &_counter, *_params, range, |
1134 | 3 | _file_slot_descs, _io_ctx.get()); |
1135 | 3 | init_status = reader->init_reader(_is_load); |
1136 | 3 | _cur_reader = std::move(reader); |
1137 | 3 | break; |
1138 | 1.91k | } |
1139 | 425 | case TFileFormatType::FORMAT_JSON: { |
1140 | 425 | _cur_reader = |
1141 | 425 | NewJsonReader::create_unique(_state, _profile, &_counter, *_params, range, |
1142 | 425 | _file_slot_descs, &_scanner_eof, _io_ctx.get()); |
1143 | 425 | init_status = ((NewJsonReader*)(_cur_reader.get())) |
1144 | 425 | ->init_reader(_col_default_value_ctx, _is_load); |
1145 | 425 | break; |
1146 | 1.91k | } |
1147 | | |
1148 | 0 | case TFileFormatType::FORMAT_WAL: { |
1149 | 0 | _cur_reader = WalReader::create_unique(_state); |
1150 | 0 | init_status = ((WalReader*)(_cur_reader.get()))->init_reader(_output_tuple_desc); |
1151 | 0 | break; |
1152 | 1.91k | } |
1153 | 3 | case TFileFormatType::FORMAT_NATIVE: { |
1154 | 3 | auto reader = |
1155 | 3 | NativeReader::create_unique(_profile, *_params, range, _io_ctx.get(), _state); |
1156 | 3 | init_status = reader->init_reader(); |
1157 | 3 | _cur_reader = std::move(reader); |
1158 | 3 | need_to_get_parsed_schema = false; |
1159 | 3 | break; |
1160 | 1.91k | } |
1161 | 10 | case TFileFormatType::FORMAT_ARROW: { |
1162 | 10 | if (range.__isset.table_format_params && |
1163 | 10 | range.table_format_params.table_format_type == "remote_doris") { |
1164 | 0 | _cur_reader = |
1165 | 0 | RemoteDorisReader::create_unique(_file_slot_descs, _state, _profile, range); |
1166 | 0 | init_status = ((RemoteDorisReader*)(_cur_reader.get()))->init_reader(); |
1167 | 0 | if (_cur_reader) { |
1168 | 0 | static_cast<RemoteDorisReader*>(_cur_reader.get()) |
1169 | 0 | ->set_col_name_to_block_idx(&_src_block_name_to_idx); |
1170 | 0 | } |
1171 | 10 | } else { |
1172 | 10 | _cur_reader = |
1173 | 10 | ArrowStreamReader::create_unique(_state, _profile, &_counter, *_params, |
1174 | 10 | range, _file_slot_descs, _io_ctx.get()); |
1175 | 10 | init_status = ((ArrowStreamReader*)(_cur_reader.get()))->init_reader(); |
1176 | 10 | } |
1177 | 10 | break; |
1178 | 1.91k | } |
1179 | 0 | default: |
1180 | 0 | return Status::NotSupported("Not supported create reader for file format: {}.", |
1181 | 0 | to_string(_params->format_type)); |
1182 | 2.65k | } |
1183 | | |
1184 | 2.65k | if (_cur_reader == nullptr) { |
1185 | 1 | return Status::NotSupported( |
1186 | 1 | "Not supported create reader for table format: {} / file format: {}.", |
1187 | 1 | range.__isset.table_format_params ? range.table_format_params.table_format_type |
1188 | 1 | : "NotSet", |
1189 | 1 | to_string(_params->format_type)); |
1190 | 1 | } |
1191 | 2.65k | COUNTER_UPDATE(_file_counter, 1); |
1192 | | // The FileScanner for external table may try to open not exist files, |
1193 | | // Because FE file cache for external table may out of date. |
1194 | | // So, NOT_FOUND for FileScanner is not a fail case. |
1195 | | // Will remove this after file reader refactor. |
1196 | 2.65k | if (init_status.is<END_OF_FILE>()) { |
1197 | 0 | COUNTER_UPDATE(_empty_file_counter, 1); |
1198 | 0 | continue; |
1199 | 2.65k | } else if (init_status.is<ErrorCode::NOT_FOUND>()) { |
1200 | 0 | if (config::ignore_not_found_file_in_external_table) { |
1201 | 0 | COUNTER_UPDATE(_not_found_file_counter, 1); |
1202 | 0 | continue; |
1203 | 0 | } |
1204 | 0 | return Status::InternalError("failed to find reader, err: {}", init_status.to_string()); |
1205 | 2.65k | } else if (!init_status.ok()) { |
1206 | 1 | return Status::InternalError("failed to init reader, err: {}", init_status.to_string()); |
1207 | 1 | } |
1208 | | |
1209 | 2.65k | _cur_reader->set_push_down_agg_type(_get_push_down_agg_type()); |
1210 | 2.65k | if (_get_push_down_agg_type() == TPushAggOp::type::COUNT && |
1211 | 2.65k | range.__isset.table_format_params && |
1212 | 2.65k | range.table_format_params.table_level_row_count >= 0) { |
1213 | | // This is a table level count push down operation, no need to call |
1214 | | // _set_fill_or_truncate_columns. |
1215 | | // in _set_fill_or_truncate_columns, we will use [range.start_offset, end offset] |
1216 | | // to filter the row group. But if this is count push down, the offset is undefined, |
1217 | | // causing incorrect row group filter and may return empty result. |
1218 | 2.65k | } else { |
1219 | 2.65k | Status status = _set_fill_or_truncate_columns(need_to_get_parsed_schema); |
1220 | 2.65k | if (status.is<END_OF_FILE>()) { // all parquet row groups are filtered |
1221 | 0 | continue; |
1222 | 2.65k | } else if (!status.ok()) { |
1223 | 0 | return Status::InternalError("failed to set_fill_or_truncate_columns, err: {}", |
1224 | 0 | status.to_string()); |
1225 | 0 | } |
1226 | 2.65k | } |
1227 | 2.65k | _cur_reader_eof = false; |
1228 | 2.65k | break; |
1229 | 2.65k | } |
1230 | 2.65k | return Status::OK(); |
1231 | 5.30k | } |
1232 | | |
1233 | | Status FileScanner::_init_parquet_reader(std::unique_ptr<ParquetReader>&& parquet_reader, |
1234 | 144 | FileMetaCache* file_meta_cache_ptr) { |
1235 | 144 | const TFileRangeDesc& range = _current_range; |
1236 | 144 | Status init_status = Status::OK(); |
1237 | | |
1238 | 144 | phmap::flat_hash_map<int, std::vector<std::shared_ptr<ColumnPredicate>>> slot_id_to_predicates = |
1239 | 144 | _local_state |
1240 | 144 | ? _local_state->cast<FileScanLocalState>()._slot_id_to_predicates |
1241 | 144 | : phmap::flat_hash_map<int, std::vector<std::shared_ptr<ColumnPredicate>>> {}; |
1242 | 144 | if (range.__isset.table_format_params && |
1243 | 144 | range.table_format_params.table_format_type == "iceberg") { |
1244 | 0 | std::unique_ptr<IcebergParquetReader> iceberg_reader = IcebergParquetReader::create_unique( |
1245 | 0 | std::move(parquet_reader), _profile, _state, *_params, range, _kv_cache, |
1246 | 0 | _io_ctx.get(), file_meta_cache_ptr); |
1247 | 0 | if (_need_iceberg_rowid_column) { |
1248 | 0 | iceberg_reader->set_need_row_id_column(true); |
1249 | 0 | } |
1250 | 0 | if (_row_lineage_columns.row_id_column_idx != -1 || |
1251 | 0 | _row_lineage_columns.last_updated_sequence_number_column_idx != -1) { |
1252 | 0 | std::shared_ptr<RowLineageColumns> row_lineage_columns; |
1253 | 0 | row_lineage_columns = std::make_shared<RowLineageColumns>(); |
1254 | 0 | row_lineage_columns->row_id_column_idx = _row_lineage_columns.row_id_column_idx; |
1255 | 0 | row_lineage_columns->last_updated_sequence_number_column_idx = |
1256 | 0 | _row_lineage_columns.last_updated_sequence_number_column_idx; |
1257 | 0 | iceberg_reader->set_row_lineage_columns(std::move(row_lineage_columns)); |
1258 | 0 | } |
1259 | 0 | iceberg_reader->set_push_down_agg_type(_get_push_down_agg_type()); |
1260 | |
|
1261 | 0 | init_status = iceberg_reader->init_reader( |
1262 | 0 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, |
1263 | 0 | slot_id_to_predicates, _real_tuple_desc, _default_val_row_desc.get(), |
1264 | 0 | _col_name_to_slot_id, &_not_single_slot_filter_conjuncts, |
1265 | 0 | &_slot_id_to_filter_conjuncts); |
1266 | 0 | _cur_reader = std::move(iceberg_reader); |
1267 | 144 | } else if (range.__isset.table_format_params && |
1268 | 144 | range.table_format_params.table_format_type == "paimon") { |
1269 | 0 | std::unique_ptr<PaimonParquetReader> paimon_reader = PaimonParquetReader::create_unique( |
1270 | 0 | std::move(parquet_reader), _profile, _state, *_params, range, _kv_cache, |
1271 | 0 | _io_ctx.get(), file_meta_cache_ptr); |
1272 | 0 | init_status = paimon_reader->init_reader( |
1273 | 0 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, |
1274 | 0 | slot_id_to_predicates, _real_tuple_desc, _default_val_row_desc.get(), |
1275 | 0 | _col_name_to_slot_id, &_not_single_slot_filter_conjuncts, |
1276 | 0 | &_slot_id_to_filter_conjuncts); |
1277 | 0 | RETURN_IF_ERROR(paimon_reader->init_row_filters()); |
1278 | 0 | _cur_reader = std::move(paimon_reader); |
1279 | 144 | } else if (range.__isset.table_format_params && |
1280 | 144 | range.table_format_params.table_format_type == "hudi") { |
1281 | 0 | std::unique_ptr<HudiParquetReader> hudi_reader = HudiParquetReader::create_unique( |
1282 | 0 | std::move(parquet_reader), _profile, _state, *_params, range, _io_ctx.get(), |
1283 | 0 | file_meta_cache_ptr); |
1284 | 0 | init_status = hudi_reader->init_reader( |
1285 | 0 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, |
1286 | 0 | slot_id_to_predicates, _real_tuple_desc, _default_val_row_desc.get(), |
1287 | 0 | _col_name_to_slot_id, &_not_single_slot_filter_conjuncts, |
1288 | 0 | &_slot_id_to_filter_conjuncts); |
1289 | 0 | _cur_reader = std::move(hudi_reader); |
1290 | 144 | } else if (range.table_format_params.table_format_type == "hive") { |
1291 | 14 | auto hive_reader = HiveParquetReader::create_unique(std::move(parquet_reader), _profile, |
1292 | 14 | _state, *_params, range, _io_ctx.get(), |
1293 | 14 | &_is_file_slot, file_meta_cache_ptr); |
1294 | 14 | init_status = hive_reader->init_reader( |
1295 | 14 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, |
1296 | 14 | slot_id_to_predicates, _real_tuple_desc, _default_val_row_desc.get(), |
1297 | 14 | _col_name_to_slot_id, &_not_single_slot_filter_conjuncts, |
1298 | 14 | &_slot_id_to_filter_conjuncts); |
1299 | 14 | _cur_reader = std::move(hive_reader); |
1300 | 130 | } else if (range.table_format_params.table_format_type == "tvf") { |
1301 | 112 | const FieldDescriptor* parquet_meta = nullptr; |
1302 | 112 | RETURN_IF_ERROR(parquet_reader->get_file_metadata_schema(&parquet_meta)); |
1303 | 112 | DCHECK(parquet_meta != nullptr); |
1304 | | |
1305 | | // TVF will first `get_parsed_schema` to obtain file information from BE, and FE will convert |
1306 | | // the column names to lowercase (because the query process is case-insensitive), |
1307 | | // so the lowercase file column names are used here to match the read columns. |
1308 | 112 | std::shared_ptr<TableSchemaChangeHelper::Node> tvf_info_node = nullptr; |
1309 | 112 | RETURN_IF_ERROR(TableSchemaChangeHelper::BuildTableInfoUtil::by_parquet_name( |
1310 | 112 | _real_tuple_desc, *parquet_meta, tvf_info_node)); |
1311 | 112 | init_status = parquet_reader->init_reader( |
1312 | 112 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, |
1313 | 112 | slot_id_to_predicates, _real_tuple_desc, _default_val_row_desc.get(), |
1314 | 112 | _col_name_to_slot_id, &_not_single_slot_filter_conjuncts, |
1315 | 112 | &_slot_id_to_filter_conjuncts, tvf_info_node); |
1316 | 112 | _cur_reader = std::move(parquet_reader); |
1317 | 112 | } else if (_is_load) { |
1318 | 18 | const FieldDescriptor* parquet_meta = nullptr; |
1319 | 18 | RETURN_IF_ERROR(parquet_reader->get_file_metadata_schema(&parquet_meta)); |
1320 | 18 | DCHECK(parquet_meta != nullptr); |
1321 | | |
1322 | | // Load is case-insensitive, so you to match the columns in the file. |
1323 | 18 | std::map<std::string, std::string> file_lower_name_to_native; |
1324 | 416 | for (const auto& parquet_field : parquet_meta->get_fields_schema()) { |
1325 | 416 | file_lower_name_to_native.emplace(doris::to_lower(parquet_field.name), |
1326 | 416 | parquet_field.name); |
1327 | 416 | } |
1328 | 18 | auto load_info_node = std::make_shared<TableSchemaChangeHelper::StructNode>(); |
1329 | 405 | for (const auto slot : _real_tuple_desc->slots()) { |
1330 | 405 | if (file_lower_name_to_native.contains(slot->col_name())) { |
1331 | 404 | load_info_node->add_children(slot->col_name(), |
1332 | 404 | file_lower_name_to_native[slot->col_name()], |
1333 | 404 | TableSchemaChangeHelper::ConstNode::get_instance()); |
1334 | | // For Load, `file_scanner` will create block columns using the file type, |
1335 | | // there is no schema change when reading inside the struct, |
1336 | | // so use `TableSchemaChangeHelper::ConstNode`. |
1337 | 404 | } else { |
1338 | 1 | load_info_node->add_not_exist_children(slot->col_name()); |
1339 | 1 | } |
1340 | 405 | } |
1341 | | |
1342 | 18 | init_status = parquet_reader->init_reader( |
1343 | 18 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, |
1344 | 18 | slot_id_to_predicates, _real_tuple_desc, _default_val_row_desc.get(), |
1345 | 18 | _col_name_to_slot_id, &_not_single_slot_filter_conjuncts, |
1346 | 18 | &_slot_id_to_filter_conjuncts, load_info_node); |
1347 | 18 | _cur_reader = std::move(parquet_reader); |
1348 | 18 | } |
1349 | | |
1350 | 144 | return init_status; |
1351 | 144 | } |
1352 | | |
1353 | | Status FileScanner::_init_orc_reader(std::unique_ptr<OrcReader>&& orc_reader, |
1354 | 118 | FileMetaCache* file_meta_cache_ptr) { |
1355 | 118 | const TFileRangeDesc& range = _current_range; |
1356 | 118 | Status init_status = Status::OK(); |
1357 | | |
1358 | 118 | if (range.__isset.table_format_params && |
1359 | 118 | range.table_format_params.table_format_type == "transactional_hive") { |
1360 | 0 | std::unique_ptr<TransactionalHiveReader> tran_orc_reader = |
1361 | 0 | TransactionalHiveReader::create_unique(std::move(orc_reader), _profile, _state, |
1362 | 0 | *_params, range, _io_ctx.get(), |
1363 | 0 | file_meta_cache_ptr); |
1364 | 0 | init_status = tran_orc_reader->init_reader( |
1365 | 0 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, _real_tuple_desc, |
1366 | 0 | _default_val_row_desc.get(), &_not_single_slot_filter_conjuncts, |
1367 | 0 | &_slot_id_to_filter_conjuncts); |
1368 | 0 | RETURN_IF_ERROR(tran_orc_reader->init_row_filters()); |
1369 | 0 | _cur_reader = std::move(tran_orc_reader); |
1370 | 118 | } else if (range.__isset.table_format_params && |
1371 | 118 | range.table_format_params.table_format_type == "iceberg") { |
1372 | 0 | std::unique_ptr<IcebergOrcReader> iceberg_reader = IcebergOrcReader::create_unique( |
1373 | 0 | std::move(orc_reader), _profile, _state, *_params, range, _kv_cache, _io_ctx.get(), |
1374 | 0 | file_meta_cache_ptr); |
1375 | 0 | if (_need_iceberg_rowid_column) { |
1376 | 0 | iceberg_reader->set_need_row_id_column(true); |
1377 | 0 | } |
1378 | 0 | if (_row_lineage_columns.row_id_column_idx != -1 || |
1379 | 0 | _row_lineage_columns.last_updated_sequence_number_column_idx != -1) { |
1380 | 0 | std::shared_ptr<RowLineageColumns> row_lineage_columns; |
1381 | 0 | row_lineage_columns = std::make_shared<RowLineageColumns>(); |
1382 | 0 | row_lineage_columns->row_id_column_idx = _row_lineage_columns.row_id_column_idx; |
1383 | 0 | row_lineage_columns->last_updated_sequence_number_column_idx = |
1384 | 0 | _row_lineage_columns.last_updated_sequence_number_column_idx; |
1385 | 0 | iceberg_reader->set_row_lineage_columns(std::move(row_lineage_columns)); |
1386 | 0 | } |
1387 | 0 | init_status = iceberg_reader->init_reader( |
1388 | 0 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, _real_tuple_desc, |
1389 | 0 | _default_val_row_desc.get(), _col_name_to_slot_id, |
1390 | 0 | &_not_single_slot_filter_conjuncts, &_slot_id_to_filter_conjuncts); |
1391 | 0 | _cur_reader = std::move(iceberg_reader); |
1392 | 118 | } else if (range.__isset.table_format_params && |
1393 | 118 | range.table_format_params.table_format_type == "paimon") { |
1394 | 0 | std::unique_ptr<PaimonOrcReader> paimon_reader = PaimonOrcReader::create_unique( |
1395 | 0 | std::move(orc_reader), _profile, _state, *_params, range, _kv_cache, _io_ctx.get(), |
1396 | 0 | file_meta_cache_ptr); |
1397 | |
|
1398 | 0 | init_status = paimon_reader->init_reader( |
1399 | 0 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, _real_tuple_desc, |
1400 | 0 | _default_val_row_desc.get(), &_not_single_slot_filter_conjuncts, |
1401 | 0 | &_slot_id_to_filter_conjuncts); |
1402 | 0 | RETURN_IF_ERROR(paimon_reader->init_row_filters()); |
1403 | 0 | _cur_reader = std::move(paimon_reader); |
1404 | 118 | } else if (range.__isset.table_format_params && |
1405 | 118 | range.table_format_params.table_format_type == "hudi") { |
1406 | 0 | std::unique_ptr<HudiOrcReader> hudi_reader = |
1407 | 0 | HudiOrcReader::create_unique(std::move(orc_reader), _profile, _state, *_params, |
1408 | 0 | range, _io_ctx.get(), file_meta_cache_ptr); |
1409 | |
|
1410 | 0 | init_status = hudi_reader->init_reader( |
1411 | 0 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, _real_tuple_desc, |
1412 | 0 | _default_val_row_desc.get(), &_not_single_slot_filter_conjuncts, |
1413 | 0 | &_slot_id_to_filter_conjuncts); |
1414 | 0 | _cur_reader = std::move(hudi_reader); |
1415 | 118 | } else if (range.__isset.table_format_params && |
1416 | 118 | range.table_format_params.table_format_type == "hive") { |
1417 | 11 | std::unique_ptr<HiveOrcReader> hive_reader = HiveOrcReader::create_unique( |
1418 | 11 | std::move(orc_reader), _profile, _state, *_params, range, _io_ctx.get(), |
1419 | 11 | &_is_file_slot, file_meta_cache_ptr); |
1420 | | |
1421 | 11 | init_status = hive_reader->init_reader( |
1422 | 11 | _file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, _real_tuple_desc, |
1423 | 11 | _default_val_row_desc.get(), &_not_single_slot_filter_conjuncts, |
1424 | 11 | &_slot_id_to_filter_conjuncts); |
1425 | 11 | _cur_reader = std::move(hive_reader); |
1426 | 107 | } else if (range.__isset.table_format_params && |
1427 | 107 | range.table_format_params.table_format_type == "tvf") { |
1428 | 96 | const orc::Type* orc_type_ptr = nullptr; |
1429 | 96 | RETURN_IF_ERROR(orc_reader->get_file_type(&orc_type_ptr)); |
1430 | | |
1431 | 96 | std::shared_ptr<TableSchemaChangeHelper::Node> tvf_info_node = nullptr; |
1432 | 96 | RETURN_IF_ERROR(TableSchemaChangeHelper::BuildTableInfoUtil::by_orc_name( |
1433 | 96 | _real_tuple_desc, orc_type_ptr, tvf_info_node)); |
1434 | 96 | init_status = orc_reader->init_reader( |
1435 | 96 | &_file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, false, |
1436 | 96 | _real_tuple_desc, _default_val_row_desc.get(), &_not_single_slot_filter_conjuncts, |
1437 | 96 | &_slot_id_to_filter_conjuncts, tvf_info_node); |
1438 | 96 | _cur_reader = std::move(orc_reader); |
1439 | 96 | } else if (_is_load) { |
1440 | 11 | const orc::Type* orc_type_ptr = nullptr; |
1441 | 11 | RETURN_IF_ERROR(orc_reader->get_file_type(&orc_type_ptr)); |
1442 | | |
1443 | 11 | std::map<std::string, std::string> file_lower_name_to_native; |
1444 | 359 | for (uint64_t idx = 0; idx < orc_type_ptr->getSubtypeCount(); idx++) { |
1445 | 348 | file_lower_name_to_native.emplace(doris::to_lower(orc_type_ptr->getFieldName(idx)), |
1446 | 348 | orc_type_ptr->getFieldName(idx)); |
1447 | 348 | } |
1448 | | |
1449 | 11 | auto load_info_node = std::make_shared<TableSchemaChangeHelper::StructNode>(); |
1450 | 348 | for (const auto slot : _real_tuple_desc->slots()) { |
1451 | 348 | if (file_lower_name_to_native.contains(slot->col_name())) { |
1452 | 348 | load_info_node->add_children(slot->col_name(), |
1453 | 348 | file_lower_name_to_native[slot->col_name()], |
1454 | 348 | TableSchemaChangeHelper::ConstNode::get_instance()); |
1455 | 348 | } else { |
1456 | 0 | load_info_node->add_not_exist_children(slot->col_name()); |
1457 | 0 | } |
1458 | 348 | } |
1459 | 11 | init_status = orc_reader->init_reader( |
1460 | 11 | &_file_col_names, &_src_block_name_to_idx, _push_down_conjuncts, false, |
1461 | 11 | _real_tuple_desc, _default_val_row_desc.get(), &_not_single_slot_filter_conjuncts, |
1462 | 11 | &_slot_id_to_filter_conjuncts, load_info_node); |
1463 | 11 | _cur_reader = std::move(orc_reader); |
1464 | 11 | } |
1465 | | |
1466 | 118 | return init_status; |
1467 | 118 | } |
1468 | | |
1469 | 2.69k | Status FileScanner::_set_fill_or_truncate_columns(bool need_to_get_parsed_schema) { |
1470 | 2.69k | _missing_cols.clear(); |
1471 | 2.69k | _slot_lower_name_to_col_type.clear(); |
1472 | 2.69k | std::unordered_map<std::string, DataTypePtr> name_to_col_type; |
1473 | 2.69k | RETURN_IF_ERROR(_cur_reader->get_columns(&name_to_col_type, &_missing_cols)); |
1474 | 2.69k | if (_need_iceberg_rowid_column && _current_range.__isset.table_format_params && |
1475 | 2.69k | _current_range.table_format_params.table_format_type == "iceberg") { |
1476 | 0 | _missing_cols.erase(BeConsts::ICEBERG_ROWID_COL); |
1477 | 0 | _missing_cols.erase(to_lower(BeConsts::ICEBERG_ROWID_COL)); |
1478 | 0 | } |
1479 | 22.0k | for (const auto& [col_name, col_type] : name_to_col_type) { |
1480 | 22.0k | auto col_name_lower = to_lower(col_name); |
1481 | 22.0k | if (_partition_col_descs.contains(col_name_lower)) { |
1482 | | /* |
1483 | | * `_slot_lower_name_to_col_type` is used by `_init_src_block` and `_cast_to_input_block` during LOAD to |
1484 | | * generate columns of the corresponding type, which records the columns existing in the file. |
1485 | | * |
1486 | | * When a column in `COLUMNS FROM PATH` exists in a file column, the column type in the block will |
1487 | | * not match the slot type in `_output_tuple_desc`, causing an error when |
1488 | | * Serde `deserialize_one_cell_from_json` fills the partition values. |
1489 | | * |
1490 | | * So for partition column not need fill _slot_lower_name_to_col_type. |
1491 | | */ |
1492 | 4 | continue; |
1493 | 4 | } |
1494 | 22.0k | _slot_lower_name_to_col_type.emplace(col_name_lower, col_type); |
1495 | 22.0k | } |
1496 | | |
1497 | 2.69k | if (!_fill_partition_from_path && config::enable_iceberg_partition_column_fallback) { |
1498 | | // check if the cols of _partition_col_descs are in _missing_cols |
1499 | | // if so, set _fill_partition_from_path to true and remove the col from _missing_cols |
1500 | 0 | for (const auto& [col_name, col_type] : _partition_col_descs) { |
1501 | 0 | if (_missing_cols.contains(col_name)) { |
1502 | 0 | _fill_partition_from_path = true; |
1503 | 0 | _missing_cols.erase(col_name); |
1504 | 0 | } |
1505 | 0 | } |
1506 | 0 | } |
1507 | | |
1508 | 2.69k | RETURN_IF_ERROR(_generate_missing_columns()); |
1509 | 2.69k | if (_fill_partition_from_path) { |
1510 | 2.69k | RETURN_IF_ERROR(_cur_reader->set_fill_columns(_partition_col_descs, _missing_col_descs)); |
1511 | 2.69k | } else { |
1512 | | // If the partition columns are not from path, we only fill the missing columns. |
1513 | 1 | RETURN_IF_ERROR(_cur_reader->set_fill_columns({}, _missing_col_descs)); |
1514 | 1 | } |
1515 | 2.69k | if (VLOG_NOTICE_IS_ON && !_missing_cols.empty() && _is_load) { |
1516 | 0 | fmt::memory_buffer col_buf; |
1517 | 0 | for (auto& col : _missing_cols) { |
1518 | 0 | fmt::format_to(col_buf, " {}", col); |
1519 | 0 | } |
1520 | 0 | VLOG_NOTICE << fmt::format("Unknown columns:{} in file {}", fmt::to_string(col_buf), |
1521 | 0 | _current_range.path); |
1522 | 0 | } |
1523 | | |
1524 | 2.69k | RETURN_IF_ERROR(_generate_truncate_columns(need_to_get_parsed_schema)); |
1525 | 2.69k | return Status::OK(); |
1526 | 2.69k | } |
1527 | | |
1528 | 2.69k | Status FileScanner::_generate_truncate_columns(bool need_to_get_parsed_schema) { |
1529 | 2.69k | _source_file_col_name_types.clear(); |
1530 | | // The col names and types of source file, such as parquet, orc files. |
1531 | 2.69k | if (_state->query_options().truncate_char_or_varchar_columns && need_to_get_parsed_schema) { |
1532 | 0 | std::vector<std::string> source_file_col_names; |
1533 | 0 | std::vector<DataTypePtr> source_file_col_types; |
1534 | 0 | Status status = |
1535 | 0 | _cur_reader->get_parsed_schema(&source_file_col_names, &source_file_col_types); |
1536 | 0 | if (!status.ok() && status.code() != TStatusCode::NOT_IMPLEMENTED_ERROR) { |
1537 | 0 | return status; |
1538 | 0 | } |
1539 | 0 | DCHECK_EQ(source_file_col_names.size(), source_file_col_types.size()); |
1540 | 0 | for (int i = 0; i < source_file_col_names.size(); ++i) { |
1541 | 0 | _source_file_col_name_types[to_lower(source_file_col_names[i])] = |
1542 | 0 | source_file_col_types[i]; |
1543 | 0 | } |
1544 | 0 | } |
1545 | 2.69k | return Status::OK(); |
1546 | 2.69k | } |
1547 | | |
1548 | 29 | Status FileScanner::prepare_for_read_lines(const TFileRangeDesc& range) { |
1549 | 29 | _current_range = range; |
1550 | | |
1551 | 29 | _file_cache_statistics.reset(new io::FileCacheStatistics()); |
1552 | 29 | _file_reader_stats.reset(new io::FileReaderStats()); |
1553 | | |
1554 | 29 | _file_read_bytes_counter = |
1555 | 29 | ADD_COUNTER_WITH_LEVEL(_profile, FileReadBytesProfile, TUnit::BYTES, 1); |
1556 | 29 | _file_read_time_counter = ADD_TIMER_WITH_LEVEL(_profile, FileReadTimeProfile, 1); |
1557 | | |
1558 | 29 | RETURN_IF_ERROR(_init_io_ctx()); |
1559 | 29 | _io_ctx->file_cache_stats = _file_cache_statistics.get(); |
1560 | 29 | _io_ctx->file_reader_stats = _file_reader_stats.get(); |
1561 | 29 | _default_val_row_desc.reset(new RowDescriptor((TupleDescriptor*)_real_tuple_desc)); |
1562 | 29 | RETURN_IF_ERROR(_init_expr_ctxes()); |
1563 | | |
1564 | | // Since only one column is read from the file, there is no need to filter, so set these variables to empty. |
1565 | 29 | _push_down_conjuncts.clear(); |
1566 | 29 | _not_single_slot_filter_conjuncts.clear(); |
1567 | 29 | _slot_id_to_filter_conjuncts.clear(); |
1568 | 29 | _kv_cache = nullptr; |
1569 | 29 | return Status::OK(); |
1570 | 29 | } |
1571 | | |
1572 | | Status FileScanner::read_lines_from_range(const TFileRangeDesc& range, |
1573 | | const std::list<int64_t>& row_ids, Block* result_block, |
1574 | | const ExternalFileMappingInfo& external_info, |
1575 | 38 | int64_t* init_reader_ms, int64_t* get_block_ms) { |
1576 | 38 | _current_range = range; |
1577 | 38 | RETURN_IF_ERROR(_generate_partition_columns()); |
1578 | | |
1579 | 38 | TFileFormatType::type format_type = _get_current_format_type(); |
1580 | 38 | Status init_status = Status::OK(); |
1581 | | |
1582 | 38 | auto file_meta_cache_ptr = external_info.enable_file_meta_cache |
1583 | 38 | ? ExecEnv::GetInstance()->file_meta_cache() |
1584 | 38 | : nullptr; |
1585 | | |
1586 | 38 | RETURN_IF_ERROR(scope_timer_run( |
1587 | 38 | [&]() -> Status { |
1588 | 38 | switch (format_type) { |
1589 | 38 | case TFileFormatType::FORMAT_PARQUET: { |
1590 | 38 | std::unique_ptr<ParquetReader> parquet_reader = ParquetReader::create_unique( |
1591 | 38 | _profile, *_params, range, 1, &_state->timezone_obj(), _io_ctx.get(), |
1592 | 38 | _state, file_meta_cache_ptr, false); |
1593 | | |
1594 | 38 | RETURN_IF_ERROR(parquet_reader->read_by_rows(row_ids)); |
1595 | 38 | RETURN_IF_ERROR( |
1596 | 38 | _init_parquet_reader(std::move(parquet_reader), file_meta_cache_ptr)); |
1597 | 38 | break; |
1598 | 38 | } |
1599 | 38 | case TFileFormatType::FORMAT_ORC: { |
1600 | 38 | std::unique_ptr<OrcReader> orc_reader = OrcReader::create_unique( |
1601 | 38 | _profile, _state, *_params, range, 1, _state->timezone(), _io_ctx.get(), |
1602 | 38 | file_meta_cache_ptr, false); |
1603 | | |
1604 | 38 | RETURN_IF_ERROR(orc_reader->read_by_rows(row_ids)); |
1605 | 38 | RETURN_IF_ERROR(_init_orc_reader(std::move(orc_reader), file_meta_cache_ptr)); |
1606 | 38 | break; |
1607 | 38 | } |
1608 | 38 | default: { |
1609 | 38 | return Status::NotSupported( |
1610 | 38 | "Not support create lines reader for file format: {}," |
1611 | 38 | "only support parquet and orc.", |
1612 | 38 | to_string(_params->format_type)); |
1613 | 38 | } |
1614 | 38 | } |
1615 | 38 | return Status::OK(); |
1616 | 38 | }, |
1617 | 38 | init_reader_ms)); |
1618 | | |
1619 | 38 | RETURN_IF_ERROR(_set_fill_or_truncate_columns(true)); |
1620 | 38 | _cur_reader_eof = false; |
1621 | | |
1622 | 38 | RETURN_IF_ERROR(scope_timer_run( |
1623 | 38 | [&]() -> Status { |
1624 | 38 | while (!_cur_reader_eof) { |
1625 | 38 | bool eof = false; |
1626 | 38 | RETURN_IF_ERROR(_get_block_impl(_state, result_block, &eof)); |
1627 | 38 | } |
1628 | 38 | return Status::OK(); |
1629 | 38 | }, |
1630 | 38 | get_block_ms)); |
1631 | | |
1632 | 38 | _cur_reader->collect_profile_before_close(); |
1633 | 38 | RETURN_IF_ERROR(_cur_reader->close()); |
1634 | | |
1635 | 38 | COUNTER_UPDATE(_file_read_bytes_counter, _file_reader_stats->read_bytes); |
1636 | 38 | COUNTER_UPDATE(_file_read_time_counter, _file_reader_stats->read_time_ns); |
1637 | 38 | return Status::OK(); |
1638 | 38 | } |
1639 | | |
1640 | 44 | Status FileScanner::_generate_partition_columns() { |
1641 | 44 | _partition_col_descs.clear(); |
1642 | 44 | _partition_value_is_null.clear(); |
1643 | 44 | const TFileRangeDesc& range = _current_range; |
1644 | 44 | if (range.__isset.columns_from_path && !_partition_slot_descs.empty()) { |
1645 | 11 | for (const auto& slot_desc : _partition_slot_descs) { |
1646 | 11 | if (slot_desc) { |
1647 | 11 | auto it = _partition_slot_index_map.find(slot_desc->id()); |
1648 | 11 | if (it == std::end(_partition_slot_index_map)) { |
1649 | 0 | return Status::InternalError("Unknown source slot descriptor, slot_id={}", |
1650 | 0 | slot_desc->id()); |
1651 | 0 | } |
1652 | 11 | const std::string& column_from_path = range.columns_from_path[it->second]; |
1653 | 11 | _partition_col_descs.emplace(slot_desc->col_name(), |
1654 | 11 | std::make_tuple(column_from_path, slot_desc)); |
1655 | 11 | if (range.__isset.columns_from_path_is_null) { |
1656 | 0 | _partition_value_is_null.emplace(slot_desc->col_name(), |
1657 | 0 | range.columns_from_path_is_null[it->second]); |
1658 | 0 | } |
1659 | 11 | } |
1660 | 11 | } |
1661 | 6 | } |
1662 | 44 | return Status::OK(); |
1663 | 44 | } |
1664 | | |
1665 | 2.69k | Status FileScanner::_generate_missing_columns() { |
1666 | 2.69k | _missing_col_descs.clear(); |
1667 | 2.69k | if (!_missing_cols.empty()) { |
1668 | 3 | for (auto* slot_desc : _real_tuple_desc->slots()) { |
1669 | 3 | if (!_missing_cols.contains(slot_desc->col_name())) { |
1670 | 2 | continue; |
1671 | 2 | } |
1672 | | |
1673 | 1 | auto it = _col_default_value_ctx.find(slot_desc->col_name()); |
1674 | 1 | if (it == _col_default_value_ctx.end()) { |
1675 | 0 | return Status::InternalError("failed to find default value expr for slot: {}", |
1676 | 0 | slot_desc->col_name()); |
1677 | 0 | } |
1678 | 1 | _missing_col_descs.emplace(slot_desc->col_name(), it->second); |
1679 | 1 | } |
1680 | 1 | } |
1681 | 2.69k | return Status::OK(); |
1682 | 2.69k | } |
1683 | | |
1684 | 2.68k | Status FileScanner::_init_expr_ctxes() { |
1685 | 2.68k | std::map<SlotId, int> full_src_index_map; |
1686 | 2.68k | std::map<SlotId, SlotDescriptor*> full_src_slot_map; |
1687 | 2.68k | std::map<std::string, int> partition_name_to_key_index_map; |
1688 | 2.68k | int index = 0; |
1689 | 21.5k | for (const auto& slot_desc : _real_tuple_desc->slots()) { |
1690 | 21.5k | full_src_slot_map.emplace(slot_desc->id(), slot_desc); |
1691 | 21.5k | full_src_index_map.emplace(slot_desc->id(), index++); |
1692 | 21.5k | } |
1693 | | |
1694 | | // For external table query, find the index of column in path. |
1695 | | // Because query doesn't always search for all columns in a table |
1696 | | // and the order of selected columns is random. |
1697 | | // All ranges in _ranges vector should have identical columns_from_path_keys |
1698 | | // because they are all file splits for the same external table. |
1699 | | // So here use the first element of _ranges to fill the partition_name_to_key_index_map |
1700 | 2.68k | if (_current_range.__isset.columns_from_path_keys) { |
1701 | 440 | std::vector<std::string> key_map = _current_range.columns_from_path_keys; |
1702 | 440 | if (!key_map.empty()) { |
1703 | 17 | for (size_t i = 0; i < key_map.size(); i++) { |
1704 | 11 | partition_name_to_key_index_map.emplace(key_map[i], i); |
1705 | 11 | } |
1706 | 6 | } |
1707 | 440 | } |
1708 | | |
1709 | 2.68k | _num_of_columns_from_file = _params->num_of_columns_from_file; |
1710 | | |
1711 | 21.5k | for (const auto& slot_info : _params->required_slots) { |
1712 | 21.5k | auto slot_id = slot_info.slot_id; |
1713 | 21.5k | auto it = full_src_slot_map.find(slot_id); |
1714 | 21.5k | if (it == std::end(full_src_slot_map)) { |
1715 | 0 | return Status::InternalError( |
1716 | 0 | fmt::format("Unknown source slot descriptor, slot_id={}", slot_id)); |
1717 | 0 | } |
1718 | 21.5k | if (it->second->col_name().starts_with(BeConsts::GLOBAL_ROWID_COL)) { |
1719 | 13 | _row_id_column_iterator_pair.second = _default_val_row_desc->get_column_id(slot_id); |
1720 | 13 | continue; |
1721 | 13 | } |
1722 | 21.5k | if (it->second->col_name() == BeConsts::ICEBERG_ROWID_COL) { |
1723 | 0 | _need_iceberg_rowid_column = true; |
1724 | 0 | continue; |
1725 | 0 | } |
1726 | | |
1727 | 21.5k | if (it->second->col_name() == IcebergTableReader::ROW_LINEAGE_ROW_ID) { |
1728 | 0 | _row_lineage_columns.row_id_column_idx = _default_val_row_desc->get_column_id(slot_id); |
1729 | 0 | } |
1730 | | |
1731 | 21.5k | if (it->second->col_name() == IcebergTableReader::ROW_LINEAGE_LAST_UPDATED_SEQ_NUMBER) { |
1732 | 0 | _row_lineage_columns.last_updated_sequence_number_column_idx = |
1733 | 0 | _default_val_row_desc->get_column_id(slot_id); |
1734 | 0 | } |
1735 | | |
1736 | 21.5k | if (slot_info.is_file_slot) { |
1737 | 21.5k | _is_file_slot.emplace(slot_id); |
1738 | 21.5k | _file_slot_descs.emplace_back(it->second); |
1739 | 21.5k | _file_col_names.push_back(it->second->col_name()); |
1740 | 21.5k | } |
1741 | | |
1742 | 21.5k | if (partition_name_to_key_index_map.contains(it->second->col_name())) { |
1743 | 11 | if (slot_info.is_file_slot) { |
1744 | | // If there is slot which is both a partition column and a file column, |
1745 | | // we should not fill the partition column from path. |
1746 | 0 | _fill_partition_from_path = false; |
1747 | 11 | } else if (!_fill_partition_from_path) { |
1748 | | // This should not happen |
1749 | 0 | return Status::InternalError( |
1750 | 0 | "Partition column {} is not a file column, but there is already a column " |
1751 | 0 | "which is both a partition column and a file column.", |
1752 | 0 | it->second->col_name()); |
1753 | 0 | } |
1754 | 11 | _partition_slot_descs.emplace_back(it->second); |
1755 | 11 | if (_is_load) { |
1756 | 11 | auto iti = full_src_index_map.find(slot_id); |
1757 | 11 | _partition_slot_index_map.emplace(slot_id, iti->second - _num_of_columns_from_file); |
1758 | 11 | } else { |
1759 | 0 | auto kit = partition_name_to_key_index_map.find(it->second->col_name()); |
1760 | 0 | _partition_slot_index_map.emplace(slot_id, kit->second); |
1761 | 0 | } |
1762 | 11 | } |
1763 | 21.5k | } |
1764 | | |
1765 | | // set column name to default value expr map |
1766 | 21.5k | for (auto* slot_desc : _real_tuple_desc->slots()) { |
1767 | 21.5k | VExprContextSPtr ctx; |
1768 | 21.5k | auto it = _params->default_value_of_src_slot.find(slot_desc->id()); |
1769 | 21.5k | if (it != std::end(_params->default_value_of_src_slot)) { |
1770 | 21.1k | if (!it->second.nodes.empty()) { |
1771 | 17.4k | RETURN_IF_ERROR(VExpr::create_expr_tree(it->second, ctx)); |
1772 | 17.4k | RETURN_IF_ERROR(ctx->prepare(_state, *_default_val_row_desc)); |
1773 | 17.4k | RETURN_IF_ERROR(ctx->open(_state)); |
1774 | 17.4k | } |
1775 | | // if expr is empty, the default value will be null |
1776 | 21.1k | _col_default_value_ctx.emplace(slot_desc->col_name(), ctx); |
1777 | 21.1k | } |
1778 | 21.5k | } |
1779 | | |
1780 | 2.68k | if (_is_load) { |
1781 | | // follow desc expr map is only for load task. |
1782 | 2.12k | bool has_slot_id_map = _params->__isset.dest_sid_to_src_sid_without_trans; |
1783 | 2.12k | int idx = 0; |
1784 | 23.7k | for (auto* slot_desc : _output_tuple_desc->slots()) { |
1785 | 23.7k | auto it = _params->expr_of_dest_slot.find(slot_desc->id()); |
1786 | 23.7k | if (it == std::end(_params->expr_of_dest_slot)) { |
1787 | 0 | return Status::InternalError("No expr for dest slot, id={}, name={}", |
1788 | 0 | slot_desc->id(), slot_desc->col_name()); |
1789 | 0 | } |
1790 | | |
1791 | 23.7k | VExprContextSPtr ctx; |
1792 | 23.7k | if (!it->second.nodes.empty()) { |
1793 | 23.7k | RETURN_IF_ERROR(VExpr::create_expr_tree(it->second, ctx)); |
1794 | 23.7k | RETURN_IF_ERROR(ctx->prepare(_state, *_src_row_desc)); |
1795 | 23.7k | RETURN_IF_ERROR(ctx->open(_state)); |
1796 | 23.7k | } |
1797 | 23.7k | _dest_vexpr_ctx.emplace_back(ctx); |
1798 | 23.7k | _dest_slot_name_to_idx[slot_desc->col_name()] = idx++; |
1799 | | |
1800 | 23.7k | if (has_slot_id_map) { |
1801 | 23.6k | auto it1 = _params->dest_sid_to_src_sid_without_trans.find(slot_desc->id()); |
1802 | 23.6k | if (it1 == std::end(_params->dest_sid_to_src_sid_without_trans)) { |
1803 | 5.87k | _src_slot_descs_order_by_dest.emplace_back(nullptr); |
1804 | 17.8k | } else { |
1805 | 17.8k | auto _src_slot_it = full_src_slot_map.find(it1->second); |
1806 | 17.8k | if (_src_slot_it == std::end(full_src_slot_map)) { |
1807 | 0 | return Status::InternalError("No src slot {} in src slot descs", |
1808 | 0 | it1->second); |
1809 | 0 | } |
1810 | 17.8k | _dest_slot_to_src_slot_index.emplace(_src_slot_descs_order_by_dest.size(), |
1811 | 17.8k | full_src_index_map[_src_slot_it->first]); |
1812 | 17.8k | _src_slot_descs_order_by_dest.emplace_back(_src_slot_it->second); |
1813 | 17.8k | } |
1814 | 23.6k | } |
1815 | 23.7k | } |
1816 | 2.12k | } |
1817 | 2.68k | return Status::OK(); |
1818 | 2.68k | } |
1819 | | |
1820 | 13.2k | bool FileScanner::_should_enable_condition_cache() { |
1821 | 13.2k | return _condition_cache_digest != 0 && !_is_load && |
1822 | 13.2k | (!_conjuncts.empty() || !_push_down_conjuncts.empty()); |
1823 | 13.2k | } |
1824 | | |
1825 | 5.30k | void FileScanner::_init_reader_condition_cache() { |
1826 | 5.30k | _condition_cache = nullptr; |
1827 | 5.30k | _condition_cache_ctx = nullptr; |
1828 | | |
1829 | 5.30k | if (!_should_enable_condition_cache() || !_cur_reader) { |
1830 | 5.29k | return; |
1831 | 5.29k | } |
1832 | | |
1833 | | // Disable condition cache when delete operations exist (e.g. Iceberg position/equality |
1834 | | // deletes, Hive ACID deletes). Cached granule results may become stale if delete files |
1835 | | // change between queries while the data file's cache key remains the same. |
1836 | 4 | if (_cur_reader->has_delete_operations()) { |
1837 | 0 | return; |
1838 | 0 | } |
1839 | | |
1840 | 4 | auto* cache = segment_v2::ConditionCache::instance(); |
1841 | 4 | _condition_cache_key = segment_v2::ConditionCache::ExternalCacheKey( |
1842 | 4 | _current_range.path, |
1843 | 4 | _current_range.__isset.modification_time ? _current_range.modification_time : 0, |
1844 | 4 | _current_range.__isset.file_size ? _current_range.file_size : -1, |
1845 | 4 | _condition_cache_digest, |
1846 | 4 | _current_range.__isset.start_offset ? _current_range.start_offset : 0, |
1847 | 4 | _current_range.__isset.size ? _current_range.size : -1); |
1848 | | |
1849 | 4 | segment_v2::ConditionCacheHandle handle; |
1850 | 4 | auto condition_cache_hit = cache->lookup(_condition_cache_key, &handle); |
1851 | 4 | if (condition_cache_hit) { |
1852 | 0 | _condition_cache = handle.get_filter_result(); |
1853 | 0 | _condition_cache_hit_count++; |
1854 | 4 | } else { |
1855 | | // Allocate cache pre-sized to total number of granules. |
1856 | | // We add +1 as a safety margin: when a file is split across multiple scanners |
1857 | | // and the first row of this scanner's range is not aligned to a granule boundary, |
1858 | | // the data may span one more granule than ceil(total_rows / GRANULE_SIZE). |
1859 | | // The extra element costs only 1 bit and never affects correctness (an extra |
1860 | | // false-granule beyond the actual data range won't overlap any real row range). |
1861 | 4 | int64_t total_rows = _cur_reader->get_total_rows(); |
1862 | 4 | if (total_rows > 0) { |
1863 | 1 | size_t num_granules = (total_rows + ConditionCacheContext::GRANULE_SIZE - 1) / |
1864 | 1 | ConditionCacheContext::GRANULE_SIZE; |
1865 | 1 | _condition_cache = std::make_shared<std::vector<bool>>(num_granules + 1, false); |
1866 | 1 | } |
1867 | 4 | } |
1868 | | |
1869 | 4 | if (_condition_cache) { |
1870 | | // Create context to pass to readers (native readers use it; non-native readers ignore it) |
1871 | 1 | _condition_cache_ctx = std::make_shared<ConditionCacheContext>(); |
1872 | 1 | _condition_cache_ctx->is_hit = condition_cache_hit; |
1873 | 1 | _condition_cache_ctx->filter_result = _condition_cache; |
1874 | 1 | _cur_reader->set_condition_cache_context(_condition_cache_ctx); |
1875 | 1 | } |
1876 | 4 | } |
1877 | | |
1878 | 7.96k | void FileScanner::_finalize_reader_condition_cache() { |
1879 | 7.96k | if (!_should_enable_condition_cache() || !_condition_cache_ctx || |
1880 | 7.96k | _condition_cache_ctx->is_hit) { |
1881 | 7.96k | _condition_cache = nullptr; |
1882 | 7.96k | _condition_cache_ctx = nullptr; |
1883 | 7.96k | return; |
1884 | 7.96k | } |
1885 | | // Only store the cache if the reader was fully consumed. If the scan was |
1886 | | // truncated early (e.g. by LIMIT), the cache is incomplete — unread granules |
1887 | | // would remain false and cause surviving rows to be incorrectly skipped on HIT. |
1888 | 1 | if (!_cur_reader_eof) { |
1889 | 0 | _condition_cache = nullptr; |
1890 | 0 | _condition_cache_ctx = nullptr; |
1891 | 0 | return; |
1892 | 0 | } |
1893 | | |
1894 | 1 | auto* cache = segment_v2::ConditionCache::instance(); |
1895 | 1 | cache->insert(_condition_cache_key, std::move(_condition_cache)); |
1896 | 1 | _condition_cache = nullptr; |
1897 | 1 | _condition_cache_ctx = nullptr; |
1898 | 1 | } |
1899 | | |
1900 | 2.65k | Status FileScanner::close(RuntimeState* state) { |
1901 | 2.65k | if (!_try_close()) { |
1902 | 0 | return Status::OK(); |
1903 | 0 | } |
1904 | | |
1905 | 2.65k | _finalize_reader_condition_cache(); |
1906 | | |
1907 | 2.65k | if (_cur_reader) { |
1908 | 13 | RETURN_IF_ERROR(_cur_reader->close()); |
1909 | 13 | } |
1910 | | |
1911 | 2.65k | RETURN_IF_ERROR(Scanner::close(state)); |
1912 | 2.65k | return Status::OK(); |
1913 | 2.65k | } |
1914 | | |
1915 | 2.65k | void FileScanner::try_stop() { |
1916 | 2.65k | Scanner::try_stop(); |
1917 | 2.65k | if (_io_ctx) { |
1918 | 2.65k | _io_ctx->should_stop = true; |
1919 | 2.65k | } |
1920 | 2.65k | } |
1921 | | |
1922 | 2.65k | void FileScanner::update_realtime_counters() { |
1923 | 2.65k | FileScanLocalState* local_state = static_cast<FileScanLocalState*>(_local_state); |
1924 | | |
1925 | 2.65k | COUNTER_UPDATE(local_state->_scan_bytes, _file_reader_stats->read_bytes); |
1926 | 2.65k | COUNTER_UPDATE(local_state->_scan_rows, _file_reader_stats->read_rows); |
1927 | | |
1928 | 2.65k | _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_rows( |
1929 | 2.65k | _file_reader_stats->read_rows); |
1930 | 2.65k | _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes( |
1931 | 2.65k | _file_reader_stats->read_bytes); |
1932 | | |
1933 | 2.65k | int64_t delta_bytes_read_from_local = |
1934 | 2.65k | _file_cache_statistics->bytes_read_from_local - _last_bytes_read_from_local; |
1935 | 2.65k | int64_t delta_bytes_read_from_remote = |
1936 | 2.65k | _file_cache_statistics->bytes_read_from_remote - _last_bytes_read_from_remote; |
1937 | 2.65k | if (_file_cache_statistics->bytes_read_from_local == 0 && |
1938 | 2.65k | _file_cache_statistics->bytes_read_from_remote == 0) { |
1939 | 2.65k | _state->get_query_ctx() |
1940 | 2.65k | ->resource_ctx() |
1941 | 2.65k | ->io_context() |
1942 | 2.65k | ->update_scan_bytes_from_remote_storage(_file_reader_stats->read_bytes); |
1943 | 2.65k | DorisMetrics::instance()->query_scan_bytes_from_local->increment( |
1944 | 2.65k | _file_reader_stats->read_bytes); |
1945 | 2.65k | } else { |
1946 | 0 | _state->get_query_ctx()->resource_ctx()->io_context()->update_scan_bytes_from_local_storage( |
1947 | 0 | delta_bytes_read_from_local); |
1948 | 0 | _state->get_query_ctx() |
1949 | 0 | ->resource_ctx() |
1950 | 0 | ->io_context() |
1951 | 0 | ->update_scan_bytes_from_remote_storage(delta_bytes_read_from_remote); |
1952 | 0 | DorisMetrics::instance()->query_scan_bytes_from_local->increment( |
1953 | 0 | delta_bytes_read_from_local); |
1954 | 0 | DorisMetrics::instance()->query_scan_bytes_from_remote->increment( |
1955 | 0 | delta_bytes_read_from_remote); |
1956 | 0 | } |
1957 | | |
1958 | 2.65k | COUNTER_UPDATE(_file_read_bytes_counter, _file_reader_stats->read_bytes); |
1959 | | |
1960 | 2.65k | DorisMetrics::instance()->query_scan_bytes->increment(_file_reader_stats->read_bytes); |
1961 | 2.65k | DorisMetrics::instance()->query_scan_rows->increment(_file_reader_stats->read_rows); |
1962 | | |
1963 | 2.65k | _file_reader_stats->read_bytes = 0; |
1964 | 2.65k | _file_reader_stats->read_rows = 0; |
1965 | | |
1966 | 2.65k | _last_bytes_read_from_local = _file_cache_statistics->bytes_read_from_local; |
1967 | 2.65k | _last_bytes_read_from_remote = _file_cache_statistics->bytes_read_from_remote; |
1968 | 2.65k | } |
1969 | | |
1970 | 2.65k | void FileScanner::_collect_profile_before_close() { |
1971 | 2.65k | Scanner::_collect_profile_before_close(); |
1972 | 2.65k | if (config::enable_file_cache && _state->query_options().enable_file_cache && |
1973 | 2.65k | _profile != nullptr) { |
1974 | 0 | io::FileCacheProfileReporter cache_profile(_profile); |
1975 | 0 | cache_profile.update(_file_cache_statistics.get()); |
1976 | 0 | _state->get_query_ctx()->resource_ctx()->io_context()->update_bytes_write_into_cache( |
1977 | 0 | _file_cache_statistics->bytes_write_into_cache); |
1978 | 0 | } |
1979 | | |
1980 | 2.65k | if (_cur_reader != nullptr) { |
1981 | 13 | _cur_reader->collect_profile_before_close(); |
1982 | 13 | } |
1983 | | |
1984 | 2.65k | FileScanLocalState* local_state = static_cast<FileScanLocalState*>(_local_state); |
1985 | 2.65k | COUNTER_UPDATE(local_state->_scan_bytes, _file_reader_stats->read_bytes); |
1986 | 2.65k | COUNTER_UPDATE(local_state->_scan_rows, _file_reader_stats->read_rows); |
1987 | | |
1988 | 2.65k | COUNTER_UPDATE(_file_read_bytes_counter, _file_reader_stats->read_bytes); |
1989 | 2.65k | COUNTER_UPDATE(_file_read_calls_counter, _file_reader_stats->read_calls); |
1990 | 2.65k | COUNTER_UPDATE(_file_read_time_counter, _file_reader_stats->read_time_ns); |
1991 | 2.65k | COUNTER_UPDATE(local_state->_condition_cache_hit_counter, _condition_cache_hit_count); |
1992 | 2.65k | if (_io_ctx) { |
1993 | 2.65k | COUNTER_UPDATE(local_state->_condition_cache_filtered_rows_counter, |
1994 | 2.65k | _io_ctx->condition_cache_filtered_rows); |
1995 | 2.65k | } |
1996 | | |
1997 | 2.65k | DorisMetrics::instance()->query_scan_bytes->increment(_file_reader_stats->read_bytes); |
1998 | 2.65k | DorisMetrics::instance()->query_scan_rows->increment(_file_reader_stats->read_rows); |
1999 | 2.65k | } |
2000 | | |
2001 | | } // namespace doris |