Apache DataFusion SQL Query Engine
fix: fix more panics in `ListingTable` (#6636)
Folyd93b1a57f9a3a
diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rsindex f6b0183f21..c14127c45e 100644--- a/datafusion/core/src/datasource/listing/table.rs+++ b/datafusion/core/src/datasource/listing/table.rs@@ -22,6 +22,7 @@ use std::{any::Any, sync::Arc};use arrow::compute::SortOptions;use arrow::datatypes::{DataType, Field, SchemaBuilder, SchemaRef};+use arrow_schema::Schema;use async_trait::async_trait;use dashmap::DashMap;use datafusion_common::ToDFSchema;@@ -149,9 +150,11 @@ impl ListingTableConfig {/// Infer `ListingOptions` based on `table_path` suffix.pub async fn infer_options(self, state: &SessionState) -> Result<Self> {- let store = state- .runtime_env()- .object_store(self.table_paths.get(0).unwrap())?;+ let store = if let Some(url) = self.table_paths.get(0) {+ state.runtime_env().object_store(url)?+ } else {+ return Ok(self);+ };let file = self.table_paths@@ -180,9 +183,11 @@ impl ListingTableConfig {pub async fn infer_schema(self, state: &SessionState) -> Result<Self> {match self.options {Some(options) => {- let schema = options- .infer_schema(state, self.table_paths.get(0).unwrap())- .await?;+ let schema = if let Some(url) = self.table_paths.get(0) {+ options.infer_schema(state, url).await?+ } else {+ Arc::new(Schema::empty())+ };Ok(Self {table_paths: self.table_paths,@@ -713,13 +718,18 @@ impl TableProvider for ListingTable {None};+ let object_store_url = if let Some(url) = self.table_paths.get(0) {+ url.object_store()+ } else {+ return Ok(Arc::new(EmptyExec::new(false, Arc::new(Schema::empty()))));+ };// create the execution planself.options.format.create_physical_plan(state,FileScanConfig {- object_store_url: self.table_paths.get(0).unwrap().object_store(),+ object_store_url,file_schema: Arc::clone(&self.file_schema),file_groups: partitioned_file_lists,statistics,