Skip to content

Commit 4f5bd35

Browse files
author
nullccxsy
committed
refactor: simplify Schema and StructType constructors and remove copy/move operations
- Removed copy and move constructors and assignment operators from Schema and StructType to streamline resource management.
1 parent 3a4dd3b commit 4f5bd35

File tree

8 files changed

+20
-137
lines changed

8 files changed

+20
-137
lines changed

src/iceberg/manifest_list.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ struct ICEBERG_EXPORT ManifestFile {
185185
507, "partitions",
186186
std::make_shared<ListType>(SchemaField::MakeRequired(
187187
508, std::string(ListType::kElementName),
188-
std::make_shared<StructType>(PartitionFieldSummary::Type()))),
188+
struct_(
189+
{PartitionFieldSummary::kContainsNull, PartitionFieldSummary::kContainsNaN,
190+
PartitionFieldSummary::kLowerBound, PartitionFieldSummary::kUpperBound}))),
189191
"Summary for each partition");
190192
inline static const SchemaField kKeyMetadata = SchemaField::MakeOptional(
191193
519, "key_metadata", iceberg::binary(), "Encryption key metadata blob");

src/iceberg/schema.cc

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,6 @@ class NameToIdVisitor {
7171
Schema::Schema(std::vector<SchemaField> fields, std::optional<int32_t> schema_id)
7272
: StructType(std::move(fields)), schema_id_(schema_id) {}
7373

74-
Schema::Schema(Schema&& other) noexcept
75-
: StructType(std::move(other)),
76-
schema_id_(other.schema_id_),
77-
id_to_field_(std::move(other.id_to_field_)),
78-
name_to_id_(std::move(other.name_to_id_)),
79-
lowercase_name_to_id_(std::move(other.lowercase_name_to_id_)) {}
80-
81-
Schema& Schema::operator=(const Schema& other) {
82-
if (this != &other) {
83-
StructType::operator=(other);
84-
schema_id_ = other.schema_id_;
85-
id_to_field_ = other.id_to_field_;
86-
name_to_id_ = other.name_to_id_;
87-
lowercase_name_to_id_ = other.lowercase_name_to_id_;
88-
}
89-
return *this;
90-
}
91-
92-
Schema::Schema(const Schema& other)
93-
: StructType(other),
94-
schema_id_(other.schema_id_),
95-
id_to_field_(other.id_to_field_),
96-
name_to_id_(other.name_to_id_),
97-
lowercase_name_to_id_(other.lowercase_name_to_id_) {}
98-
99-
Schema& Schema::operator=(Schema&& other) noexcept {
100-
if (this != &other) {
101-
StructType::operator=(std::move(other));
102-
schema_id_ = other.schema_id_;
103-
id_to_field_ = std::move(other.id_to_field_);
104-
name_to_id_ = std::move(other.name_to_id_);
105-
lowercase_name_to_id_ = std::move(other.lowercase_name_to_id_);
106-
}
107-
return *this;
108-
}
109-
11074
std::optional<int32_t> Schema::schema_id() const { return schema_id_; }
11175

11276
std::string Schema::ToString() const {

src/iceberg/schema.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,6 @@ class ICEBERG_EXPORT Schema : public StructType {
4949
explicit Schema(std::vector<SchemaField> fields,
5050
std::optional<int32_t> schema_id = std::nullopt);
5151

52-
Schema(const Schema& other);
53-
Schema(Schema&& other) noexcept;
54-
Schema& operator=(const Schema& other);
55-
Schema& operator=(Schema&& other) noexcept;
5652
/// \brief Get the schema ID.
5753
///
5854
/// A schema is identified by a unique ID for the purposes of schema

src/iceberg/type.cc

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -48,34 +48,6 @@ std::string StructType::ToString() const {
4848
return repr;
4949
}
5050
std::span<const SchemaField> StructType::fields() const { return fields_; }
51-
StructType::StructType(const StructType& other)
52-
: fields_(other.fields_),
53-
field_by_id_(other.field_by_id_),
54-
field_by_name_(other.field_by_name_),
55-
field_by_lowercase_name_(other.field_by_lowercase_name_) {}
56-
StructType::StructType(StructType&& other) noexcept
57-
: fields_(std::move(other.fields_)),
58-
field_by_id_(std::move(other.field_by_id_)),
59-
field_by_name_(std::move(other.field_by_name_)),
60-
field_by_lowercase_name_(std::move(other.field_by_lowercase_name_)) {}
61-
StructType& StructType::operator=(const StructType& other) {
62-
if (*this != other) {
63-
fields_ = other.fields_;
64-
field_by_id_ = other.field_by_id_;
65-
field_by_name_ = other.field_by_name_;
66-
field_by_lowercase_name_ = other.field_by_lowercase_name_;
67-
}
68-
return *this;
69-
}
70-
StructType& StructType::operator=(StructType&& other) noexcept {
71-
if (*this != other) {
72-
fields_ = std::move(other.fields_);
73-
field_by_id_ = std::move(other.field_by_id_);
74-
field_by_name_ = std::move(other.field_by_name_);
75-
field_by_lowercase_name_ = std::move(other.field_by_lowercase_name_);
76-
}
77-
return *this;
78-
}
7951
Result<std::optional<NestedType::SchemaFieldConstRef>> StructType::GetFieldById(
8052
int32_t field_id) const {
8153
ICEBERG_RETURN_UNEXPECTED(

src/iceberg/type.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,6 @@ class ICEBERG_EXPORT StructType : public NestedType {
117117
constexpr static TypeId kTypeId = TypeId::kStruct;
118118
explicit StructType(std::vector<SchemaField> fields);
119119
~StructType() override = default;
120-
StructType(const StructType&);
121-
StructType(StructType&&) noexcept;
122-
StructType& operator=(const StructType&);
123-
StructType& operator=(StructType&&) noexcept;
124120

125121
TypeId type_id() const override;
126122
std::string ToString() const override;

test/avro_data_test.cc

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,16 +1195,16 @@ TEST(ExtractDatumFromArrayTest, NullHandling) {
11951195

11961196
struct RoundTripParam {
11971197
std::string name;
1198-
Schema iceberg_schema;
1198+
std::shared_ptr<Schema> iceberg_schema;
11991199
std::string arrow_json;
12001200
};
12011201

12021202
void VerifyRoundTripConversion(const RoundTripParam& test_case) {
12031203
::avro::NodePtr avro_node;
1204-
ASSERT_THAT(ToAvroNodeVisitor{}.Visit(test_case.iceberg_schema, &avro_node), IsOk());
1204+
ASSERT_THAT(ToAvroNodeVisitor{}.Visit(*test_case.iceberg_schema, &avro_node), IsOk());
12051205

12061206
ArrowSchema arrow_c_schema;
1207-
ASSERT_THAT(ToArrowSchema(test_case.iceberg_schema, &arrow_c_schema), IsOk());
1207+
ASSERT_THAT(ToArrowSchema(*test_case.iceberg_schema, &arrow_c_schema), IsOk());
12081208
auto arrow_schema = ::arrow::ImportSchema(&arrow_c_schema).ValueOrDie();
12091209
auto arrow_struct_type = std::make_shared<::arrow::StructType>(arrow_schema->fields());
12101210

@@ -1221,14 +1221,14 @@ void VerifyRoundTripConversion(const RoundTripParam& test_case) {
12211221
}
12221222

12231223
auto projection_result =
1224-
Project(test_case.iceberg_schema, avro_node, /*prune_source=*/false);
1224+
Project(*test_case.iceberg_schema, avro_node, /*prune_source=*/false);
12251225
ASSERT_THAT(projection_result, IsOk());
12261226
auto projection = std::move(projection_result.value());
12271227

12281228
auto builder = ::arrow::MakeBuilder(arrow_struct_type).ValueOrDie();
12291229
for (const auto& datum : extracted_data) {
12301230
ASSERT_THAT(AppendDatumToBuilder(avro_node, datum, projection,
1231-
test_case.iceberg_schema, builder.get()),
1231+
*test_case.iceberg_schema, builder.get()),
12321232
IsOk());
12331233
}
12341234

@@ -1249,7 +1249,7 @@ TEST_P(AvroRoundTripConversionTest, ConvertTypes) {
12491249
const std::vector<RoundTripParam> kRoundTripTestCases = {
12501250
{
12511251
.name = "SimpleStruct",
1252-
.iceberg_schema = Schema({
1252+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
12531253
SchemaField::MakeRequired(1, "id", int32()),
12541254
SchemaField::MakeRequired(2, "name", string()),
12551255
SchemaField::MakeOptional(3, "age", int32()),
@@ -1262,7 +1262,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
12621262
},
12631263
{
12641264
.name = "PrimitiveTypes",
1265-
.iceberg_schema = Schema({
1265+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
12661266
SchemaField::MakeRequired(1, "bool_field", boolean()),
12671267
SchemaField::MakeRequired(2, "int_field", int32()),
12681268
SchemaField::MakeRequired(3, "long_field", int64()),
@@ -1277,7 +1277,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
12771277
},
12781278
{
12791279
.name = "NestedStruct",
1280-
.iceberg_schema = Schema({
1280+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
12811281
SchemaField::MakeRequired(1, "id", int32()),
12821282
SchemaField::MakeRequired(
12831283
2, "person",
@@ -1293,7 +1293,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
12931293
},
12941294
{
12951295
.name = "ListOfIntegers",
1296-
.iceberg_schema = Schema({
1296+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
12971297
SchemaField::MakeRequired(
12981298
1, "numbers",
12991299
std::make_shared<ListType>(
@@ -1307,7 +1307,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
13071307
},
13081308
{
13091309
.name = "MapStringToInt",
1310-
.iceberg_schema = Schema({
1310+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
13111311
SchemaField::MakeRequired(
13121312
1, "scores",
13131313
std::make_shared<MapType>(
@@ -1322,7 +1322,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
13221322
},
13231323
{
13241324
.name = "ComplexNested",
1325-
.iceberg_schema = Schema({
1325+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
13261326
SchemaField::MakeRequired(
13271327
1, "data",
13281328
std::make_shared<StructType>(std::vector<SchemaField>{
@@ -1345,7 +1345,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
13451345
},
13461346
{
13471347
.name = "NullablePrimitives",
1348-
.iceberg_schema = Schema({
1348+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
13491349
SchemaField::MakeOptional(1, "optional_bool", boolean()),
13501350
SchemaField::MakeOptional(2, "optional_int", int32()),
13511351
SchemaField::MakeOptional(3, "optional_long", int64()),
@@ -1361,7 +1361,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
13611361
},
13621362
{
13631363
.name = "NullableNestedStruct",
1364-
.iceberg_schema = Schema({
1364+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
13651365
SchemaField::MakeRequired(1, "id", int32()),
13661366
SchemaField::MakeOptional(
13671367
2, "person",
@@ -1381,7 +1381,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
13811381
},
13821382
{
13831383
.name = "NullableListElements",
1384-
.iceberg_schema = Schema({
1384+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
13851385
SchemaField::MakeRequired(1, "id", int32()),
13861386
SchemaField::MakeOptional(
13871387
2, "numbers",
@@ -1401,7 +1401,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
14011401
},
14021402
{
14031403
.name = "NullableMapValues",
1404-
.iceberg_schema = Schema({
1404+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
14051405
SchemaField::MakeRequired(1, "id", int32()),
14061406
SchemaField::MakeOptional(
14071407
2, "scores",
@@ -1423,7 +1423,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
14231423
},
14241424
{
14251425
.name = "DeeplyNestedWithNulls",
1426-
.iceberg_schema = Schema({
1426+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
14271427
SchemaField::MakeRequired(
14281428
1, "root",
14291429
std::make_shared<StructType>(std::vector<SchemaField>{
@@ -1452,7 +1452,7 @@ const std::vector<RoundTripParam> kRoundTripTestCases = {
14521452
},
14531453
{
14541454
.name = "AllNullsVariations",
1455-
.iceberg_schema = Schema({
1455+
.iceberg_schema = std::make_shared<Schema>(std::vector<SchemaField>{
14561456
SchemaField::MakeOptional(1, "always_null", string()),
14571457
SchemaField::MakeOptional(2, "sometimes_null", int32()),
14581458
SchemaField::MakeOptional(

test/schema_test.cc

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -559,26 +559,3 @@ TEST_F(SchemaThreadSafetyTest, MixedConcurrentOperations) {
559559
thread.join();
560560
}
561561
}
562-
563-
TEST_F(SchemaThreadSafetyTest, CopyAndConcurrentAccess) {
564-
const int num_threads = 5;
565-
const int iterations_per_thread = 20;
566-
std::vector<std::thread> threads;
567-
auto schema_copy = *schema_;
568-
569-
for (int i = 0; i < num_threads; ++i) {
570-
threads.emplace_back([this, &schema_copy, iterations_per_thread, i]() {
571-
for (int j = 0; j < iterations_per_thread; ++j) {
572-
if (i % 2 == 0) {
573-
ASSERT_THAT(schema_->FindFieldById(1), ::testing::Optional(*field1_));
574-
} else {
575-
ASSERT_THAT(schema_copy.FindFieldById(1), ::testing::Optional(*field1_));
576-
}
577-
}
578-
});
579-
}
580-
581-
for (auto& thread : threads) {
582-
thread.join();
583-
}
584-
}

test/type_test.cc

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -604,27 +604,3 @@ TEST_F(StructTypeThreadSafetyTest, MixedConcurrentOperations) {
604604
thread.join();
605605
}
606606
}
607-
608-
TEST_F(StructTypeThreadSafetyTest, CopyAndConcurrentAccess) {
609-
const int num_threads = 5;
610-
const int iterations_per_thread = 20;
611-
std::vector<std::thread> threads;
612-
613-
auto struct_copy = *struct_type_;
614-
615-
for (int i = 0; i < num_threads; ++i) {
616-
threads.emplace_back([this, &struct_copy, iterations_per_thread, i]() {
617-
for (int j = 0; j < iterations_per_thread; ++j) {
618-
if (i % 2 == 0) {
619-
ASSERT_THAT(struct_type_->GetFieldById(1), ::testing::Optional(*field1_));
620-
} else {
621-
ASSERT_THAT(struct_copy.GetFieldById(1), ::testing::Optional(*field1_));
622-
}
623-
}
624-
});
625-
}
626-
627-
for (auto& thread : threads) {
628-
thread.join();
629-
}
630-
}

0 commit comments

Comments
 (0)