MCPcopy Create free account
hub / github.com/apache/datafusion / get_table

Method get_table

benchmarks/src/imdb/run.rs:419–476  ·  view source on GitHub ↗
(
        &self,
        ctx: &SessionContext,
        table: &str,
    )

Source from the content-addressed store, hash-verified

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 }

Callers 1

register_tablesMethod · 0.45

Calls 15

newFunction · 0.85
get_imdb_table_schemaFunction · 0.85
with_collect_statMethod · 0.80
with_file_extensionMethod · 0.80
collect_statisticsMethod · 0.80
with_listing_optionsMethod · 0.80
with_cacheMethod · 0.80
as_strMethod · 0.45
stateMethod · 0.45
with_has_headerMethod · 0.45
with_delimiterMethod · 0.45

Tested by

no test coverage detected