Coverage Report

Created: 2026-07-02 23:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/format_v2/column_mapper_nested.h
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
#pragma once
19
20
#include <cstddef>
21
#include <span>
22
#include <string>
23
#include <vector>
24
25
#include "common/status.h"
26
#include "core/data_type/data_type.h"
27
#include "core/field.h"
28
#include "exprs/vexpr_fwd.h"
29
#include "exprs/vliteral.h"
30
#include "exprs/vslot_ref.h"
31
#include "format_v2/column_mapper.h"
32
#include "format_v2/file_reader.h"
33
34
namespace doris::format {
35
36
struct StructChildSelector {
37
    bool by_name = true;
38
    std::string name;
39
    size_t ordinal = 0;
40
};
41
42
struct NestedStructPath {
43
    GlobalIndex root_global_index;
44
    std::vector<StructChildSelector> selectors;
45
};
46
47
struct ResolvedNestedStructPath {
48
    LocalColumnIndex file_projection;
49
    std::vector<std::string> file_child_names;
50
    std::vector<DataTypePtr> file_child_types;
51
};
52
53
// A split-local literal produced by slot-literal predicate localization. This wrapper keeps the
54
// original table literal so a cloned conjunct can be localized again for another split.
55
class SplitLocalFileLiteral final : public VLiteral {
56
public:
57
    SplitLocalFileLiteral(const DataTypePtr& file_type, const Field& file_field,
58
                          DataTypePtr original_type, Field original_field);
59
60
0
    const DataTypePtr& original_type() const { return _original_type; }
61
0
    const Field& original_field() const { return _original_field; }
62
0
    Status clone_node(VExprSPtr* cloned_expr) const override {
63
0
        DORIS_CHECK(cloned_expr != nullptr);
64
0
        Field file_field;
65
0
        get_column_ptr()->get(0, file_field);
66
0
        *cloned_expr = std::make_shared<SplitLocalFileLiteral>(_data_type, file_field,
67
0
                                                               _original_type, _original_field);
68
0
        return Status::OK();
69
0
    }
70
71
private:
72
    DataTypePtr _original_type;
73
    Field _original_field;
74
};
75
76
GlobalIndex slot_ref_global_index(const VSlotRef& slot_ref);
77
bool is_struct_element_expr(const VExprSPtr& expr);
78
Field literal_field(const VExprSPtr& literal_expr);
79
80
bool resolve_nested_struct_path_for_file(const NestedStructPath& path,
81
                                         const std::vector<ColumnMapping>& mappings,
82
                                         ResolvedNestedStructPath* resolved,
83
                                         bool require_scan_projection = false);
84
85
bool resolve_nested_struct_expr_for_file(const VExprSPtr& expr,
86
                                         const std::vector<ColumnMapping>& mappings,
87
                                         ResolvedNestedStructPath* resolved);
88
89
void collect_nested_struct_paths(const VExprSPtr& expr, std::vector<NestedStructPath>* paths);
90
91
std::vector<const ColumnMapping*> present_child_mappings_in_file_order(
92
        const std::vector<ColumnMapping>& child_mappings);
93
94
Status build_file_child_projection_from_schema(const std::vector<ColumnDefinition>& children,
95
                                               std::span<const StructChildSelector> selectors,
96
                                               LocalColumnIndex* projection);
97
98
} // namespace doris::format