Skip to content

Commit

Permalink
make string params const ref
Browse files Browse the repository at this point in the history
  • Loading branch information
samansmink committed Nov 29, 2023
1 parent db09227 commit 553a0a7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
16 changes: 8 additions & 8 deletions src/common/iceberg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ IcebergTable IcebergTable::Load(const string &iceberg_path, IcebergSnapshot &sna
return ret;
}

vector<IcebergManifest> IcebergTable::ReadManifestListFile(string path, FileSystem &fs, idx_t iceberg_format_version) {
vector<IcebergManifest> IcebergTable::ReadManifestListFile(const string &path, FileSystem &fs, idx_t iceberg_format_version) {
vector<IcebergManifest> ret;

// TODO: make streaming
Expand Down Expand Up @@ -63,7 +63,7 @@ vector<IcebergManifest> IcebergTable::ReadManifestListFile(string path, FileSyst
return ret;
}

vector<IcebergManifestEntry> IcebergTable::ReadManifestEntries(string path, FileSystem &fs,
vector<IcebergManifestEntry> IcebergTable::ReadManifestEntries(const string &path, FileSystem &fs,
idx_t iceberg_format_version) {
vector<IcebergManifestEntry> ret;

Expand Down Expand Up @@ -118,7 +118,7 @@ unique_ptr<SnapshotParseInfo> IcebergSnapshot::GetParseInfo(yyjson_doc *metadata
return make_uniq<SnapshotParseInfo>(std::move(info));
}

unique_ptr<SnapshotParseInfo> IcebergSnapshot::GetParseInfo(string &path, FileSystem &fs) {
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);
Expand All @@ -130,7 +130,7 @@ unique_ptr<SnapshotParseInfo> IcebergSnapshot::GetParseInfo(string &path, FileSy
return std::move(parse_info);
}

IcebergSnapshot IcebergSnapshot::GetLatestSnapshot(string &path, FileSystem &fs) {
IcebergSnapshot IcebergSnapshot::GetLatestSnapshot(const string &path, FileSystem &fs) {
auto info = GetParseInfo(path, fs);
auto latest_snapshot = FindLatestSnapshotInternal(info->snapshots);

Expand All @@ -141,7 +141,7 @@ IcebergSnapshot IcebergSnapshot::GetLatestSnapshot(string &path, FileSystem &fs)
return ParseSnapShot(latest_snapshot, info->iceberg_version, info->schema_id, info->schemas);
}

IcebergSnapshot IcebergSnapshot::GetSnapshotById(string &path, FileSystem &fs, idx_t snapshot_id) {
IcebergSnapshot IcebergSnapshot::GetSnapshotById(const string &path, FileSystem &fs, idx_t snapshot_id) {
auto info = GetParseInfo(path, fs);
auto snapshot = FindSnapshotByIdInternal(info->snapshots, snapshot_id);

Expand All @@ -152,7 +152,7 @@ IcebergSnapshot IcebergSnapshot::GetSnapshotById(string &path, FileSystem &fs, i
return ParseSnapShot(snapshot, info->iceberg_version, info->schema_id, info->schemas);
}

IcebergSnapshot IcebergSnapshot::GetSnapshotByTimestamp(string &path, FileSystem &fs, timestamp_t timestamp) {
IcebergSnapshot IcebergSnapshot::GetSnapshotByTimestamp(const string &path, FileSystem &fs, timestamp_t timestamp) {
auto info = GetParseInfo(path, fs);
auto snapshot = FindSnapshotByIdTimestampInternal(info->snapshots, timestamp);

Expand All @@ -163,7 +163,7 @@ IcebergSnapshot IcebergSnapshot::GetSnapshotByTimestamp(string &path, FileSystem
return ParseSnapShot(snapshot, info->iceberg_version, info->schema_id, info->schemas);
}

string IcebergSnapshot::ReadMetaData(string &path, FileSystem &fs) {
string IcebergSnapshot::ReadMetaData(const string &path, FileSystem &fs) {
string metadata_file_path;

if (StringUtil::EndsWith(path, ".json")) {
Expand Down Expand Up @@ -201,7 +201,7 @@ IcebergSnapshot IcebergSnapshot::ParseSnapShot(yyjson_val *snapshot, idx_t icebe
return ret;
}

string IcebergSnapshot::GetTableVersion(string &path, FileSystem &fs) {
string IcebergSnapshot::GetTableVersion(const string &path, FileSystem &fs) {
auto meta_path = fs.JoinPath(path, "metadata");
auto version_file_path = fs.JoinPath(meta_path, "version-hint.text");
auto version_file_content = IcebergUtils::FileToString(version_file_path, fs);
Expand Down
6 changes: 3 additions & 3 deletions src/common/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ string IcebergUtils::GetFullPath(const string &iceberg_path, const string &relat
throw IOException("Did not recognize iceberg path");
}

uint64_t IcebergUtils::TryGetNumFromObject(yyjson_val *obj, string field) {
uint64_t IcebergUtils::TryGetNumFromObject(yyjson_val *obj, const string &field) {
auto val = yyjson_obj_getn(obj, field.c_str(), field.size());
if (!val || yyjson_get_tag(val) != YYJSON_TYPE_NUM) {
throw IOException("Invalid field found while parsing field: " + field);
}
return yyjson_get_uint(val);
}

bool IcebergUtils::TryGetBoolFromObject(yyjson_val *obj, string field) {
bool IcebergUtils::TryGetBoolFromObject(yyjson_val *obj, const string &field) {
auto val = yyjson_obj_getn(obj, field.c_str(), field.size());
if (!val || yyjson_get_tag(val) != YYJSON_TYPE_BOOL) {
throw IOException("Invalid field found while parsing field: " + field);
}
return yyjson_get_bool(val);
}

string IcebergUtils::TryGetStrFromObject(yyjson_val *obj, string field) {
string IcebergUtils::TryGetStrFromObject(yyjson_val *obj, const string &field) {
auto val = yyjson_obj_getn(obj, field.c_str(), field.size());
if (!val || yyjson_get_tag(val) != YYJSON_TYPE_STR) {
throw IOException("Invalid field found while parsing field: " + field);
Expand Down
18 changes: 9 additions & 9 deletions src/include/iceberg_metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,25 +58,25 @@ class IcebergSnapshot {
uint64_t schema_id;
vector<IcebergColumnDefinition> schema;

static IcebergSnapshot GetLatestSnapshot(string &path, FileSystem &fs);
static IcebergSnapshot GetSnapshotById(string &path, FileSystem &fs, idx_t snapshot_id);
static IcebergSnapshot GetSnapshotByTimestamp(string &path, FileSystem &fs, timestamp_t timestamp);
static IcebergSnapshot GetLatestSnapshot(const string &path, FileSystem &fs);
static IcebergSnapshot GetSnapshotById(const string &path, FileSystem &fs, idx_t snapshot_id);
static IcebergSnapshot GetSnapshotByTimestamp(const string &path, FileSystem &fs, timestamp_t timestamp);

static IcebergSnapshot ParseSnapShot(yyjson_val *snapshot, idx_t iceberg_format_version, idx_t schema_id,
vector<yyjson_val *> &schemas);
static string ReadMetaData(string &path, FileSystem &fs);
static yyjson_val *GetSnapshots(string &path, FileSystem &fs);
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);

protected:
//! Internal JSON parsing functions
static string GetTableVersion(string &path, FileSystem &fs);
static string GetTableVersion(const string &path, FileSystem &fs);
static yyjson_val *FindLatestSnapshotInternal(yyjson_val *snapshots);
static yyjson_val *FindSnapshotByIdInternal(yyjson_val *snapshots, idx_t target_id);
static yyjson_val *FindSnapshotByIdTimestampInternal(yyjson_val *snapshots, timestamp_t timestamp);
static vector<IcebergColumnDefinition> ParseSchema(vector<yyjson_val *> &schemas, idx_t schema_id);
static unique_ptr<SnapshotParseInfo> GetParseInfo(string &path, FileSystem &fs);
static unique_ptr<SnapshotParseInfo> GetParseInfo(const string &path, FileSystem &fs);
};

//! Represents the iceberg table at a specific IcebergSnapshot. Corresponds to a single Manifest List.
Expand Down Expand Up @@ -117,8 +117,8 @@ struct IcebergTable {
vector<IcebergTableEntry> entries;

protected:
static vector<IcebergManifest> ReadManifestListFile(string path, FileSystem &fs, idx_t iceberg_format_version);
static vector<IcebergManifestEntry> ReadManifestEntries(string path, FileSystem &fs, idx_t iceberg_format_version);
static vector<IcebergManifest> ReadManifestListFile(const string &path, FileSystem &fs, idx_t iceberg_format_version);
static vector<IcebergManifestEntry> ReadManifestEntries(const string &path, FileSystem &fs, idx_t iceberg_format_version);
string path;
};

Expand Down
6 changes: 3 additions & 3 deletions src/include/iceberg_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class IcebergUtils {
static string GetFullPath(const string &iceberg_path, const string &relative_file_path, FileSystem &fs);

//! YYJSON utility functions
static uint64_t TryGetNumFromObject(yyjson_val *obj, string field);
static string TryGetStrFromObject(yyjson_val *obj, string field);
static bool TryGetBoolFromObject(yyjson_val *obj, string field);
static uint64_t TryGetNumFromObject(yyjson_val *obj, const string &field);
static string TryGetStrFromObject(yyjson_val *obj, const string &field);
static bool TryGetBoolFromObject(yyjson_val *obj, const string &field);
};

} // namespace duckdb

0 comments on commit 553a0a7

Please sign in to comment.