+use aws_sdk_s3::primitives::ByteStream;
use polars::prelude::*;
use std::env::args;
use std::fs::{create_dir_all,File};
-#[::tokio::main]
-async fn main() -> Result<(),PolarsError> {
-
- // expect first arg to be a file partition = 0, 1, 2
- let mut argsiter = args();
- let _ = argsiter.next();
- let partition = argsiter.next()
- .expect("single argument required, 0 or 1 or 2");
+async fn map_bucket(partition: &str) -> Result<(),PolarsError> {
// set some columns to be parsed as numeric
let mut schema_override = Schema::new();
.finish()?;
// split list based on arg
- match partition.as_str() {
+ match partition {
"0" => {
let mask = col("Country Name").lt(lit("Ethiopia"));
df = df.filter(mask);
("8", 1_000_000_000_000f64, 4_000_000_000_000f64)
];
+ // prep S3 client
let config = aws_config::load_from_env().await;
let client = aws_sdk_s3::Client::new(&config);
// write to s3
let _ = client.put_object()
- .bucket("mackdanz-polars-test")
- .key(outs3key.clone())
- .set_body(Some(aws_sdk_s3::primitives::ByteStream::from_path(outfilepath).await.unwrap()))
- .send().await;
+ .bucket("mackdanz-polars-test")
+ .key(outs3key.clone())
+ .set_body(Some(ByteStream::from_path(outfilepath)
+ .await.unwrap()))
+ .send().await;
println!("wrote file to S3 {}", outs3key);
}
Ok(())
}
+
+#[::tokio::main]
+async fn main() -> Result<(),PolarsError> {
+
+ let mut argsiter = args();
+ // first arg is program name
+ let _ = argsiter.next();
+ let command = argsiter.next()
+ .expect("no command arg");
+
+ match command.as_str() {
+ "mapbucket" => {
+ // expect next arg to be a file partition = 0, 1, 2
+ let partition = argsiter.next()
+ .expect("single argument required, 0 or 1 or 2");
+
+ map_bucket(partition.as_str()).await
+ },
+ _ => {
+ panic!("invalid command");
+ }
+ }
+
+}
+