You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "tustvold (via GitHub)" <gi...@apache.org> on 2023/05/15 19:14:23 UTC

[GitHub] [arrow-rs] tustvold opened a new pull request, #4220: Extract Common Listing and Retrieval Functionality

tustvold opened a new pull request, #4220:
URL: https://github.com/apache/arrow-rs/pull/4220

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Closes #.
   
   # Rationale for this change
    
   <!--
   Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
   Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.
   -->
   
   Extracts common listing and get functionality from the various cloud ObjectStore. This ends up being more code, but avoids duplication and so I think is probably better, would appreciate any thoughts?
   
   # What changes are included in this PR?
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are there any user-facing changes?
   
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!---
   If there are any breaking changes to public APIs, please add the `breaking change` label.
   -->
   


-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4220: Extract Common Listing and Retrieval Functionality

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4220:
URL: https://github.com/apache/arrow-rs/pull/4220#discussion_r1194264850


##########
object_store/src/aws/client.rs:
##########
@@ -302,89 +268,6 @@ impl S3Client {
         Ok(())
     }
 
-    /// Make an S3 List request <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html>
-    async fn list_request(
-        &self,
-        prefix: Option<&str>,
-        delimiter: bool,
-        token: Option<&str>,
-        offset: Option<&str>,
-    ) -> Result<(ListResult, Option<String>)> {
-        let credential = self.get_credential().await?;
-        let url = self.config.bucket_endpoint.clone();
-
-        let mut query = Vec::with_capacity(4);
-
-        // Note: the order of these matters to ensure the generated URL is canonical
-        if let Some(token) = token {
-            query.push(("continuation-token", token))
-        }
-
-        if delimiter {
-            query.push(("delimiter", DELIMITER))
-        }
-
-        query.push(("list-type", "2"));
-
-        if let Some(prefix) = prefix {
-            query.push(("prefix", prefix))
-        }
-
-        if let Some(offset) = offset {
-            query.push(("start-after", offset))
-        }
-
-        let response = self
-            .client
-            .request(Method::GET, &url)
-            .query(&query)
-            .with_aws_sigv4(
-                credential.as_ref(),
-                &self.config.region,
-                "s3",
-                self.config.sign_payload,
-                None,
-            )
-            .send_retry(&self.config.retry_config)
-            .await
-            .context(ListRequestSnafu)?
-            .bytes()
-            .await
-            .context(ListResponseBodySnafu)?;
-
-        let mut response: ListResponse = quick_xml::de::from_reader(response.reader())
-            .context(InvalidListResponseSnafu)?;
-        let token = response.next_continuation_token.take();
-
-        Ok((response.try_into()?, token))
-    }
-
-    /// Perform a list operation automatically handling pagination
-    pub fn list_paginated(

Review Comment:
   This is now implemented by ListClientExt



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4220: Extract Common Listing and Retrieval Functionality

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4220:
URL: https://github.com/apache/arrow-rs/pull/4220#discussion_r1194264181


##########
object_store/src/aws/client.rs:
##########
@@ -302,89 +268,6 @@ impl S3Client {
         Ok(())
     }
 
-    /// Make an S3 List request <https://docs.aws.amazon.com/AmazonS3/latest/API/API_ListObjectsV2.html>
-    async fn list_request(

Review Comment:
   This is just moved



##########
object_store/src/aws/client.rs:
##########
@@ -169,40 +169,6 @@ impl S3Client {
         self.config.credentials.get_credential().await
     }
 
-    /// Make an S3 GET request <https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html>
-    pub async fn get_request(

Review Comment:
   This is moved to be a trait implementation



-- 
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


[GitHub] [arrow-rs] alamb commented on a diff in pull request #4220: Extract Common Listing and Retrieval Functionality

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #4220:
URL: https://github.com/apache/arrow-rs/pull/4220#discussion_r1197009970


##########
object_store/src/azure/client.rs:
##########
@@ -300,14 +267,59 @@ impl AzureClient {
 
         Ok(())
     }
+}
 
+#[async_trait]
+impl GetClient for AzureClient {
+    const STORE: &'static str = STORE;
+
+    /// Make an Azure GET request
+    /// <https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob>
+    /// <https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-properties>
+    async fn get_request(
+        &self,
+        path: &Path,
+        options: GetOptions,
+        head: bool,
+    ) -> Result<Response> {
+        let credential = self.get_credential().await?;
+        let url = self.config.path_url(path);
+        let method = match head {
+            true => Method::HEAD,
+            false => Method::GET,
+        };
+
+        let builder = self
+            .client
+            .request(method, url)
+            .header(CONTENT_LENGTH, HeaderValue::from_static("0"))
+            .body(Bytes::new());
+
+        let response = builder
+            .with_get_options(options)
+            .with_azure_authorization(&credential, &self.config.account)
+            .send_retry(&self.config.retry_config)
+            .await
+            .context(GetRequestSnafu {
+                path: path.as_ref(),
+            })?;
+
+        Ok(response)
+    }
+}
+
+#[async_trait]
+impl ListClient for AzureClient {
     /// Make an Azure List request <https://docs.microsoft.com/en-us/rest/api/storageservices/list-blobs>
     async fn list_request(
         &self,
         prefix: Option<&str>,
         delimiter: bool,
         token: Option<&str>,
+        offset: Option<&str>,
     ) -> Result<(ListResult, Option<String>)> {
+        assert!(offset.is_none()); // Not yet supported

Review Comment:
   This should return an error rather than panic'ing I think



##########
object_store/src/client/get.rs:
##########
@@ -0,0 +1,68 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use crate::client::header::header_meta;
+use crate::path::Path;
+use crate::Result;
+use crate::{Error, GetOptions, GetResult, ObjectMeta};
+use async_trait::async_trait;
+use futures::{StreamExt, TryStreamExt};
+use reqwest::Response;
+
+#[async_trait]
+pub trait GetClient: Send + Sync + 'static {

Review Comment:
   I think some this should have some comments / explination for what it is doing



##########
object_store/src/azure/client.rs:
##########
@@ -346,22 +358,6 @@ impl AzureClient {
 
         Ok((to_list_result(response, prefix)?, token))
     }
-
-    /// Perform a list operation automatically handling pagination

Review Comment:
   This is now implemented indirectly via `ListClientExt`



-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4220: Extract Common Listing and Retrieval Functionality

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4220:
URL: https://github.com/apache/arrow-rs/pull/4220#discussion_r1194270361


##########
object_store/src/client/list_response.rs:
##########
@@ -0,0 +1,85 @@
+// or more contributor license agreements.  See the NOTICE file

Review Comment:
   This is just moved from list.rs



-- 
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


[GitHub] [arrow-rs] tustvold merged pull request #4220: Extract Common Listing and Retrieval Functionality

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold merged PR #4220:
URL: https://github.com/apache/arrow-rs/pull/4220


-- 
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


[GitHub] [arrow-rs] tustvold commented on a diff in pull request #4220: Extract Common Listing and Retrieval Functionality

Posted by "tustvold (via GitHub)" <gi...@apache.org>.
tustvold commented on code in PR #4220:
URL: https://github.com/apache/arrow-rs/pull/4220#discussion_r1197524556


##########
object_store/src/azure/client.rs:
##########
@@ -300,14 +267,59 @@ impl AzureClient {
 
         Ok(())
     }
+}
 
+#[async_trait]
+impl GetClient for AzureClient {
+    const STORE: &'static str = STORE;
+
+    /// Make an Azure GET request
+    /// <https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob>
+    /// <https://docs.microsoft.com/en-us/rest/api/storageservices/get-blob-properties>
+    async fn get_request(
+        &self,
+        path: &Path,
+        options: GetOptions,
+        head: bool,
+    ) -> Result<Response> {
+        let credential = self.get_credential().await?;
+        let url = self.config.path_url(path);
+        let method = match head {
+            true => Method::HEAD,
+            false => Method::GET,
+        };
+
+        let builder = self
+            .client
+            .request(method, url)
+            .header(CONTENT_LENGTH, HeaderValue::from_static("0"))
+            .body(Bytes::new());
+
+        let response = builder
+            .with_get_options(options)
+            .with_azure_authorization(&credential, &self.config.account)
+            .send_retry(&self.config.retry_config)
+            .await
+            .context(GetRequestSnafu {
+                path: path.as_ref(),
+            })?;
+
+        Ok(response)
+    }
+}
+
+#[async_trait]
+impl ListClient for AzureClient {
     /// Make an Azure List request <https://docs.microsoft.com/en-us/rest/api/storageservices/list-blobs>
     async fn list_request(
         &self,
         prefix: Option<&str>,
         delimiter: bool,
         token: Option<&str>,
+        offset: Option<&str>,
     ) -> Result<(ListResult, Option<String>)> {
+        assert!(offset.is_none()); // Not yet supported

Review Comment:
   It is unreachable by the current code



-- 
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