|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +// namespace iceberg::rest { |
| 21 | + |
| 22 | +// class ICEBERG_REST_EXPORT RestCatalogConfig { |
| 23 | +// public: |
| 24 | +// std::string uri; |
| 25 | +// std::optional<std::string> warehouse; |
| 26 | +// std::map<std::string, std::string> props; |
| 27 | + |
| 28 | +// // Endpoint builder methods |
| 29 | +// std::string config_endpoint() const; |
| 30 | +// std::string namespaces_endpoint() const; |
| 31 | +// std::string namespace_endpoint(const Namespace& ns) const; |
| 32 | +// std::string tables_endpoint(const Namespace& ns) const; |
| 33 | +// std::string table_endpoint(const TableIdentifier& table) const; |
| 34 | +// std::string rename_table_endpoint() const; |
| 35 | +// }; |
| 36 | + |
| 37 | +// } // namespace iceberg::rest |
| 38 | + |
| 39 | +#pragma once |
| 40 | + |
| 41 | +#include <format> |
| 42 | +#include <map> |
| 43 | +#include <optional> |
| 44 | +#include <string> |
| 45 | + |
| 46 | +#include "constant.h" |
| 47 | +#include "iceberg/catalog/rest/iceberg_rest_export.h" |
| 48 | +#include "iceberg/table_identifier.h" |
| 49 | +#include "iceberg/util/config.h" |
| 50 | +#include "util.h" |
| 51 | + |
| 52 | +/// \file iceberg/catalog/rest/config.h |
| 53 | +/// RestCatalogConfig implementation for Iceberg REST API. |
| 54 | + |
| 55 | +namespace iceberg::rest { |
| 56 | + |
| 57 | +class ICEBERG_REST_EXPORT RestCatalogConfig : public ConfigBase<RestCatalogConfig> { |
| 58 | + public: |
| 59 | + const std::string& GetUri() const { return uri_; } |
| 60 | + |
| 61 | + const std::optional<std::string>& GetWarehouse() const { return warehouse_; } |
| 62 | + |
| 63 | + RestCatalogConfig& SetUri(std::string uri) { |
| 64 | + uri_ = std::move(uri); |
| 65 | + return *this; |
| 66 | + } |
| 67 | + |
| 68 | + RestCatalogConfig& SetWarehouse(std::string warehouse) { |
| 69 | + warehouse_ = std::move(warehouse); |
| 70 | + return *this; |
| 71 | + } |
| 72 | + |
| 73 | + std::string GetConfigEndpoint() const { |
| 74 | + return std::format("{}/{}/config", TrimTrailingSlash(uri_), kPathV1); |
| 75 | + } |
| 76 | + |
| 77 | + /// \brief Get the namespaces endpoint |
| 78 | + std::string GetNamespacesEndpoint() const { |
| 79 | + return std::format("{}/{}/namespaces", TrimTrailingSlash(uri_), kPathV1); |
| 80 | + } |
| 81 | + |
| 82 | + /// \brief Get the namespace endpoint |
| 83 | + std::string GetNamespaceEndpoint(const Namespace& ns) const { |
| 84 | + return std::format("{}/{}/namespaces/{}", TrimTrailingSlash(uri_), kPathV1, |
| 85 | + EncodeNamespaceForUrl(ns)); |
| 86 | + } |
| 87 | + |
| 88 | + /// \brief Get the tables endpoint |
| 89 | + std::string GetTablesEndpoint(const Namespace& ns) const { |
| 90 | + return std::format("{}/{}/namespaces/{}/tables", TrimTrailingSlash(uri_), kPathV1, |
| 91 | + EncodeNamespaceForUrl(ns)); |
| 92 | + } |
| 93 | + |
| 94 | + /// \brief Get the rename table endpoint |
| 95 | + std::string GetRenameTableEndpoint() const { |
| 96 | + return std::format("{}/{}/tables/rename", TrimTrailingSlash(uri_), kPathV1); |
| 97 | + } |
| 98 | + |
| 99 | + /// \brief Get the table endpoint |
| 100 | + std::string GetTableEndpoint(const TableIdentifier& table) const { |
| 101 | + return std::format("{}/{}/namespaces/{}/tables/{}", TrimTrailingSlash(uri_), kPathV1, |
| 102 | + EncodeNamespaceForUrl(table.ns), table.name); |
| 103 | + } |
| 104 | + |
| 105 | + private: |
| 106 | + std::string uri_; |
| 107 | + std::optional<std::string> warehouse_; |
| 108 | +}; |
| 109 | + |
| 110 | +} // namespace iceberg::rest |
0 commit comments