Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/iceberg/catalog/rest/json_serde.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ constexpr std::string_view kReferencedDataFile = "referenced-data-file";
constexpr std::string_view kContentOffset = "content-offset";
constexpr std::string_view kContentSizeInBytes = "content-size-in-bytes";
constexpr std::string_view kDataFile = "data-file";
constexpr std::string_view kDataSequenceNumber = "data-sequence-number";
constexpr std::string_view kDeleteFileReferences = "delete-file-references";
constexpr std::string_view kResidualFilter = "residual-filter";
constexpr std::string_view kMapKeys = "keys";
Expand Down Expand Up @@ -323,10 +324,11 @@ Result<std::vector<std::shared_ptr<FileScanTask>>> FileScanTasksFromJson(
GetJsonValue<nlohmann::json>(task_json, kDataFile));
ICEBERG_ASSIGN_OR_RAISE(
auto data_file, DataFileFromJson(data_file_json, partition_spec_by_id, schema));
// FIXME: REST scan-task DataFile JSON currently carries first-row-id,
// but not the manifest-entry data sequence number. Until the REST API exposes
// it, REST-planned tasks cannot inherit _last_updated_sequence_number.
// See https://github.com/apache/iceberg-cpp/issues/834.
if (task_json.contains(kDataSequenceNumber) &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we can't do this until the rest spec has adopted data sequence number to the FileScanTask object.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Understood — I'll keep this as a draft blocked on the upstream REST spec adopting the field. I don't plan to file the spec proposal right now; happy to revisit once the protocol supports it. Feel free to close this PR if you'd rather not keep it open in the meantime.

!task_json.at(kDataSequenceNumber).is_null()) {
ICEBERG_ASSIGN_OR_RAISE(data_file.data_sequence_number,
GetJsonValue<int64_t>(task_json, kDataSequenceNumber));
}

std::vector<std::shared_ptr<DataFile>> task_delete_files;
if (task_json.contains(kDeleteFileReferences) &&
Expand Down Expand Up @@ -497,6 +499,10 @@ Result<nlohmann::json> ScanTaskFieldsToJson(
auto data_file_json,
ToJson(*task->data_file(), partition_specs_by_id, schema));
task_json[kDataFile] = std::move(data_file_json);
if (task->data_file()->data_sequence_number.has_value()) {
task_json[kDataSequenceNumber] =
task->data_file()->data_sequence_number.value();
}
}
if (!task->delete_files().empty()) {
std::vector<int32_t> refs;
Expand Down
37 changes: 31 additions & 6 deletions src/iceberg/test/rest_json_serde_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2280,14 +2280,32 @@ TEST(FileScanTasksFromJsonTest, SingleTaskNoDeleteFiles) {
const auto& task = result.value()[0];
ASSERT_NE(task->data_file(), nullptr);
EXPECT_EQ(task->data_file()->file_path, "s3://bucket/data/file.parquet");
EXPECT_FALSE(task->data_file()->data_sequence_number.has_value());
EXPECT_TRUE(task->delete_files().empty());
EXPECT_EQ(task->residual_filter(), nullptr);
}

TEST(FileScanTasksFromJsonTest, RowLineageSequence) {
GTEST_SKIP() << "REST scan-task JSON does not expose data-sequence-number yet: "
<< "https://github.com/apache/iceberg-cpp/issues/834";
TEST(FileScanTasksFromJsonTest, NullDataSequenceNumber) {
auto json = R"([{
"data-file": {
"content": "data",
"file-path": "s3://bucket/data/file.parquet",
"file-format": "PARQUET",
"spec-id": 0,
"partition": [],
"file-size-in-bytes": 12345,
"record-count": 100
},
"data-sequence-number": null
}])"_json;

auto result = FileScanTasksFromJson(json, {}, UnpartitionedSpecs(), Schema({}, 0));
ASSERT_THAT(result, IsOk());
ASSERT_EQ(result.value().size(), 1U);
EXPECT_FALSE(result.value()[0]->data_file()->data_sequence_number.has_value());
}

TEST(FileScanTasksFromJsonTest, RowLineageSequence) {
auto json = R"([{
"data-file": {
"content": "data",
Expand All @@ -2297,9 +2315,9 @@ TEST(FileScanTasksFromJsonTest, RowLineageSequence) {
"partition": [],
"file-size-in-bytes": 12345,
"record-count": 100,
"first-row-id": 100,
"data-sequence-number": 7
}
"first-row-id": 100
},
"data-sequence-number": 7
}])"_json;

auto result = FileScanTasksFromJson(json, {}, UnpartitionedSpecs(), Schema({}, 0));
Expand All @@ -2309,6 +2327,13 @@ TEST(FileScanTasksFromJsonTest, RowLineageSequence) {
ASSERT_NE(data_file, nullptr);
EXPECT_EQ(data_file->first_row_id, 100);
EXPECT_EQ(data_file->data_sequence_number, 7);

FetchScanTasksResponse response;
response.file_scan_tasks = std::move(result.value());
ICEBERG_UNWRAP_OR_FAIL(auto roundtrip_json,
ToJson(response, UnpartitionedSpecs(), Schema({}, 0)));
ASSERT_EQ(roundtrip_json["file-scan-tasks"].size(), 1);
EXPECT_EQ(roundtrip_json["file-scan-tasks"][0]["data-sequence-number"], 7);
}

TEST(FileScanTasksFromJsonTest, TaskWithDeleteFileReferences) {
Expand Down