4444#include " iceberg/table.h"
4545#include " iceberg/table_requirement.h"
4646#include " iceberg/table_update.h"
47+ #include " iceberg/transaction.h"
4748#include " iceberg/util/macros.h"
4849
4950namespace iceberg ::rest {
@@ -274,11 +275,11 @@ Result<std::vector<TableIdentifier>> RestCatalog::ListTables(const Namespace& ns
274275 return result;
275276}
276277
277- Result<std::shared_ptr<Table>> RestCatalog::CreateTable (
278+ Result<LoadTableResult> RestCatalog::CreateTableInternal (
278279 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
279280 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
280281 const std::string& location,
281- const std::unordered_map<std::string, std::string>& properties) {
282+ const std::unordered_map<std::string, std::string>& properties, bool stage_create ) {
282283 ICEBERG_ENDPOINT_CHECK (supported_endpoints_, Endpoint::CreateTable ());
283284 ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Tables (identifier.ns ));
284285
@@ -288,7 +289,7 @@ Result<std::shared_ptr<Table>> RestCatalog::CreateTable(
288289 .schema = schema,
289290 .partition_spec = spec,
290291 .write_order = order,
291- .stage_create = false ,
292+ .stage_create = stage_create ,
292293 .properties = properties,
293294 };
294295
@@ -298,10 +299,19 @@ Result<std::shared_ptr<Table>> RestCatalog::CreateTable(
298299 client_->Post (path, json_request, /* headers=*/ {}, *TableErrorHandler::Instance ()));
299300
300301 ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (response.body ()));
301- ICEBERG_ASSIGN_OR_RAISE (auto load_result, LoadTableResultFromJson (json));
302- return Table::Make (identifier, load_result.metadata ,
303- std::move (load_result.metadata_location ), file_io_,
304- shared_from_this ());
302+ return LoadTableResultFromJson (json);
303+ }
304+
305+ Result<std::shared_ptr<Table>> RestCatalog::CreateTable (
306+ const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
307+ const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
308+ const std::string& location,
309+ const std::unordered_map<std::string, std::string>& properties) {
310+ ICEBERG_ASSIGN_OR_RAISE (auto result,
311+ CreateTableInternal (identifier, schema, spec, order, location,
312+ properties, /* stage_create=*/ false ));
313+ return Table::Make (identifier, std::move (result.metadata ),
314+ std::move (result.metadata_location ), file_io_, shared_from_this ());
305315}
306316
307317Result<std::shared_ptr<Table>> RestCatalog::UpdateTable (
@@ -335,13 +345,19 @@ Result<std::shared_ptr<Table>> RestCatalog::UpdateTable(
335345}
336346
337347Result<std::shared_ptr<Transaction>> RestCatalog::StageCreateTable (
338- [[maybe_unused]] const TableIdentifier& identifier,
339- [[maybe_unused]] const std::shared_ptr<Schema>& schema,
340- [[maybe_unused]] const std::shared_ptr<PartitionSpec>& spec,
341- [[maybe_unused]] const std::shared_ptr<SortOrder>& order,
342- [[maybe_unused]] const std::string& location,
343- [[maybe_unused]] const std::unordered_map<std::string, std::string>& properties) {
344- return NotImplemented (" Not implemented" );
348+ const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
349+ const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
350+ const std::string& location,
351+ const std::unordered_map<std::string, std::string>& properties) {
352+ ICEBERG_ASSIGN_OR_RAISE (auto result,
353+ CreateTableInternal (identifier, schema, spec, order, location,
354+ properties, /* stage_create=*/ true ));
355+ ICEBERG_ASSIGN_OR_RAISE (auto staged_table,
356+ StagedTable::Make (identifier, std::move (result.metadata ),
357+ std::move (result.metadata_location ), file_io_,
358+ shared_from_this ()));
359+ return Transaction::Make (std::move (staged_table), Transaction::Kind::kCreate ,
360+ /* auto_commit=*/ false );
345361}
346362
347363Status RestCatalog::DropTable (const TableIdentifier& identifier, bool purge) {
@@ -393,9 +409,6 @@ Result<std::string> RestCatalog::LoadTableInternal(
393409}
394410
395411Result<std::shared_ptr<Table>> RestCatalog::LoadTable (const TableIdentifier& identifier) {
396- ICEBERG_ENDPOINT_CHECK (supported_endpoints_, Endpoint::LoadTable ());
397- ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Table (identifier));
398-
399412 ICEBERG_ASSIGN_OR_RAISE (const auto body, LoadTableInternal (identifier));
400413 ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (body));
401414 ICEBERG_ASSIGN_OR_RAISE (auto load_result, LoadTableResultFromJson (json));
0 commit comments