Skip to content

Commit 14a04ba

Browse files
committed
fix test failure
1 parent 7a34102 commit 14a04ba

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

src/iceberg/partition_spec.cc

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,10 @@ Status PartitionSpec::ValidatePartitionName(const Schema& schema,
187187
std::unordered_set<std::string> partition_names;
188188
for (const auto& partition_field : spec.fields()) {
189189
auto name = std::string(partition_field.name());
190-
ICEBERG_PRECHECK(!name.empty(), "Cannot use empty partition name: {}", name);
190+
ICEBERG_CHECK(!name.empty(), "Cannot use empty partition name: {}", name);
191191

192-
if (partition_names.contains(name)) {
193-
return InvalidArgument("Cannot use partition name more than once: {}", name);
194-
}
192+
ICEBERG_PRECHECK(!partition_names.contains(name),
193+
"Cannot use partition name more than once: {}", name);
195194
partition_names.insert(name);
196195

197196
ICEBERG_ASSIGN_OR_RAISE(auto schema_field, schema.FindFieldByName(name));
@@ -202,17 +201,15 @@ Status PartitionSpec::ValidatePartitionName(const Schema& schema,
202201
// field name as long as they are sourced from the same schema field
203202
if (schema_field.has_value() &&
204203
schema_field.value().get().field_id() != partition_field.source_id()) {
205-
return InvalidArgument(
204+
return ValidationFailed(
206205
"Cannot create identity partition sourced from different field in schema: {}",
207206
name);
208207
}
209208
} else {
210209
// for all other transforms we don't allow conflicts between partition name and
211210
// schema field name
212-
if (schema_field.has_value()) {
213-
return InvalidArgument(
214-
"Cannot create partition from name that exists in schema: {}", name);
215-
}
211+
ICEBERG_CHECK(!schema_field.has_value(),
212+
"Cannot create partition from name that exists in schema: {}", name);
216213
}
217214
}
218215

@@ -276,9 +273,9 @@ Status PartitionSpec::ValidateRedundantPartitions(const PartitionSpec& spec) {
276273
// Check if this dedup key already exists
277274
// If it does, we have found a redundant partition field
278275
auto existing_field_iter = dedup_fields.find(dedup_key);
279-
ICEBERG_PRECHECK(existing_field_iter == dedup_fields.end(),
280-
"Cannot add redundant partition: {} conflicts with {}",
281-
field.ToString(), existing_field_iter->second->ToString());
276+
ICEBERG_CHECK(existing_field_iter == dedup_fields.end(),
277+
"Cannot add redundant partition: {} conflicts with {}",
278+
field.ToString(), existing_field_iter->second->ToString());
282279

283280
// Add this field to the dedup map for future conflict detection
284281
dedup_fields[dedup_key] = &field;

src/iceberg/test/update_partition_spec_test.cc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -729,39 +729,41 @@ TEST_P(UpdatePartitionSpecTest, TestRemoveAndAddMultiTimes) {
729729
update3->AddField(Expressions::Day("ts"), "ts_date");
730730
auto add_second_time_spec = ApplyUpdateAndGetSpec(update3);
731731

732-
// Remove second time
733-
auto table3 = CreateTableWithSpec(add_second_time_spec, "test_table3");
734-
auto update4 = CreateUpdateFromTable(table3);
735-
update4->RemoveField(Expressions::Day("ts"));
736-
auto remove_second_time_spec = ApplyUpdateAndGetSpec(update4);
737-
738732
// Add third time with month
739-
auto table4 = CreateTableWithSpec(remove_second_time_spec, "test_table4");
733+
auto table4 = CreateTableWithSpec(add_second_time_spec, "test_table4");
740734
auto update5 = CreateUpdateFromTable(table4);
741-
update5->AddField(Expressions::Month("ts"));
735+
update5->AddField(Expressions::Month("ts"), "ts_month");
742736
auto add_third_time_spec = ApplyUpdateAndGetSpec(update5);
743737

744738
// Rename ts_month to ts_date
745739
auto table5 = CreateTableWithSpec(add_third_time_spec, "test_table5");
746740
auto update6 = CreateUpdateFromTable(table5);
747-
update6->RenameField("ts_month", "ts_date");
741+
update6->RenameField("ts_month", "__ts_date");
748742
auto updated_spec = ApplyUpdateAndGetSpec(update6);
749743

750744
if (format_version_ == 1) {
745+
// Remove second time
746+
auto table3 = CreateTableWithSpec(add_second_time_spec, "test_table3");
747+
auto update4 = CreateUpdateFromTable(table3);
748+
update4->RemoveField(Expressions::Day("ts"));
749+
ExpectError(update4, ErrorKind::kValidationFailed,
750+
"Cannot add redundant partition: ts_date");
751+
751752
ASSERT_EQ(updated_spec->fields().size(), 3);
752753
// In V1, we expect void transforms for deleted fields
753754
EXPECT_TRUE(updated_spec->fields()[0].name().find("ts_date") == 0);
754755
EXPECT_TRUE(updated_spec->fields()[1].name().find("ts_date") == 0);
755-
EXPECT_EQ(updated_spec->fields()[2].name(), "ts_date");
756+
EXPECT_EQ(updated_spec->fields()[2].name(), "__ts_date");
756757
EXPECT_EQ(*updated_spec->fields()[0].transform(), *Transform::Void());
757-
EXPECT_EQ(*updated_spec->fields()[1].transform(), *Transform::Void());
758+
EXPECT_EQ(*updated_spec->fields()[1].transform(), *Transform::Day());
758759
EXPECT_EQ(*updated_spec->fields()[2].transform(), *Transform::Month());
759760
} else {
760761
ICEBERG_UNWRAP_OR_FAIL(
761762
auto expected_spec,
762763
PartitionSpec::Make(PartitionSpec::kInitialSpecId,
763764
std::vector<PartitionField>{
764-
PartitionField(2, 1000, "ts_date", Transform::Month())},
765+
PartitionField(2, 1000, "ts_date", Transform::Day()),
766+
PartitionField(2, 1001, "__ts_date", Transform::Month())},
765767
1000));
766768
auto expected = std::shared_ptr<PartitionSpec>(expected_spec.release());
767769
AssertPartitionSpecEquals(*expected, *updated_spec);

0 commit comments

Comments
 (0)