(
&self,
ctx: &SessionContext,
table: &str,
)
| 417 | } |
| 418 | |
| 419 | async fn get_table( |
| 420 | &self, |
| 421 | ctx: &SessionContext, |
| 422 | table: &str, |
| 423 | ) -> Result<Arc<dyn TableProvider>> { |
| 424 | let path = self.path.to_str().unwrap(); |
| 425 | let table_format = self.file_format.as_str(); |
| 426 | |
| 427 | // Obtain a snapshot of the SessionState |
| 428 | let state = ctx.state(); |
| 429 | let (format, path, extension): (Arc<dyn FileFormat>, String, &'static str) = |
| 430 | match table_format { |
| 431 | // dbgen creates .tbl ('|' delimited) files without header |
| 432 | "tbl" => { |
| 433 | let path = format!("{path}/{table}.tbl"); |
| 434 | |
| 435 | let format = CsvFormat::default() |
| 436 | .with_delimiter(b'|') |
| 437 | .with_has_header(false); |
| 438 | |
| 439 | (Arc::new(format), path, ".tbl") |
| 440 | } |
| 441 | "csv" => { |
| 442 | let path = format!("{path}/{table}.csv"); |
| 443 | let format = CsvFormat::default() |
| 444 | .with_delimiter(b',') |
| 445 | .with_escape(Some(b'\\')) |
| 446 | .with_has_header(false); |
| 447 | |
| 448 | (Arc::new(format), path, DEFAULT_CSV_EXTENSION) |
| 449 | } |
| 450 | "parquet" => { |
| 451 | let path = format!("{path}/{table}.parquet"); |
| 452 | let format = ParquetFormat::default() |
| 453 | .with_options(ctx.state().table_options().parquet.clone()); |
| 454 | (Arc::new(format), path, DEFAULT_PARQUET_EXTENSION) |
| 455 | } |
| 456 | other => { |
| 457 | unimplemented!("Invalid file format '{}'", other); |
| 458 | } |
| 459 | }; |
| 460 | |
| 461 | let options = ListingOptions::new(format) |
| 462 | .with_file_extension(extension) |
| 463 | .with_collect_stat(state.config().collect_statistics()); |
| 464 | |
| 465 | let table_path = ListingTableUrl::parse(path)?; |
| 466 | let config = ListingTableConfig::new(table_path).with_listing_options(options); |
| 467 | let config = match table_format { |
| 468 | "parquet" => config.with_schema(Arc::new(get_imdb_table_schema(table))), |
| 469 | "csv" => config.with_schema(Arc::new(get_imdb_table_schema(table))), |
| 470 | _ => unreachable!(), |
| 471 | }; |
| 472 | |
| 473 | Ok(Arc::new(ListingTable::try_new(config)?.with_cache( |
| 474 | ctx.runtime_env().cache_manager.get_file_statistic_cache(), |
| 475 | ))) |
| 476 | } |
no test coverage detected