Coverage Report

Created: 2026-07-30 02:46

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/function/function_variant_element_v2.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 <cstdint>
21
#include <memory>
22
#include <span>
23
24
#include "common/status.h"
25
#include "core/column/column.h"
26
#include "core/string_ref.h"
27
28
namespace doris {
29
30
class ColumnVariantV2;
31
32
class VariantElementV2PathSegment {
33
public:
34
    enum class Kind : uint8_t { OBJECT_KEY, ARRAY_INDEX };
35
36
20
    static VariantElementV2PathSegment object_key(StringRef key) {
37
20
        return {Kind::OBJECT_KEY, key, 0};
38
20
    }
39
40
    // Non-negative indexes are zero-based. Negative indexes address elements from the end, so -1
41
    // selects the last element.
42
5
    static VariantElementV2PathSegment array_index(int64_t index) {
43
5
        return {Kind::ARRAY_INDEX, {}, index};
44
5
    }
45
46
50
    Kind kind() const noexcept { return _kind; }
47
116
    StringRef key() const noexcept { return _key; }
48
25
    int64_t index() const noexcept { return _index; }
49
50
private:
51
    VariantElementV2PathSegment(Kind kind, StringRef key, int64_t index)
52
25
            : _kind(kind), _key(key), _index(index) {}
53
54
    Kind _kind;
55
    StringRef _key;
56
    int64_t _index;
57
};
58
59
// Owns an explicit, already-tokenized path. It intentionally does not parse dotted strings: the
60
// runtime SQL adapter contract remains deferred until the coordinated Variant V2 cutover.
61
class ResolvedVariantElementV2Path {
62
public:
63
    ~ResolvedVariantElementV2Path();
64
    ResolvedVariantElementV2Path(ResolvedVariantElementV2Path&&) noexcept;
65
    ResolvedVariantElementV2Path& operator=(ResolvedVariantElementV2Path&&) noexcept;
66
67
    ResolvedVariantElementV2Path(const ResolvedVariantElementV2Path&) = delete;
68
    ResolvedVariantElementV2Path& operator=(const ResolvedVariantElementV2Path&) = delete;
69
70
    size_t size() const noexcept;
71
    VariantElementV2PathSegment::Kind kind_at(size_t position) const;
72
    StringRef object_key_at(size_t position) const;
73
    int64_t array_index_at(size_t position) const;
74
75
private:
76
    struct Impl;
77
    explicit ResolvedVariantElementV2Path(std::unique_ptr<Impl> impl);
78
79
    friend Status resolve_variant_element_v2_path(
80
            std::span<const VariantElementV2PathSegment> segments,
81
            std::unique_ptr<ResolvedVariantElementV2Path>* output);
82
83
    std::unique_ptr<Impl> _impl;
84
};
85
86
Status resolve_variant_element_v2_path(std::span<const VariantElementV2PathSegment> segments,
87
                                       std::unique_ptr<ResolvedVariantElementV2Path>* output);
88
89
// The source must be materialized by IFunction routing, which also owns ColumnConst expansion and
90
// supplies the outer SQL-null map. The output is always Nullable(ColumnVariantV2).
91
Status extract_variant_element_v2(const ColumnVariantV2& source,
92
                                  const ResolvedVariantElementV2Path& path,
93
                                  std::span<const uint8_t> outer_nulls, ColumnPtr* output);
94
95
} // namespace doris