Coverage Report

Created: 2026-07-14 20:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/util/variant/variant_encoded_block.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 <cstdint>
22
#include <memory>
23
#include <span>
24
25
#include "core/string_ref.h"
26
#include "util/variant/variant_metadata.h"
27
#include "util/variant/variant_value.h"
28
29
namespace doris {
30
31
class VariantBlockBuilder;
32
struct VariantEncodedBlockStorage;
33
34
// Borrows one immutable shared-metadata encoding unit. Offsets are directly compatible with
35
// ColumnString and always contain num_rows() + 1 entries.
36
class VariantEncodedBlockView {
37
public:
38
    size_t num_rows() const noexcept;
39
109
    VariantMetadataRef metadata_ref() const noexcept { return _metadata; }
40
    VariantValueRef value_at(size_t row) const;
41
63
    StringRef value_bytes() const noexcept { return _values; }
42
65
    std::span<const uint32_t> value_offsets() const noexcept { return _offsets; }
43
44
private:
45
    friend class VariantEncodedBlock;
46
47
    VariantEncodedBlockView(VariantMetadataRef metadata, StringRef values,
48
                            std::span<const uint32_t> offsets) noexcept
49
25.1k
            : _metadata(metadata), _values(values), _offsets(offsets) {}
50
51
    VariantMetadataRef _metadata;
52
    StringRef _values;
53
    std::span<const uint32_t> _offsets;
54
};
55
56
// Owns one immutable two-pass encoding unit. Views and value refs remain valid until this block is
57
// destroyed or moved.
58
class VariantEncodedBlock {
59
public:
60
    VariantEncodedBlock(VariantEncodedBlock&&) noexcept;
61
    VariantEncodedBlock& operator=(VariantEncodedBlock&&) noexcept;
62
    ~VariantEncodedBlock();
63
64
    VariantEncodedBlock(const VariantEncodedBlock&) = delete;
65
    VariantEncodedBlock& operator=(const VariantEncodedBlock&) = delete;
66
67
    VariantEncodedBlockView view() const noexcept;
68
    size_t num_rows() const noexcept { return view().num_rows(); }
69
    VariantMetadataRef metadata_ref() const noexcept { return view().metadata_ref(); }
70
12.6k
    VariantValueRef value_at(size_t row) const { return view().value_at(row); }
71
    StringRef value_bytes() const noexcept { return view().value_bytes(); }
72
    std::span<const uint32_t> value_offsets() const noexcept { return view().value_offsets(); }
73
74
private:
75
    friend class VariantBlockBuilder;
76
77
    explicit VariantEncodedBlock(std::unique_ptr<VariantEncodedBlockStorage> storage) noexcept;
78
79
    std::unique_ptr<VariantEncodedBlockStorage> _storage;
80
};
81
82
} // namespace doris