4242#include " iceberg/schema.h"
4343#include " iceberg/sort_order.h"
4444#include " iceberg/table.h"
45+ #include " iceberg/transaction.h"
4546#include " iceberg/util/macros.h"
4647
4748namespace iceberg ::rest {
@@ -249,11 +250,11 @@ Result<std::vector<TableIdentifier>> RestCatalog::ListTables(
249250 return NotImplemented (" Not implemented" );
250251}
251252
252- Result<std::shared_ptr<Table>> RestCatalog::CreateTable (
253+ Result<LoadTableResult> RestCatalog::CreateTableInternal (
253254 const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
254255 const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
255256 const std::string& location,
256- const std::unordered_map<std::string, std::string>& properties) {
257+ const std::unordered_map<std::string, std::string>& properties, bool stage_create ) {
257258 ICEBERG_ENDPOINT_CHECK (supported_endpoints_, Endpoint::CreateTable ());
258259 ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Tables (identifier.ns ));
259260
@@ -263,7 +264,7 @@ Result<std::shared_ptr<Table>> RestCatalog::CreateTable(
263264 .schema = schema,
264265 .partition_spec = spec,
265266 .write_order = order,
266- .stage_create = false ,
267+ .stage_create = stage_create ,
267268 .properties = properties,
268269 };
269270
@@ -273,10 +274,19 @@ Result<std::shared_ptr<Table>> RestCatalog::CreateTable(
273274 client_->Post (path, json_request, /* headers=*/ {}, *TableErrorHandler::Instance ()));
274275
275276 ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (response.body ()));
276- ICEBERG_ASSIGN_OR_RAISE (auto load_result, LoadTableResultFromJson (json));
277- return Table::Make (identifier, load_result.metadata ,
278- std::move (load_result.metadata_location ), file_io_,
279- shared_from_this ());
277+ return LoadTableResultFromJson (json);
278+ }
279+
280+ Result<std::shared_ptr<Table>> RestCatalog::CreateTable (
281+ const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
282+ const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
283+ const std::string& location,
284+ const std::unordered_map<std::string, std::string>& properties) {
285+ ICEBERG_ASSIGN_OR_RAISE (
286+ auto result,
287+ CreateTableInternal (identifier, schema, spec, order, location, properties, false ));
288+ return Table::Make (identifier, result.metadata , std::move (result.metadata_location ),
289+ file_io_, shared_from_this ());
280290}
281291
282292Result<std::shared_ptr<Table>> RestCatalog::UpdateTable (
@@ -287,13 +297,19 @@ Result<std::shared_ptr<Table>> RestCatalog::UpdateTable(
287297}
288298
289299Result<std::shared_ptr<Transaction>> RestCatalog::StageCreateTable (
290- [[maybe_unused]] const TableIdentifier& identifier,
291- [[maybe_unused]] const std::shared_ptr<Schema>& schema,
292- [[maybe_unused]] const std::shared_ptr<PartitionSpec>& spec,
293- [[maybe_unused]] const std::shared_ptr<SortOrder>& order,
294- [[maybe_unused]] const std::string& location,
295- [[maybe_unused]] const std::unordered_map<std::string, std::string>& properties) {
296- return NotImplemented (" Not implemented" );
300+ const TableIdentifier& identifier, const std::shared_ptr<Schema>& schema,
301+ const std::shared_ptr<PartitionSpec>& spec, const std::shared_ptr<SortOrder>& order,
302+ const std::string& location,
303+ const std::unordered_map<std::string, std::string>& properties) {
304+ ICEBERG_ASSIGN_OR_RAISE (
305+ auto result,
306+ CreateTableInternal (identifier, schema, spec, order, location, properties, true ));
307+ ICEBERG_ASSIGN_OR_RAISE (
308+ auto staged_table,
309+ StagedTable::Make (identifier, result.metadata , std::move (result.metadata_location ),
310+ file_io_, shared_from_this ()));
311+ return Transaction::Make (staged_table, Transaction::Kind::kCreate ,
312+ /* auto_commit=*/ false );
297313}
298314
299315Status RestCatalog::DropTable (const TableIdentifier& identifier, bool purge) {
@@ -337,9 +353,6 @@ Result<std::string> RestCatalog::LoadTableInternal(
337353}
338354
339355Result<std::shared_ptr<Table>> RestCatalog::LoadTable (const TableIdentifier& identifier) {
340- ICEBERG_ENDPOINT_CHECK (supported_endpoints_, Endpoint::LoadTable ());
341- ICEBERG_ASSIGN_OR_RAISE (auto path, paths_->Table (identifier));
342-
343356 ICEBERG_ASSIGN_OR_RAISE (const auto body, LoadTableInternal (identifier));
344357 ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (body));
345358 ICEBERG_ASSIGN_OR_RAISE (auto load_result, LoadTableResultFromJson (json));
0 commit comments