Skip to content

Commit d000927

Browse files
committed
fix: use AddFile flags to gate empty-replace check, not DataSpec()
DataSpec() also errors on multi-spec stages, which would silently break a ReplacePartitions that touches files from more than one spec. Use the flags AddFile() sets (replace_by_row_filter_ / replaced_partitions_) instead — the same condition that already gated the no-op early-return below, now promoted to an error to match Java BaseReplacePartitions.
1 parent c2a4a5f commit d000927

1 file changed

Lines changed: 7 additions & 10 deletions

File tree

src/iceberg/update/replace_partitions.cc

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,17 @@ std::string ReplacePartitions::operation() { return DataOperation::kOverwrite; }
9191

9292
Status ReplacePartitions::Validate(const TableMetadata& current_metadata,
9393
const std::shared_ptr<Snapshot>& snapshot) {
94-
// Java's BaseReplacePartitions requires at least one staged data file:
95-
// dataSpec() throws if none was added. Call DataSpec() up front to surface
96-
// the same error here, instead of silently committing an empty snapshot.
97-
ICEBERG_ASSIGN_OR_RAISE(auto data_spec, DataSpec());
94+
// Match Java BaseReplacePartitions: require at least one staged data file.
95+
// Use the flags AddFile() sets — `DataSpec()` would also error on multi-spec
96+
// stages and is not the guard we want here.
97+
if (!replace_by_row_filter_ && replaced_partitions_.empty()) {
98+
return InvalidArgument(
99+
"ReplacePartitions requires at least one data file; call AddFile() first");
100+
}
98101

99102
if (snapshot == nullptr) {
100103
return {};
101104
}
102-
// No-op update: no partitions were staged and no table-wide replace was
103-
// requested, so there is nothing to conflict with. Calling the validators
104-
// with AlwaysTrue here would turn an empty builder into a full-table check.
105-
if (!replace_by_row_filter_ && replaced_partitions_.empty()) {
106-
return {};
107-
}
108105

109106
auto io = ctx_->table->io();
110107
if (validate_conflicting_data_) {

0 commit comments

Comments
 (0)