Skip to content

Commit 6450898

Browse files
committed
fix rebase conflict
1 parent 04cc8d3 commit 6450898

4 files changed

Lines changed: 20 additions & 47 deletions

File tree

src/iceberg/json_internal.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,8 @@ Result<std::unique_ptr<Schema>> SchemaFromJson(const nlohmann::json& json) {
488488
auto identifier_field_ids,
489489
GetJsonValueOrDefault<std::vector<int32_t>>(json, kIdentifierFieldIds));
490490

491-
return std::make_unique<Schema>(std::move(fields),
492-
schema_id_opt.value_or(Schema::kInitialSchemaId),
493-
std::move(identifier_field_ids));
491+
return Schema::Make(std::move(fields), schema_id_opt.value_or(Schema::kInitialSchemaId),
492+
std::move(identifier_field_ids));
494493
}
495494

496495
nlohmann::json ToJson(const PartitionField& partition_field) {

src/iceberg/schema.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@ class ICEBERG_EXPORT Schema : public StructType {
5454

5555
explicit Schema(std::vector<SchemaField> fields, int32_t schema_id = kInitialSchemaId);
5656

57-
explicit Schema(std::vector<SchemaField> fields,
58-
std::optional<int32_t> schema_id = std::nullopt);
59-
6057
/// \brief Create a schema.
6158
///
6259
/// \param fields The fields that make up the schema.
@@ -77,7 +74,7 @@ class ICEBERG_EXPORT Schema : public StructType {
7774
/// \return A new Schema instance or Status if failed.
7875
static Result<std::unique_ptr<Schema>> Make(
7976
std::vector<SchemaField> fields, int32_t schema_id,
80-
const std::vector<std::string>& identifier_field_names = {});
77+
const std::vector<std::string>& identifier_field_names);
8178

8279
/// \brief Get an empty schema.
8380
///

src/iceberg/test/metadata_serde_test.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,13 @@ TEST(MetadataSerdeTest, DeserializeV2Valid) {
139139
/*optional=*/false)},
140140
/*schema_id=*/0);
141141

142-
auto expected_schema_2 = std::make_shared<Schema>(
143-
std::vector<SchemaField>{SchemaField::MakeRequired(1, "x", int64()),
144-
SchemaField::MakeRequired(2, "y", int64()),
145-
SchemaField::MakeRequired(3, "z", int64())},
146-
/*schema_id=*/1,
147-
/*identifier_field_ids=*/std::vector<int32_t>{1, 2});
142+
ICEBERG_UNWRAP_OR_FAIL(
143+
std::shared_ptr<Schema> expected_schema_2,
144+
Schema::Make(std::vector<SchemaField>{SchemaField::MakeRequired(1, "x", int64()),
145+
SchemaField::MakeRequired(2, "y", int64()),
146+
SchemaField::MakeRequired(3, "z", int64())},
147+
/*schema_id=*/1,
148+
/*identifier_field_ids=*/std::vector<int32_t>{1, 2}));
148149

