You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/06/22 15:50:14 UTC

[GitHub] [arrow] pitrou commented on a diff in pull request #13404: ARROW-16510: [R] Add bindings for GCS filesystem

pitrou commented on code in PR #13404:
URL: https://github.com/apache/arrow/pull/13404#discussion_r903935405


##########
r/src/filesystem.cpp:
##########
@@ -331,3 +337,77 @@ std::string fs___S3FileSystem__region(const std::shared_ptr<fs::S3FileSystem>& f
 }
 
 #endif
+
+#if defined(ARROW_R_WITH_GCS)
+
+#include <arrow/filesystem/gcsfs.h>
+
+std::shared_ptr<arrow::KeyValueMetadata> strings_to_kvm(cpp11::strings metadata);
+
+// [[gcs::export]]
+std::shared_ptr<fs::GcsFileSystem> fs___GcsFileSystem__Make(bool anonymous,
+                                                            cpp11::list options) {
+  fs::GcsOptions gcs_opts;
+
+  // Handle auth (anonymous, credentials, default)
+  // (validation/internal coherence handled in R)
+  if (anonymous) {
+    gcs_opts = fs::GcsOptions::Anonymous();
+  } else if (!Rf_isNull(options["access_token"])) {
+    // Convert POSIXct timestamp seconds to nanoseconds
+    std::chrono::nanoseconds ns_count(
+        static_cast<int64_t>(cpp11::as_cpp<double>(options["expiration"])) * 1000000000);
+    auto expiration_timepoint =
+        fs::TimePoint(std::chrono::duration_cast<fs::TimePoint::duration>(ns_count));
+    gcs_opts = fs::GcsOptions::FromAccessToken(
+        cpp11::as_cpp<std::string>(options["access_token"]), expiration_timepoint);
+    // TODO: implement FromImpersonatedServiceAccount
+    // } else if (base_credentials != "") {
+    //   // static GcsOptions FromImpersonatedServiceAccount(
+    //   // const GcsCredentials& base_credentials, const std::string&
+    //   target_service_account);
+    //   // TODO: construct GcsCredentials
+    //   gcs_opts = fs::GcsOptions::FromImpersonatedServiceAccount(base_credentials,
+    //                                                             target_service_account);
+  } else if (!Rf_isNull(options["json_credentials"])) {
+    gcs_opts = fs::GcsOptions::FromServiceAccountCredentials(
+        cpp11::as_cpp<std::string>(options["json_credentials"]));
+  } else {
+    gcs_opts = fs::GcsOptions::Defaults();
+  }
+
+  // Handle other attributes
+  if (!Rf_isNull(options["endpoint_override"])) {
+    gcs_opts.endpoint_override = cpp11::as_cpp<std::string>(options["endpoint_override"]);
+  }
+
+  if (!Rf_isNull(options["scheme"])) {
+    gcs_opts.scheme = cpp11::as_cpp<std::string>(options["scheme"]);
+  }
+
+  // /// \brief Location to use for creating buckets.
+  if (!Rf_isNull(options["default_bucket_location"])) {
+    gcs_opts.default_bucket_location =
+        cpp11::as_cpp<std::string>(options["default_bucket_location"]);
+  }
+  // /// \brief If set used to control total time allowed for retrying underlying
+  // /// errors.
+  // ///
+  // /// The default policy is to retry for up to 15 minutes.
+  if (!Rf_isNull(options["retry_limit_seconds"])) {
+    gcs_opts.retry_limit_seconds = cpp11::as_cpp<double>(options["retry_limit_seconds"]);
+  }
+
+  // /// \brief Default metadata for OpenOutputStream.
+  // ///
+  // /// This will be ignored if non-empty metadata is passed to OpenOutputStream.
+  if (!Rf_isNull(options["default_metadata"])) {
+    gcs_opts.default_metadata = strings_to_kvm(options["default_metadata"]);
+  }
+
+  auto io_context = arrow::io::IOContext(gc_memory_pool());
+  // TODO: S3FileSystem::Make returns a Result and uses ValueOrStop but this doesn't?

Review Comment:
   Let's make it a `Result`, so that we can potentially raise errors on invalid parameters etc.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org