|
65 | 65 | #include "format_v2/table/hudi_reader.h" |
66 | 66 | #include "format_v2/table/iceberg_position_delete_sys_table_reader.h" |
67 | 67 | #include "format_v2/table/iceberg_reader.h" |
| 68 | +#include "format_v2/table/load_reader.h" |
68 | 69 | #include "format_v2/table/paimon_reader.h" |
69 | 70 | #include "format_v2/table/remote_doris_reader.h" |
70 | 71 | #include "format_v2/table_reader.h" |
@@ -414,6 +415,7 @@ FileScannerV2::FileScannerV2(RuntimeState* state, FileScanLocalState* local_stat |
414 | 415 |
|
415 | 416 | Status FileScannerV2::init(RuntimeState* state, const VExprContextSPtrs& conjuncts) { |
416 | 417 | RETURN_IF_ERROR(Scanner::init(state, conjuncts)); |
| 418 | + _is_load = state->desc_tbl().get_tuple_descriptor(_params->src_tuple_id) != nullptr; |
417 | 419 | auto* profile = _local_state->scanner_profile(); |
418 | 420 | const auto hierarchy = file_scan_profile::ensure_hierarchy(profile); |
419 | 421 | _scanner_total_timer = hierarchy.scanner; |
@@ -466,7 +468,13 @@ Status FileScannerV2::_open_impl(RuntimeState* state) { |
466 | 468 | RETURN_IF_ERROR(Scanner::_open_impl(state)); |
467 | 469 | RETURN_IF_ERROR(_get_next_scan_range(&_first_scan_range)); |
468 | 470 | if (_first_scan_range) { |
469 | | - RETURN_IF_ERROR(_create_table_reader_for_format(_current_range, &_table_reader)); |
| 471 | + if (_is_load) { |
| 472 | + _table_reader = std::make_unique<format::LoadTableReader>( |
| 473 | + state->desc_tbl().get_tuple_descriptor(_params->src_tuple_id), |
| 474 | + _output_tuple_desc); |
| 475 | + } else { |
| 476 | + RETURN_IF_ERROR(_create_table_reader_for_format(_current_range, &_table_reader)); |
| 477 | + } |
470 | 478 | DORIS_CHECK(_table_reader != nullptr); |
471 | 479 | RETURN_IF_ERROR(_init_expr_ctxes()); |
472 | 480 | RETURN_IF_ERROR(_init_table_reader(_current_range)); |
@@ -927,7 +935,18 @@ Status FileScannerV2::_init_expr_ctxes() { |
927 | 935 | _slot_id_to_desc.emplace(slot_desc->id(), slot_desc); |
928 | 936 | } |
929 | 937 | DORIS_CHECK(_table_reader != nullptr); |
930 | | - RETURN_IF_ERROR(_build_projected_columns(*_table_reader)); |
| 938 | + if (_is_load) { |
| 939 | + // Load required_slots describe the source tuple, not this destination tuple. |
| 940 | + // LoadTableReader owns source projection, defaults and partition materialization. |
| 941 | + _projected_columns.clear(); |
| 942 | + for (size_t i = 0; i < _output_tuple_desc->slots().size(); ++i) { |
| 943 | + const auto* slot = _output_tuple_desc->slots()[i]; |
| 944 | + _projected_columns.push_back(_build_table_column(slot)); |
| 945 | + _slot_id_to_global_index.emplace(slot->id(), format::GlobalIndex(i)); |
| 946 | + } |
| 947 | + } else { |
| 948 | + RETURN_IF_ERROR(_build_projected_columns(*_table_reader)); |
| 949 | + } |
931 | 950 | return Status::OK(); |
932 | 951 | } |
933 | 952 |
|
@@ -1023,6 +1042,9 @@ format::ColumnDefinition FileScannerV2::_build_table_column(const SlotDescriptor |
1023 | 1042 | Status FileScannerV2::_build_table_conjuncts(VExprContextSPtrs* conjuncts) const { |
1024 | 1043 | DORIS_CHECK(conjuncts != nullptr); |
1025 | 1044 | conjuncts->clear(); |
| 1045 | + if (_is_load) { |
| 1046 | + return Status::OK(); |
| 1047 | + } |
1026 | 1048 | conjuncts->reserve(_conjuncts.size()); |
1027 | 1049 | for (const auto& conjunct : _conjuncts) { |
1028 | 1050 | VExprSPtr root; |
@@ -1364,6 +1386,13 @@ bool FileScannerV2::_should_update_load_counters() const { |
1364 | 1386 | } |
1365 | 1387 |
|
1366 | 1388 | void FileScannerV2::_report_file_reader_predicate_filtered_rows() { |
| 1389 | + if (_io_ctx != nullptr && _is_load) { |
| 1390 | + _counter.num_rows_filtered += _io_ctx->load_filtered_rows - _reported_load_filtered_rows; |
| 1391 | + _counter.num_rows_unselected += |
| 1392 | + _io_ctx->load_unselected_rows - _reported_load_unselected_rows; |
| 1393 | + _reported_load_filtered_rows = _io_ctx->load_filtered_rows; |
| 1394 | + _reported_load_unselected_rows = _io_ctx->load_unselected_rows; |
| 1395 | + } |
1367 | 1396 | const int64_t filtered_rows = _io_ctx != nullptr ? _io_ctx->predicate_filtered_rows : 0; |
1368 | 1397 | const int64_t filtered_delta = filtered_rows - _reported_predicate_filtered_rows; |
1369 | 1398 | if (filtered_delta > 0) { |
|
0 commit comments