Skip to content

Commit

Permalink
pass by ref to make ownership stay at caller
Browse files Browse the repository at this point in the history
  • Loading branch information
samansmink committed Nov 29, 2023
1 parent 553a0a7 commit 6d4dbe8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/common/iceberg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ vector<IcebergManifestEntry> IcebergTable::ReadManifestEntries(const string &pat
return ret;
}

unique_ptr<SnapshotParseInfo> IcebergSnapshot::GetParseInfo(yyjson_doc *metadata_json) {
unique_ptr<SnapshotParseInfo> IcebergSnapshot::GetParseInfo(yyjson_doc &metadata_json) {
SnapshotParseInfo info {};
auto root = yyjson_doc_get_root(metadata_json);
auto root = yyjson_doc_get_root(&metadata_json);
info.iceberg_version = IcebergUtils::TryGetNumFromObject(root, "format-version");
info.snapshots = yyjson_obj_get(root, "snapshots");

Expand Down Expand Up @@ -121,7 +121,7 @@ unique_ptr<SnapshotParseInfo> IcebergSnapshot::GetParseInfo(yyjson_doc *metadata
unique_ptr<SnapshotParseInfo> IcebergSnapshot::GetParseInfo(const string &path, FileSystem &fs) {
auto metadata_json = ReadMetaData(path, fs);
auto doc = yyjson_read(metadata_json.c_str(), metadata_json.size(), 0);
auto parse_info = GetParseInfo(doc);
auto parse_info = GetParseInfo(*doc);

// Transfer string and yyjson doc ownership
parse_info->doc = doc;
Expand Down
2 changes: 1 addition & 1 deletion src/iceberg_functions/iceberg_snapshots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ static void IcebergSnapshotsFunction(ClientContext &context, TableFunctionInput
break;
}

auto parse_info = IcebergSnapshot::GetParseInfo(global_state.metadata_doc);
auto parse_info = IcebergSnapshot::GetParseInfo(*global_state.metadata_doc);
auto snapshot = IcebergSnapshot::ParseSnapShot(next_snapshot, global_state.iceberg_format_version,
parse_info->schema_id, parse_info->schemas);

Expand Down
3 changes: 1 addition & 2 deletions src/include/iceberg_metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ class IcebergSnapshot {
vector<yyjson_val *> &schemas);
static string ReadMetaData(const string &path, FileSystem &fs);
static yyjson_val *GetSnapshots(const string &path, FileSystem &fs);
//! Note: caller keeps ownership of yyjson doc
static unique_ptr<SnapshotParseInfo> GetParseInfo(yyjson_doc *metadata_json);
static unique_ptr<SnapshotParseInfo> GetParseInfo(yyjson_doc &metadata_json);

protected:
//! Internal JSON parsing functions
Expand Down

0 comments on commit 6d4dbe8

Please sign in to comment.