Skip to content

Commit

Permalink
Remove scan_json methods from LogicalPlanBuilder (#2541)
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove authored May 16, 2022
1 parent 419adde commit ffb9fa6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 61 deletions.
31 changes: 19 additions & 12 deletions datafusion/core/src/execution/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
49 changes: 0 additions & 49 deletions datafusion/core/src/logical_plan/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn ObjectStore>,
path: impl Into<String>,
options: NdJsonReadOptions<'_>,
projection: Option<Vec<usize>>,
target_partitions: usize,
) -> Result<Self> {
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<dyn ObjectStore>,
path: impl Into<String>,
options: NdJsonReadOptions<'_>,
projection: Option<Vec<usize>>,
table_name: impl Into<String>,
target_partitions: usize,
) -> Result<Self> {
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>,
Expand Down

0 comments on commit ffb9fa6

Please sign in to comment.