-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
512e3a2
commit 1d5f05e
Showing
4 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use aws_config; | ||
use aws_config::BehaviorVersion; | ||
use aws_sdk_sts::config::ProvideCredentials; | ||
use deltalake::{open_table_with_storage_options, DeltaTable, DeltaTableError}; | ||
use std::collections::HashMap; | ||
use std::time::Duration; | ||
|
||
// Load AWS Creds into a hashmap for use with delta lake reader | ||
pub fn get_aws_config() -> Result<HashMap<String, String>, Box<dyn std::error::Error>> { | ||
let runtime = tokio::runtime::Runtime::new().unwrap(); | ||
let config = runtime.block_on(async { | ||
aws_config::defaults(BehaviorVersion::latest()) | ||
.retry_config(aws_config::retry::RetryConfig::standard().with_max_attempts(5)) | ||
.timeout_config( | ||
aws_config::timeout::TimeoutConfig::builder() | ||
.operation_timeout(Duration::from_secs(30)) | ||
.build(), | ||
) | ||
.load() | ||
.await | ||
}); | ||
|
||
let mut aws_info = HashMap::new(); | ||
// Add credentials to HashMap if available | ||
if let Some(creds_provider) = config.credentials_provider() { | ||
match runtime.block_on(creds_provider.provide_credentials()) { | ||
Ok(creds) => { | ||
aws_info.insert( | ||
"AWS_ACCESS_KEY_ID".to_string(), | ||
creds.access_key_id().to_string(), | ||
); | ||
aws_info.insert( | ||
"AWS_SECRET_ACCESS_KEY".to_string(), | ||
creds.secret_access_key().to_string(), | ||
); | ||
if let Some(session_token) = creds.session_token() { | ||
aws_info.insert("AWS_SESSION_TOKEN".to_string(), session_token.to_string()); | ||
} | ||
} | ||
Err(e) => return Err(format!("Failed to retrieve credentials: {}", e).into()), | ||
} | ||
} else { | ||
return Err("No credentials provider found in the configuration".into()); | ||
} | ||
// Add success message | ||
println!("AWS configuration loaded successfully and added to HashMap."); | ||
Ok(aws_info) | ||
} | ||
|
||
// Read basic info about delta lake stored in S3 | ||
pub fn load_remote_delta_lake_table_info( | ||
s3_uri: &str, | ||
credential_hash_map: HashMap<String, String>, | ||
) -> Result<DeltaTable, DeltaTableError> { | ||
let storage_options: HashMap<String, String> = credential_hash_map; | ||
|
||
deltalake_aws::register_handlers(None); | ||
|
||
let remote_delta_lake_table = open_table(s3_uri, Some(storage_options))?; | ||
|
||
println!("version: {}", remote_delta_lake_table.version()); | ||
println!("metadata: {:?}", remote_delta_lake_table.metadata()); | ||
Ok(remote_delta_lake_table) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
pub mod api; | ||
pub mod bytes; | ||
pub mod csv; | ||
pub mod delta_lake; | ||
pub mod excel; | ||
pub mod utils; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters