(
&self,
ctx: &SessionContext,
table: &str,
)
| 303 | } |
| 304 | |
| 305 | async fn get_table( |
| 306 | &self, |
| 307 | ctx: &SessionContext, |
| 308 | table: &str, |
| 309 | ) -> Result<Arc<dyn TableProvider>> { |
| 310 | let path = self.path.to_str().unwrap(); |
| 311 | let target_partitions = self.partitions(); |
| 312 | |
| 313 | // Obtain a snapshot of the SessionState |
| 314 | let state = ctx.state(); |
| 315 | let path = format!("{path}/{table}.parquet"); |
| 316 | |
| 317 | // Check if the file exists |
| 318 | if !std::path::Path::new(&path).exists() { |
| 319 | eprintln!("Warning registering {table}: Table file does not exist: {path}"); |
| 320 | } |
| 321 | |
| 322 | let format = ParquetFormat::default() |
| 323 | .with_options(ctx.state().table_options().parquet.clone()); |
| 324 | |
| 325 | let table_path = ListingTableUrl::parse(path)?; |
| 326 | let options = ListingOptions::new(Arc::new(format)) |
| 327 | .with_file_extension(DEFAULT_PARQUET_EXTENSION) |
| 328 | .with_target_partitions(target_partitions) |
| 329 | .with_collect_stat(state.config().collect_statistics()); |
| 330 | let schema = options.infer_schema(&state, &table_path).await?; |
| 331 | |
| 332 | if self.common.debug { |
| 333 | println!( |
| 334 | "Inferred schema from {table_path} for table '{table}':\n{schema:#?}\n" |
| 335 | ); |
| 336 | } |
| 337 | |
| 338 | let options = if self.sorted { |
| 339 | let key_column_name = schema.fields()[0].name(); |
| 340 | options |
| 341 | .with_file_sort_order(vec![vec![col(key_column_name).sort(true, false)]]) |
| 342 | } else { |
| 343 | options |
| 344 | }; |
| 345 | |
| 346 | let config = ListingTableConfig::new(table_path) |
| 347 | .with_listing_options(options) |
| 348 | .with_schema(schema); |
| 349 | |
| 350 | Ok(Arc::new(ListingTable::try_new(config)?.with_cache( |
| 351 | ctx.runtime_env().cache_manager.get_file_statistic_cache(), |
| 352 | ))) |
| 353 | } |
| 354 | |
| 355 | fn iterations(&self) -> usize { |
| 356 | self.common.iterations |
no test coverage detected