(self)
| 50 | |
| 51 | impl ConvertOpt { |
| 52 | pub async fn run(self) -> Result<()> { |
| 53 | let input_path = self.input_path.to_str().unwrap(); |
| 54 | let output_path = self.output_path.to_str().unwrap(); |
| 55 | let config = SessionConfig::new().with_batch_size(self.batch_size); |
| 56 | let ctx = SessionContext::new_with_config(config); |
| 57 | |
| 58 | for table in IMDB_TABLES { |
| 59 | let start = Instant::now(); |
| 60 | let schema = get_imdb_table_schema(table); |
| 61 | let input_path = format!("{input_path}/{table}.csv"); |
| 62 | let output_path = format!("{output_path}/{table}.parquet"); |
| 63 | let options = CsvReadOptions::new() |
| 64 | .schema(&schema) |
| 65 | .has_header(false) |
| 66 | .delimiter(b',') |
| 67 | .escape(b'\\') |
| 68 | .file_extension(".csv"); |
| 69 | |
| 70 | let mut csv = ctx.read_csv(&input_path, options).await?; |
| 71 | |
| 72 | // Select all apart from the padding column |
| 73 | let selection = csv |
| 74 | .schema() |
| 75 | .iter() |
| 76 | .take(schema.fields.len()) |
| 77 | .map(Expr::from) |
| 78 | .map(SelectExpr::from) |
| 79 | .collect::<Vec<_>>(); |
| 80 | |
| 81 | csv = csv.select(selection)?; |
| 82 | |
| 83 | println!( |
| 84 | "Converting '{}' to {} files in directory '{}'", |
| 85 | &input_path, self.file_format, &output_path |
| 86 | ); |
| 87 | match self.file_format.as_str() { |
| 88 | "csv" => { |
| 89 | csv.write_csv( |
| 90 | output_path.as_str(), |
| 91 | DataFrameWriteOptions::new(), |
| 92 | None, |
| 93 | ) |
| 94 | .await?; |
| 95 | } |
| 96 | "parquet" => { |
| 97 | csv.write_parquet( |
| 98 | output_path.as_str(), |
| 99 | DataFrameWriteOptions::new(), |
| 100 | None, |
| 101 | ) |
| 102 | .await?; |
| 103 | } |
| 104 | other => { |
| 105 | return not_impl_err!("Invalid output format: {other}"); |
| 106 | } |
| 107 | } |
| 108 | println!("Conversion completed in {} ms", start.elapsed().as_millis()); |
| 109 | } |
nothing calls this directly
no test coverage detected