149150
auto expected_spec_result = PartitionSpec::Make(
150151
/*spec_id=*/0,

src/iceberg/test/table_metadata_builder_test.cc

Lines changed: 10 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,15 @@ std::shared_ptr<Schema> CreateTestSchema() {
4949
return std::make_shared<Schema>(std::vector<SchemaField>{field1, field2, field3}, 0);
5050
}
5151

52-
// Helper function to create a simple schema with invalid identifier fields
53-
std::shared_ptr<Schema> CreateInvalidSchema() {
54-
auto field1 = SchemaField::MakeRequired(2, "id", int32());
55-
auto field2 = SchemaField::MakeRequired(5, "part_col", string());
56-
auto field3 = SchemaField::MakeRequired(8, "sort_col", timestamp());
57-
return std::make_shared<Schema>(std::vector<SchemaField>{field1, field2, field3},
58-
/*schema_id=*/1,
59-
/*identifier_field_ids=*/std::vector<int32_t>{10});
60-
}
61-
6252
// Helper function to create a simple schema with disordered field_ids
63-
std::shared_ptr<Schema> CreateDisorderedSchema() {
53+
Result<std::unique_ptr<Schema>> CreateDisorderedSchema() {
6454
auto field1 = SchemaField::MakeRequired(2, "id", int32());
6555
auto field2 = SchemaField::MakeRequired(5, "part_col", string());
6656
auto field3 = SchemaField::MakeRequired(8, "sort_col", timestamp());
67-
return std::make_shared<Schema>(std::vector<SchemaField>{field1, field2, field3},
68-
/*schema_id=*/1,
69-
/*identifier_field_ids=*/std::vector<int32_t>{2});
57+
58+
return Schema::Make(std::vector<SchemaField>{field1, field2, field3},
59+
/*schema_id=*/1,
60+
/*identifier_field_ids=*/std::vector<int32_t>{2});
7061
}
7162

7263
// Helper function to create base metadata for tests
@@ -95,7 +86,7 @@ std::unique_ptr<TableMetadata> CreateBaseMetadata() {
9586

9687
// test for TableMetadata
9788
TEST(TableMetadataTest, Make) {
98-
auto Schema = CreateDisorderedSchema();
89+
ICEBERG_UNWRAP_OR_FAIL(auto Schema, CreateDisorderedSchema());
9990
ICEBERG_UNWRAP_OR_FAIL(
10091
auto spec, PartitionSpec::Make(1, std::vector<PartitionField>{PartitionField(
10192
5, 1, "part_name", Transform::Identity())}));
@@ -140,23 +131,8 @@ TEST(TableMetadataTest, Make) {
140131
EXPECT_EQ(NullOrder::kLast, order_fields[0].null_order());
141132
}
142133

143-
TEST(TableMetadataTest, MakeWithInvalidSchema) {
144-
auto schema = CreateInvalidSchema();
145-
ICEBERG_UNWRAP_OR_FAIL(
146-
auto spec, PartitionSpec::Make(1, std::vector<PartitionField>{PartitionField(
147-
5, 1, "part_name", Transform::Identity())}));
148-
ICEBERG_UNWRAP_OR_FAIL(
149-
auto order, SortOrder::Make(1, std::vector<SortField>{SortField(
150-
5, Transform::Identity(),
151-
SortDirection::kAscending, NullOrder::kLast)}));
152-
153-
auto res = TableMetadata::Make(*schema, *spec, *order, "s3://bucket/test", {});
154-
EXPECT_THAT(res, IsError(ErrorKind::kInvalidSchema));
155-
EXPECT_THAT(res, HasErrorMessage("Cannot find identifier field id"));
156-
}
157-
158134
TEST(TableMetadataTest, MakeWithInvalidPartitionSpec) {
159-
auto schema = CreateDisorderedSchema();
135+
ICEBERG_UNWRAP_OR_FAIL(auto schema, CreateDisorderedSchema());
160136
ICEBERG_UNWRAP_OR_FAIL(
161137
auto spec, PartitionSpec::Make(1, std::vector<PartitionField>{PartitionField(
162138
6, 1, "part_name", Transform::Identity())}));
@@ -171,7 +147,7 @@ TEST(TableMetadataTest, MakeWithInvalidPartitionSpec) {
171147
}
172148

173149
TEST(TableMetadataTest, MakeWithInvalidSortOrder) {
174-
auto schema = CreateDisorderedSchema();
150+
ICEBERG_UNWRAP_OR_FAIL(auto schema, CreateDisorderedSchema());
175151
ICEBERG_UNWRAP_OR_FAIL(
176152
auto spec, PartitionSpec::Make(1, std::vector<PartitionField>{PartitionField(
177153
5, 1, "part_name", Transform::Identity())}));
@@ -191,7 +167,7 @@ TEST(TableMetadataTest, InvalidProperties) {
191167

192168
{
193169
// Invalid metrics config
194-
auto schema = CreateDisorderedSchema();
170+
ICEBERG_UNWRAP_OR_FAIL(auto schema, CreateDisorderedSchema());
195171
std::unordered_map<std::string, std::string> invlaid_metric_config = {
196172
{std::string(TableProperties::kMetricModeColumnConfPrefix) + "unknown_col",
197173
"value"}};
@@ -204,7 +180,7 @@ TEST(TableMetadataTest, InvalidProperties) {
204180

205181
{
206182
// Invaid commit properties
207-
auto schema = CreateDisorderedSchema();
183+
ICEBERG_UNWRAP_OR_FAIL(auto schema, CreateDisorderedSchema());
208184
std::unordered_map<std::string, std::string> invlaid_commit_properties = {
209185
{TableProperties::kCommitNumRetries.key(), "-1"}};
210186

0 commit comments

Comments
 (0)