iceberg-cpp
Loading...
Searching...
No Matches
schema_field.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
25
26#include <cstdint>
27#include <memory>
28#include <string>
29#include <string_view>
30
31#include "iceberg/iceberg_export.h"
32#include "iceberg/result.h"
33#include "iceberg/type_fwd.h"
35
36namespace iceberg {
37
39class ICEBERG_EXPORT SchemaField : public iceberg::util::Formattable {
40 public:
41 static constexpr int32_t kInvalidFieldId = -1;
42
49 SchemaField(int32_t field_id, std::string_view name, std::shared_ptr<Type> type,
50 bool optional, std::string_view doc = {});
51
53 static SchemaField MakeOptional(int32_t field_id, std::string_view name,
54 std::shared_ptr<Type> type, std::string_view doc = {});
56 static SchemaField MakeRequired(int32_t field_id, std::string_view name,
57 std::shared_ptr<Type> type, std::string_view doc = {});
58
60 [[nodiscard]] int32_t field_id() const;
61
63 [[nodiscard]] std::string_view name() const;
64
66 [[nodiscard]] const std::shared_ptr<Type>& type() const;
67
69 [[nodiscard]] bool optional() const;
70
72 std::string_view doc() const;
73
74 [[nodiscard]] std::string ToString() const override;
75
76 Status Validate() const;
77
78 friend bool operator==(const SchemaField& lhs, const SchemaField& rhs) {
79 return lhs.Equals(rhs);
80 }
81
82 SchemaField AsRequired() const {
83 auto copy = *this;
84 copy.optional_ = false;
85 return copy;
86 }
87
88 SchemaField AsOptional() const {
89 auto copy = *this;
90 copy.optional_ = true;
91 return copy;
92 }
93
94 private:
96 [[nodiscard]] bool Equals(const SchemaField& other) const;
97
98 int32_t field_id_;
99 std::string name_;
100 std::shared_ptr<Type> type_;
101 bool optional_;
102 std::string doc_;
103};
104
105} // namespace iceberg
A type combined with a name.
Definition schema_field.h:39
Interface for objects that can be formatted via std::format.
Definition formattable.h:36