Skip to content

Commit 3846d96

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

File tree

11 files changed

+1108
-3
lines changed

11 files changed

+1108
-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 schema.cc schema_field.cc type.cc)
1919

2020
add_iceberg_lib(iceberg
2121
SOURCES

src/iceberg/schema.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
#include "iceberg/schema.h"
21+
22+
#include <format>
23+
24+
#include "iceberg/type.h"
25+
#include "iceberg/util/formatter.h"
26+
27+
namespace iceberg {
28+
29+
Schema::Schema(int32_t schema_id, std::vector<SchemaField> fields)
30+
: StructType(std::move(fields)), schema_id_(schema_id) {}
31+
32+
int32_t Schema::schema_id() const { return schema_id_; }
33+
34+
std::string Schema::ToString() const {
35+
std::string repr = "schema<";
36+
for (const auto& field : fields_) {
37+
std::format_to(std::back_inserter(repr), " {}\n", field);
38+
}
39+
repr += ">";
40+
return repr;
41+
}
42+
43+
bool Schema::Equals(const Schema& other) const {
44+
return schema_id_ == other.schema_id_ && fields_ == other.fields_;
45+
}
46+
47+
} // namespace iceberg

src/iceberg/schema.h

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
[[nodiscard]] std::string ToString() const;
52+
53+
friend bool operator==(const Schema& lhs, const Schema& rhs) { return lhs.Equals(rhs); }
54+
55+
friend bool operator!=(const Schema& lhs, const Schema& rhs) { return !(lhs == rhs); }
56+
57+
private:
58+
/// \brief Compare two schemas for equality.
59+
[[nodiscard]] bool Equals(const Schema& other) const;
60+
61+
const int32_t schema_id_;
62+
};
63+
64+
} // namespace iceberg

src/iceberg/schema_field.cc

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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+
#include "iceberg/schema_field.h"
21+
22+
#include <format>
23+
24+
#include "iceberg/type.h"
25+
#include "iceberg/util/formatter.h"
26+
27+
namespace iceberg {
28+
29+
SchemaField::SchemaField(int32_t field_id, std::string name, std::shared_ptr<Type> type,
30+
bool optional)
31+
: field_id_(field_id),
32+
name_(std::move(name)),
33+
type_(std::move(type)),
34+
optional_(optional) {}
35+
36+
SchemaField SchemaField::MakeOptional(int32_t field_id, std::string name,
37+
std::shared_ptr<Type> type) {
38+
return SchemaField(field_id, std::move(name), std::move(type), true);
39+
}
40+
41+
SchemaField SchemaField::MakeRequired(int32_t field_id, std::string name,
42+
std::shared_ptr<Type> type) {
43+
return SchemaField(field_id, std::move(name), std::move(type), false);
44+
}
45+
46+
int32_t SchemaField::field_id() const { return field_id_; }
47+
48+
std::string_view SchemaField::name() const { return name_; }
49+
50+
const std::shared_ptr<Type>& SchemaField::type() const { return type_; }
51+
52+
bool SchemaField::optional() const { return optional_; }
53+
54+
std::string SchemaField::ToString() const {
55+
return std::format("{} ({}): {}{}", name_, field_id_, *type_,
56+
optional_ ? "" : " (required)");
57+
}
58+
59+
bool SchemaField::Equals(const SchemaField& other) const {
60+
return field_id_ == other.field_id_ && name_ == other.name_ && *type_ == *other.type_ &&
61+
optional_ == other.optional_;
62+
}
63+
64+
} // 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/schema_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+
[[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)