4040#include " iceberg/partition_spec.h"
4141#include " iceberg/result.h"
4242#include " iceberg/schema.h"
43+ #include " iceberg/sort_order.h"
4344#include " iceberg/table.h"
4445#include " iceberg/util/macros.h"
4546
@@ -77,8 +78,8 @@ Result<CatalogConfig> FetchServerConfig(const ResourcePaths& paths,
7778
7879RestCatalog::~RestCatalog () = default ;
7980
80- Result<std::unique_ptr <RestCatalog>> RestCatalog::Make (
81- const RestCatalogProperties& config) {
81+ Result<std::shared_ptr <RestCatalog>> RestCatalog::Make (
82+ const RestCatalogProperties& config, std::shared_ptr<FileIO> file_io ) {
8283 ICEBERG_ASSIGN_OR_RAISE (auto uri, config.Uri ());
8384 ICEBERG_ASSIGN_OR_RAISE (
8485 auto paths, ResourcePaths::Make (std::string (TrimTrailingSlash (uri)),
@@ -103,14 +104,17 @@ Result<std::unique_ptr<RestCatalog>> RestCatalog::Make(
103104 ICEBERG_ASSIGN_OR_RAISE (auto final_uri, final_config->Uri ());
104105 ICEBERG_RETURN_UNEXPECTED (paths->SetBaseUri (std::string (TrimTrailingSlash (final_uri))));
105106
106- return std::unique_ptr<RestCatalog>(
107- new RestCatalog (std::move (final_config), std::move (paths), std::move (endpoints)));
107+ return std::shared_ptr<RestCatalog>(
108+ new RestCatalog (std::move (final_config), std::move (file_io), std::move (paths),
109+ std::move (endpoints)));
108110}
109111
110112RestCatalog::RestCatalog (std::unique_ptr<RestCatalogProperties> config,
113+ std::shared_ptr<FileIO> file_io,
111114 std::unique_ptr<ResourcePaths> paths,
112115 std::unordered_set<Endpoint> endpoints)
113116 : config_(std::move(config)),
117+ file_io_ (std::move(file_io)),
114118 client_(std::make_unique<HttpClient>(config_->ExtractHeaders ())),
115119 paths_(std::move(paths)),
116120 name_(config_->Get (RestCatalogProperties::kName )),
@@ -241,11 +245,33 @@ Result<std::vector<TableIdentifier>> RestCatalog::ListTables(
241245}
242246
243247Result<std::shared_ptr<Table>> RestCatalog::CreateTable (
244- [[maybe_unused]] const TableIdentifier& identifier,
245- [[maybe_unused]] const Schema& schema, [[maybe_unused]] const PartitionSpec& spec,
246- [[maybe_unused]] const std::string& location,
247- [[maybe_unused]] const std::unordered_map<std::string, std::string>& properties) {
248- return NotImplemented (" Not implemented" );
248+ const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
249+ const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
250+ const std::string& location,
251+ const std::unordered_map<std::string, std::string>& properties) {
252+ ICEBERG_RETURN_UNEXPECTED (CheckEndpoint (supported_endpoints_, Endpoint::CreateTable ()));
253+ ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Tables (identifier.ns ));
254+
255+ CreateTableRequest request{
256+ .name = identifier.name ,
257+ .location = location,
258+ .schema = schema,
259+ .partition_spec = spec,
260+ .write_order = order,
261+ .stage_create = false ,
262+ .properties = properties,
263+ };
264+
265+ ICEBERG_ASSIGN_OR_RAISE (auto json_request, ToJsonString (ToJson (request)));
266+ ICEBERG_ASSIGN_OR_RAISE (
267+ const auto response,
268+ client_->Post (path, json_request, /* headers=*/ {}, *TableErrorHandler::Instance ()));
269+
270+ ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (response.body ()));
271+ ICEBERG_ASSIGN_OR_RAISE (auto load_result, LoadTableResultFromJson (json));
272+ return Table::Make (identifier, load_result.metadata ,
273+ std::move (load_result.metadata_location ), file_io_,
274+ shared_from_this ());
249275}
250276
251277Result<std::shared_ptr<Table>> RestCatalog::UpdateTable (
@@ -257,7 +283,9 @@ Result<std::shared_ptr<Table>> RestCatalog::UpdateTable(
257283
258284Result<std::shared_ptr<Transaction>> RestCatalog::StageCreateTable (
259285 [[maybe_unused]] const TableIdentifier& identifier,
260- [[maybe_unused]] const Schema& schema, [[maybe_unused]] const PartitionSpec& spec,
286+ [[maybe_unused]] const std::shared_ptr<Schema>& schema,
287+ [[maybe_unused]] const std::shared_ptr<PartitionSpec>& spec,
288+ [[maybe_unused]] const std::shared_ptr<SortOrder>& order,
261289 [[maybe_unused]] const std::string& location,
262290 [[maybe_unused]] const std::unordered_map<std::string, std::string>& properties) {
263291 return NotImplemented (" Not implemented" );
0 commit comments