Skip to content

Conversation

@HeartLinked
Copy link
Contributor

No description provided.

/// initialized directly via aggregate initialization. It provides helper methods to
/// construct specific endpoint URLs and HTTP headers from the configuration properties.
struct ICEBERG_REST_EXPORT RestCatalogConfig {
/// \brief Returns the endpoint string for listing all catalog configuration settings.
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider adding timeout and retry configurations to the REST catalog to handle transient network or service issues

Copy link
Member

Choose a reason for hiding this comment

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

Yes that's a good point. I think Iceberg spec (at least the Java impl) has defined some properties to address this as my comment above.

return r;
}
constexpr std::string_view kMimeTypeApplicationJson = "application/json";
constexpr std::string_view kClientVersion = "0.14.1";
Copy link
Member

Choose a reason for hiding this comment

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

What is this?

/// any custom headers prefixed with "header." in the properties.
/// \return A Result containing cpr::Header object, or an error if names/values are
/// invalid.
Result<cpr::Header> GetExtraHeaders() const;
Copy link
Member

Choose a reason for hiding this comment

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

We cannot expose cpr symbols in the public api.

Result<cpr::Header> RestCatalogConfig::GetExtraHeaders() const {
cpr::Header headers;

headers[std::string(kHeaderContentType)] = std::string(kMimeTypeApplicationJson);
Copy link
Member

Choose a reason for hiding this comment

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

If the major usage of these magics are as string types, we should better define them as strings.

}

std::string RestCatalogConfig::GetNamespacesEndpoint() const {
return std::format("{}/{}/namespaces", TrimTrailingSlash(uri), kPathV1);
Copy link
Member

Choose a reason for hiding this comment

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

This is not correct. prefix should be considered though in most cases it is an empty string.

Copy link
Member

Choose a reason for hiding this comment

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

For example, the Java code is as below:

public String namespaces() {
    return SLASH.join("v1", prefix, "namespaces");
  }

while (true) {
cpr::Parameters params;
if (!ns.levels.empty()) {
params.Add({"parent", EncodeNamespaceForUrl(ns)});
Copy link
Member

Choose a reason for hiding this comment

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

Define these magic strings as constants.

///
/// This class wraps the CPR library and provides a type-safe interface for making
/// HTTP requests. It handles authentication, headers, and response parsing.
class ICEBERG_REST_EXPORT HttpClient {
Copy link
Member

Choose a reason for hiding this comment

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

I think the major issue of this design is that HttpClient is not a real wrapper of the cpr client. We should design a library-independent interface of http client and should be super easy to replace the cpr library with any other network library without changing a single line in the RestCatalog class.

/// via EncodeUriComponent. Returns an empty string if there are no levels.
/// \param ns The namespace (sequence of path-like levels) to encode.
/// \return The percent-encoded namespace string suitable for URLs.
inline std::string EncodeNamespaceForUrl(const Namespace& ns) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add some unit tests about this method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants