Skip to content

Commit 8fdd8cf

Browse files
committed
Refactor imports and error handling in object_storage.rs for improved readability
1 parent 2ab27bf commit 8fdd8cf

File tree

1 file changed

+39
-31
lines changed

1 file changed

+39
-31
lines changed

datafusion-cli/src/object_storage.rs

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,35 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use std::any::Any;
19-
use std::error::Error;
20-
use std::fmt::{Debug, Display};
21-
use std::sync::Arc;
22-
23-
use datafusion::common::config::{
24-
ConfigEntry, ConfigExtension, ConfigField, ExtensionOptions, TableOptions, Visit,
25-
};
26-
use datafusion::common::{config_err, exec_datafusion_err, exec_err};
27-
use datafusion::error::{DataFusionError, Result};
28-
use datafusion::execution::context::SessionState;
29-
3018
use async_trait::async_trait;
3119
use aws_config::BehaviorVersion;
32-
use aws_credential_types::provider::error::CredentialsError;
33-
use aws_credential_types::provider::{ProvideCredentials, SharedCredentialsProvider};
20+
use aws_credential_types::provider::{
21+
error::CredentialsError, ProvideCredentials, SharedCredentialsProvider,
22+
};
23+
use datafusion::{
24+
common::{
25+
config::ConfigEntry, config::ConfigExtension, config::ConfigField,
26+
config::ExtensionOptions, config::TableOptions, config::Visit, config_err,
27+
exec_datafusion_err, exec_err,
28+
},
29+
error::{DataFusionError, Result},
30+
execution::context::SessionState,
31+
};
3432
use log::debug;
35-
use object_store::aws::{AmazonS3Builder, AmazonS3ConfigKey, AwsCredential};
36-
use object_store::gcp::GoogleCloudStorageBuilder;
37-
use object_store::http::HttpBuilder;
38-
use object_store::{ClientOptions, CredentialProvider, ObjectStore};
33+
use object_store::{
34+
aws::{AmazonS3Builder, AmazonS3ConfigKey, AwsCredential},
35+
gcp::GoogleCloudStorageBuilder,
36+
http::HttpBuilder,
37+
ClientOptions, CredentialProvider,
38+
Error::Generic,
39+
ObjectStore,
40+
};
41+
use std::{
42+
any::Any,
43+
error::Error,
44+
fmt::{Debug, Display},
45+
sync::Arc,
46+
};
3947
use url::Url;
4048

4149
#[cfg(not(test))]
@@ -153,7 +161,7 @@ impl CredentialsFromConfig {
153161
let credentials = config
154162
.credentials_provider()
155163
.ok_or_else(|| {
156-
DataFusionError::ObjectStore(Box::new(object_store::Error::Generic {
164+
DataFusionError::ObjectStore(Box::new(Generic {
157165
store: "S3",
158166
source: "Failed to get S3 credentials aws_config".into(),
159167
}))
@@ -183,12 +191,10 @@ impl CredentialsFromConfig {
183191
"Error getting credentials from provider: {e}{source_message}",
184192
);
185193

186-
return Err(DataFusionError::ObjectStore(Box::new(
187-
object_store::Error::Generic {
188-
store: "S3",
189-
source: message.into(),
190-
},
191-
)));
194+
return Err(DataFusionError::ObjectStore(Box::new(Generic {
195+
store: "S3",
196+
source: message.into(),
197+
})));
192198
}
193199
};
194200
Ok(Self {
@@ -208,12 +214,14 @@ impl CredentialProvider for S3CredentialProvider {
208214
type Credential = AwsCredential;
209215

210216
async fn get_credential(&self) -> object_store::Result<Arc<Self::Credential>> {
211-
let creds = self.credentials.provide_credentials().await.map_err(|e| {
212-
object_store::Error::Generic {
213-
store: "S3",
214-
source: Box::new(e),
215-
}
216-
})?;
217+
let creds =
218+
self.credentials
219+
.provide_credentials()
220+
.await
221+
.map_err(|e| Generic {
222+
store: "S3",
223+
source: Box::new(e),
224+
})?;
217225
Ok(Arc::new(AwsCredential {
218226
key_id: creds.access_key_id().to_string(),
219227
secret_key: creds.secret_access_key().to_string(),

0 commit comments

Comments
 (0)