Skip to content

Commit e0d6e5e

Browse files
committed
WIP: Add headers for type/field/schema
1 parent f17fd2f commit e0d6e5e

File tree

5 files changed

+593
-2
lines changed

5 files changed

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

0 commit comments

Comments
 (0)