diff --git a/datafusion/core/src/execution/context.rs b/datafusion/core/src/execution/context.rs index c18c49eb86a39..202928a0cb782 100644 --- a/datafusion/core/src/execution/context.rs +++ b/datafusion/core/src/execution/context.rs @@ -527,18 +527,25 @@ impl SessionContext { let uri: String = uri.into(); let (object_store, path) = self.runtime_env().object_store(&uri)?; let target_partitions = self.copied_config().target_partitions; - Ok(Arc::new(DataFrame::new( - self.state.clone(), - &LogicalPlanBuilder::scan_json( - object_store, - path, - options, - None, - target_partitions, - ) - .await? - .build()?, - ))) + + let listing_options = options.to_listing_options(target_partitions); + + let path: String = path.into(); + + let resolved_schema = match options.schema { + Some(s) => s, + None => { + listing_options + .infer_schema(Arc::clone(&object_store), &path) + .await? + } + }; + let config = ListingTableConfig::new(object_store, path) + .with_listing_options(listing_options) + .with_schema(resolved_schema); + let provider = ListingTable::try_new(config)?; + + self.read_table(Arc::new(provider)) } /// Creates an empty DataFrame. diff --git a/datafusion/core/src/logical_plan/builder.rs b/datafusion/core/src/logical_plan/builder.rs index d5f881b9bf520..9a2d03b17dd27 100644 --- a/datafusion/core/src/logical_plan/builder.rs +++ b/datafusion/core/src/logical_plan/builder.rs @@ -305,55 +305,6 @@ impl LogicalPlanBuilder { Self::scan(table_name, Arc::new(provider), projection) } - /// Scan an Json data source - pub async fn scan_json( - object_store: Arc, - path: impl Into, - options: NdJsonReadOptions<'_>, - projection: Option>, - target_partitions: usize, - ) -> Result { - let path = path.into(); - Self::scan_json_with_name( - object_store, - path.clone(), - options, - projection, - path, - target_partitions, - ) - .await - } - - /// Scan an Json data source and register it with a given table name - pub async fn scan_json_with_name( - object_store: Arc, - path: impl Into, - options: NdJsonReadOptions<'_>, - projection: Option>, - table_name: impl Into, - target_partitions: usize, - ) -> Result { - let listing_options = options.to_listing_options(target_partitions); - - let path: String = path.into(); - - let resolved_schema = match options.schema { - Some(s) => s, - None => { - listing_options - .infer_schema(Arc::clone(&object_store), &path) - .await? - } - }; - let config = ListingTableConfig::new(object_store, path) - .with_listing_options(listing_options) - .with_schema(resolved_schema); - let provider = ListingTable::try_new(config)?; - - Self::scan(table_name, Arc::new(provider), projection) - } - /// Scan an empty data source, mainly used in tests pub fn scan_empty( name: Option<&str>,