Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
12 changes: 2 additions & 10 deletions src/iceberg/catalog/rest/resource_paths.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,8 @@ Result<std::unique_ptr<ResourcePaths>> ResourcePaths::Make(std::string base_uri,
ResourcePaths::ResourcePaths(std::string base_uri, const std::string& prefix)
: base_uri_(std::move(base_uri)), prefix_(prefix.empty() ? "" : (prefix + "/")) {}

Status ResourcePaths::SetBaseUri(const std::string& base_uri) {
if (base_uri.empty()) {
return InvalidArgument("Base URI is empty");
}
base_uri_ = base_uri;
return {};
}

Result<std::string> ResourcePaths::Config() const {
return std::format("{}/v1/config", base_uri_);
Result<std::string> ResourcePaths::Config(const std::string& base_uri) {
return std::format("{}/v1/config", base_uri);
}

Result<std::string> ResourcePaths::OAuth2Tokens() const {
Expand Down
6 changes: 1 addition & 5 deletions src/iceberg/catalog/rest/resource_paths.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include <string>

#include "iceberg/catalog/rest/iceberg_rest_export.h"
#include "iceberg/catalog/rest/type_fwd.h"
#include "iceberg/result.h"
#include "iceberg/type_fwd.h"

Expand All @@ -44,11 +43,8 @@ class ICEBERG_REST_EXPORT ResourcePaths {
static Result<std::unique_ptr<ResourcePaths>> Make(std::string base_uri,
const std::string& prefix);

/// \brief Set the base URI of the REST catalog server.
Status SetBaseUri(const std::string& base_uri);

/// \brief Get the /v1/config endpoint path.
Result<std::string> Config() const;
static Result<std::string> Config(const std::string& base_uri);

@wgtmac wgtmac Jan 5, 2026

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.

It sounds good to remove SetBaseUri. However, it leads to confusion to make this a static function. I'd suggest to revert this function as you have created a new ResourcePaths based on the server config.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It sounds good to remove SetBaseUri. However, it leads to confusion to make this a static function. I'd suggest to revert this function as you have created a new ResourcePaths based on the server config.

it's reasonable, i've reverted.


/// \brief Get the /v1/{prefix}/oauth/tokens endpoint path.
Result<std::string> OAuth2Tokens() const;
Expand Down
14 changes: 7 additions & 7 deletions src/iceberg/catalog/rest/rest_catalog.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ std::unordered_set<Endpoint> GetDefaultEndpoints() {
}

/// \brief Fetch server config and merge it with client config
Result<CatalogConfig> FetchServerConfig(const ResourcePaths& paths,
Result<CatalogConfig> FetchServerConfig(const std::string& config_path,
const RestCatalogProperties& current_config) {
ICEBERG_ASSIGN_OR_RAISE(auto config_path, paths.Config());
HttpClient client(current_config.ExtractHeaders());
ICEBERG_ASSIGN_OR_RAISE(const auto response,
client.Get(config_path, /*params=*/{}, /*headers=*/{},
Expand Down Expand Up @@ -111,10 +110,9 @@ Result<std::shared_ptr<RestCatalog>> RestCatalog::Make(
if (!file_io) {
return InvalidArgument("FileIO is required to create RestCatalog");
}
ICEBERG_ASSIGN_OR_RAISE(
auto paths, ResourcePaths::Make(std::string(TrimTrailingSlash(uri)),
config.Get(RestCatalogProperties::kPrefix)));
ICEBERG_ASSIGN_OR_RAISE(auto server_config, FetchServerConfig(*paths, config));
ICEBERG_ASSIGN_OR_RAISE(auto config_uri,
ResourcePaths::Config(std::string(TrimTrailingSlash(uri))));
ICEBERG_ASSIGN_OR_RAISE(auto server_config, FetchServerConfig(config_uri, config));

std::unique_ptr<RestCatalogProperties> final_config = RestCatalogProperties::FromMap(
MergeConfigs(server_config.defaults, config.configs(), server_config.overrides));

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.

Thanks for fixing this! Let's not complicate the PR. I think this change can be added without the test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks for fixing this! Let's not complicate the PR. I think this change can be added without the test.

Yes, i create a new pull request for it.https://github.com/apache/iceberg-cpp/pull/483/files

Expand All @@ -132,7 +130,9 @@ Result<std::shared_ptr<RestCatalog>> RestCatalog::Make(

// Update resource paths based on the final config
ICEBERG_ASSIGN_OR_RAISE(auto final_uri, final_config->Uri());
ICEBERG_RETURN_UNEXPECTED(paths->SetBaseUri(std::string(TrimTrailingSlash(final_uri))));
ICEBERG_ASSIGN_OR_RAISE(
Comment thread
wgtmac marked this conversation as resolved.
auto paths, ResourcePaths::Make(std::string(TrimTrailingSlash(final_uri)),
final_config->Get(RestCatalogProperties::kPrefix)));

return std::shared_ptr<RestCatalog>(
new RestCatalog(std::move(final_config), std::move(file_io), std::move(paths),
Expand Down
Loading