be/src/util/variant/variant_field.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 <memory> |
22 | | |
23 | | #include "core/string_ref.h" |
24 | | #include "util/variant/variant_value.h" |
25 | | |
26 | | namespace doris { |
27 | | |
28 | | // Validate a complete metadata dictionary, including every UTF-8 key. Call this once before |
29 | | // validating one or more payloads that reference the same dictionary. |
30 | | void validate_variant_metadata(VariantMetadataRef metadata); |
31 | | |
32 | | // Validate exactly one recursive Variant payload. The referenced metadata must already have |
33 | | // passed validate_variant_metadata(). |
34 | | void validate_variant_payload(VariantValueRef value); |
35 | | |
36 | | // Owns one encoded Variant row. The byte layout is |
37 | | // [u32 little-endian metadata_size][metadata][exactly one value]. |
38 | | class VariantField { |
39 | | public: |
40 | | VariantField() noexcept = default; |
41 | 303 | ~VariantField() = default; |
42 | | |
43 | | VariantField(const VariantField& other); |
44 | | VariantField(VariantField&& other) noexcept; |
45 | | VariantField& operator=(const VariantField& other); |
46 | | VariantField& operator=(VariantField&& other) noexcept; |
47 | | |
48 | | // Both entry points validate the complete row once, then own a byte-for-byte copy; |
49 | | // decode never borrows the input buffer. |
50 | | static VariantField encode(VariantValueRef value); |
51 | | static VariantField decode(StringRef bytes); |
52 | | |
53 | | // The returned view borrows this field and is invalidated by assignment or destruction. It is |
54 | | // O(1) and does not revalidate. Default and moved-from fields have empty bytes(), and ref() |
55 | | // throws for them. |
56 | | VariantValueRef ref() const; |
57 | | StringRef bytes() const noexcept; |
58 | | |
59 | | // VariantField has no ordering or equality contract; all six comparisons always throw. |
60 | | bool operator<(const VariantField&) const; |
61 | | bool operator<=(const VariantField&) const; |
62 | | bool operator==(const VariantField&) const; |
63 | | bool operator!=(const VariantField&) const; |
64 | | bool operator>=(const VariantField&) const; |
65 | | bool operator>(const VariantField&) const; |
66 | | |
67 | | private: |
68 | | VariantField(std::unique_ptr<char[]> data, size_t size) noexcept; |
69 | | void swap(VariantField& other) noexcept; |
70 | | |
71 | | std::unique_ptr<char[]> _data; |
72 | | size_t _size = 0; |
73 | | }; |
74 | | |
75 | | } // namespace doris |