3838#include " iceberg/catalog/rest/rest_file_io.h"
3939#include " iceberg/catalog/rest/rest_util.h"
4040#include " iceberg/catalog/rest/types.h"
41+ #include " iceberg/file_io_registry.h"
4142#include " iceberg/json_serde_internal.h"
4243#include " iceberg/partition_spec.h"
4344#include " iceberg/result.h"
@@ -486,13 +487,36 @@ Result<LoadTableResult> RestCatalog::LoadTableResultFor(
486487 return LoadTableResultFromJson (json);
487488}
488489
490+ Result<std::shared_ptr<FileIO>> RestCatalog::MakeFileIOForTable (
491+ const LoadTableResult& load_result) const {
492+ // Longest-prefix S3-family vended credential, matching the Java client's
493+ // VendedCredentialsProvider.
494+ const StorageCredential* s3_cred =
495+ SelectS3StorageCredential (load_result.storage_credentials );
496+ if (s3_cred == nullptr ) {
497+ return file_io_;
498+ }
499+
500+ // Build an S3 FileIO from catalog + table config + the vended credential; its
501+ // ResolvePath resolves oss:// and other S3-compatible schemes.
502+ auto properties = config_.configs ();
503+ for (const auto & [key, value] : load_result.config ) {
504+ properties[key] = value;
505+ }
506+ for (const auto & [key, value] : s3_cred->config ) {
507+ properties[key] = value;
508+ }
509+ ICEBERG_ASSIGN_OR_RAISE (
510+ auto io,
511+ FileIORegistry::Load (std::string (FileIORegistry::kArrowS3FileIO ), properties));
512+ return std::shared_ptr<FileIO>(std::move (io));
513+ }
514+
489515Result<std::shared_ptr<Table>> RestCatalog::LoadTable (const TableIdentifier& identifier) {
490516 ICEBERG_ASSIGN_OR_RAISE (auto load_result, LoadTableResultFor (identifier));
491- // Binds the catalog's default FileIO; use LoadTableResultFor() for vended creds.
492- // TODO: Support table-specific auth config and per-table FileIO from the REST
493- // load response when table-scoped REST operations are introduced.
517+ ICEBERG_ASSIGN_OR_RAISE (auto io, MakeFileIOForTable (load_result));
494518 return Table::Make (identifier, std::move (load_result.metadata ),
495- std::move (load_result.metadata_location ), file_io_ ,
519+ std::move (load_result.metadata_location ), std::move (io) ,
496520 shared_from_this ());
497521}
498522
@@ -514,10 +538,9 @@ Result<std::shared_ptr<Table>> RestCatalog::RegisterTable(
514538
515539 ICEBERG_ASSIGN_OR_RAISE (auto json, FromJsonString (response.body ()));
516540 ICEBERG_ASSIGN_OR_RAISE (auto load_result, LoadTableResultFromJson (json));
517- // TODO: Support table-specific auth config and per-table FileIO from the REST
518- // register response when table-scoped REST operations are introduced.
541+ ICEBERG_ASSIGN_OR_RAISE (auto io, MakeFileIOForTable (load_result));
519542 return Table::Make (identifier, std::move (load_result.metadata ),
520- std::move (load_result.metadata_location ), file_io_ ,
543+ std::move (load_result.metadata_location ), std::move (io) ,
521544 shared_from_this ());
522545}
523546
0 commit comments