Skip to content

Commit a32ed60

Browse files
committed
Add headers for type/field/schema
1 parent f17fd2f commit a32ed60

File tree

9 files changed

+997
-3
lines changed

9 files changed

+997
-3
lines changed

docs/Doxyfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ INLINE_INHERITED_MEMB = NO
195195
# shortest path that makes the file name unique will be used
196196
# The default value is: YES.
197197

198-
FULL_PATH_NAMES = NO
198+
FULL_PATH_NAMES = YES
199199

200200
# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path.
201201
# Stripping is only done if one of the specified strings matches the left-hand
@@ -207,7 +207,7 @@ FULL_PATH_NAMES = NO
207207
# will be relative from the directory where doxygen is started.
208208
# This tag requires that the tag FULL_PATH_NAMES is set to YES.
209209

210-
STRIP_FROM_PATH =
210+
STRIP_FROM_PATH = ../src
211211

212212
# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the
213213
# path mentioned in the documentation of a class, which tells the reader which

src/iceberg/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
set(ICEBERG_SOURCES demo_table.cc)
18+
set(ICEBERG_SOURCES demo_table.cc type.cc)
1919

2020
add_iceberg_lib(iceberg
2121
SOURCES

src/iceberg/schema.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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+
22+
/// \file iceberg/schema.h
23+
/// Schemas for Iceberg tables. This header contains the definition of Schema
24+
/// and any utility functions. See iceberg/type.h and iceberg/field.h as well.
25+
26+
#include <cstdint>
27+
#include <string>
28+
#include <vector>
29+
30+
#include "iceberg/iceberg_export.h"
31+
#include "iceberg/schema_field.h"
32+
#include "iceberg/type.h"
33+
34+
namespace iceberg {
35+
36+
/// \brief A schema for a Table.
37+
///
38+
/// A schema is a list of typed columns, along with a unique integer ID. A
39+
/// Table may have different schemas over its lifetime due to schema
40+
/// evolution.
41+
class ICEBERG_EXPORT Schema : public StructType {
42+
public:
43+
Schema(int32_t schema_id, std::vector<SchemaField> fields);
44+
45+
/// \brief Get the schema ID.
46+
///
47+
/// Schemas are identified by a unique ID for the purposes of schema
48+
/// evolution.
49+
[[nodiscard]] int32_t schema_id() const;
50+
51+
/// \brief Get a user-readable string representation of the schema.
52+
[[nodiscard]] std::string ToString() const;
53+
54+
friend bool operator==(const Schema& lhs, const Schema& rhs) { return lhs.Equals(rhs); }
55+
56+
friend bool operator!=(const Schema& lhs, const Schema& rhs) { return !(lhs == rhs); }
57+
58+
private:
59+
/// \brief Compare two schemas for equality.
60+
[[nodiscard]] bool Equals(const Schema& other) const;
61+
};
62+
63+
} // namespace iceberg

src/iceberg/schema_field.h

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
22+
/// \file iceberg/field.h
23+
/// A (schema) field is a name and a type and is part of a schema or nested
24+
/// type (e.g. a struct).
25+
26+
#include <cstdint>
27+
#include <memory>
28+
#include <string>
29+
#include <string_view>
30+
31+
#include "iceberg/iceberg_export.h"
32+
#include "iceberg/type_fwd.h"
33+
#include "iceberg/util/formattable.h"
34+
35+
namespace iceberg {
36+
37+
/// \brief A type combined with a name.
38+
class ICEBERG_EXPORT SchemaField : public iceberg::util::Formattable {
39+
public:
40+
/// \brief Construct a field.
41+
/// \param[in] field_id The field ID.
42+
/// \param[in] name The field name.
43+
/// \param[in] type The field type.
44+
/// \param[in] optional Whether values of this field are required or nullable.
45+
SchemaField(int32_t field_id, std::string name, std::shared_ptr<Type> type,
46+
bool optional);
47+
48+
/// \brief Construct an optional (nullable) field.
49+
static SchemaField MakeOptional(int32_t field_id, std::string name,
50+
std::shared_ptr<Type> type);
51+
/// \brief Construct a required (non-null) field.
52+
static SchemaField MakeRequired(int32_t field_id, std::string name,
53+
std::shared_ptr<Type> type);
54+
55+
/// \brief Get the field ID.
56+
[[nodiscard]] int32_t field_id() const;
57+
58+
/// \brief Get the field name.
59+
[[nodiscard]] std::string_view name() const;
60+
61+
/// \brief Get the field type.
62+
[[nodiscard]] const std::shared_ptr<Type>& type() const;
63+
64+
/// \brief Get whether the field is optional.
65+
[[nodiscard]] bool optional() const;
66+
67+
/// \brief Get a user-readable string representation of the field.
68+
[[nodiscard]] std::string ToString() const;
69+
70+
friend bool operator==(const SchemaField& lhs, const SchemaField& rhs) {
71+
return lhs.Equals(rhs);
72+
}
73+
74+
friend bool operator!=(const SchemaField& lhs, const SchemaField& rhs) {
75+
return !(lhs == rhs);
76+
}
77+
78+
private:
79+
/// \brief Compare two fields for equality.
80+
[[nodiscard]] bool Equals(const SchemaField& other) const;
81+
82+
int32_t field_id_;
83+
std::string name_;
84+
std::shared_ptr<Type> type_;
85+
bool optional_;
86+
};
87+
88+
} // namespace iceberg

0 commit comments

Comments
 (0)