You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2023/06/11 17:49:21 UTC

[arrow-datafusion] branch main updated: fix: fix more panics in `ListingTable` (#6636)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new 93b1a57f9a fix: fix more panics in `ListingTable` (#6636)
93b1a57f9a is described below

commit 93b1a57f9a3a5adf7258282cd856b7eafecec5da
Author: Folyd <ly...@gmail.com>
AuthorDate: Mon Jun 12 01:49:15 2023 +0800

    fix: fix more panics in `ListingTable` (#6636)
---
 datafusion/core/src/datasource/listing/table.rs | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rs
index 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 plan
         self.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,