Coverage Report

Created: 2026-03-17 00:04

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format/generic_reader.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 "format/generic_reader.h"
19
20
#include <gen_cpp/PlanNodes_types.h>
21
#include <gen_cpp/Types_types.h>
22
23
namespace doris {
24
25
Status GenericReader::init_column_descriptors(
26
        const TFileScanRangeParams& params, const TFileRangeDesc& range,
27
        const std::vector<ColumnDescriptor>& column_descs, const TupleDescriptor* tuple_descriptor,
28
        const RowDescriptor* row_descriptor, RuntimeState* state, bool fill_partition_from_path,
29
        const std::unordered_map<std::string, std::tuple<std::string, const SlotDescriptor*>>&
30
                partition_col_descs,
31
        std::unordered_map<std::string, VExprContextSPtr>* out_missing_col_descs,
32
        std::unordered_set<std::string>* out_missing_cols,
33
24
        std::unordered_map<std::string, DataTypePtr>* out_name_to_col_type) {
34
    // 1. Get columns from reader (which columns exist in the file, which are missing)
35
24
    RETURN_IF_ERROR(get_columns(out_name_to_col_type, out_missing_cols));
36
37
    // 2. Build default value expressions for missing columns
38
24
    std::unordered_map<std::string, VExprContextSPtr> col_default_value_ctx;
39
141
    for (auto* slot_desc : tuple_descriptor->slots()) {
40
141
        auto it = params.default_value_of_src_slot.find(slot_desc->id());
41
141
        if (it != params.default_value_of_src_slot.end()) {
42
0
            VExprContextSPtr ctx;
43
0
            if (!it->second.nodes.empty()) {
44
0
                RETURN_IF_ERROR(VExpr::create_expr_tree(it->second, ctx));
45
0
                RETURN_IF_ERROR(ctx->prepare(state, *row_descriptor));
46
0
                RETURN_IF_ERROR(ctx->open(state));
47
0
            }
48
0
            col_default_value_ctx.emplace(slot_desc->col_name(), ctx);
49
0
        }
50
141
    }
51
52
    // 3. Build missing_col_descs from missing columns
53
24
    out_missing_col_descs->clear();
54
141
    for (const auto& col_desc : column_descs) {
55
141
        if (!col_desc.is_file_slot) {
56
0
            continue;
57
0
        }
58
141
        if (out_missing_cols->contains(col_desc.name) ||
59
141
            out_missing_cols->contains(to_lower(col_desc.name))) {
60
0
            auto it = col_default_value_ctx.find(col_desc.name);
61
0
            if (it != col_default_value_ctx.end()) {
62
0
                out_missing_col_descs->emplace(col_desc.name, it->second);
63
0
            } else {
64
                // No default value: fill with null
65
0
                out_missing_col_descs->emplace(col_desc.name, nullptr);
66
0
            }
67
0
        }
68
141
    }
69
70
    // 4. Call set_fill_columns on the reader
71
24
    if (fill_partition_from_path) {
72
24
        RETURN_IF_ERROR(set_fill_columns(partition_col_descs, *out_missing_col_descs));
73
24
    } else {
74
0
        RETURN_IF_ERROR(set_fill_columns({}, *out_missing_col_descs));
75
0
    }
76
24
    return Status::OK();
77
24
}
78
79
} // namespace doris