-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move remaining code out of legacy
core/logical_plan
module (#2701)
* move DefaultTableSource to datasource module * add public re-exports * clippy
- Loading branch information
Showing
11 changed files
with
151 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! Default TableSource implementation used in DataFusion physical plans | ||
use crate::datasource::TableProvider; | ||
use arrow::datatypes::SchemaRef; | ||
use datafusion_common::DataFusionError; | ||
use datafusion_expr::{Expr, TableProviderFilterPushDown, TableSource}; | ||
use std::any::Any; | ||
use std::sync::Arc; | ||
|
||
/// DataFusion default table source, wrapping TableProvider | ||
/// | ||
/// This structure adapts a `TableProvider` (physical plan trait) to the `TableSource` | ||
/// (logical plan trait) | ||
pub struct DefaultTableSource { | ||
/// table provider | ||
pub table_provider: Arc<dyn TableProvider>, | ||
} | ||
|
||
impl DefaultTableSource { | ||
/// Create a new DefaultTableSource to wrap a TableProvider | ||
pub fn new(table_provider: Arc<dyn TableProvider>) -> Self { | ||
Self { table_provider } | ||
} | ||
} | ||
|
||
impl TableSource for DefaultTableSource { | ||
/// Returns the table source as [`Any`](std::any::Any) so that it can be | ||
/// downcast to a specific implementation. | ||
fn as_any(&self) -> &dyn Any { | ||
self | ||
} | ||
|
||
/// Get a reference to the schema for this table | ||
fn schema(&self) -> SchemaRef { | ||
self.table_provider.schema() | ||
} | ||
|
||
/// Tests whether the table provider can make use of a filter expression | ||
/// to optimise data retrieval. | ||
fn supports_filter_pushdown( | ||
&self, | ||
filter: &Expr, | ||
) -> datafusion_common::Result<TableProviderFilterPushDown> { | ||
self.table_provider.supports_filter_pushdown(filter) | ||
} | ||
} | ||
|
||
/// Wrap TableProvider in TableSource | ||
pub fn provider_as_source( | ||
table_provider: Arc<dyn TableProvider>, | ||
) -> Arc<dyn TableSource> { | ||
Arc::new(DefaultTableSource::new(table_provider)) | ||
} | ||
|
||
/// Attempt to downcast a TableSource to DefaultTableSource and access the | ||
/// TableProvider. This will only work with a TableSource created by DataFusion. | ||
pub fn source_as_provider( | ||
source: &Arc<dyn TableSource>, | ||
) -> datafusion_common::Result<Arc<dyn TableProvider>> { | ||
match source | ||
.as_ref() | ||
.as_any() | ||
.downcast_ref::<DefaultTableSource>() | ||
{ | ||
Some(source) => Ok(source.table_provider.clone()), | ||
_ => Err(DataFusionError::Internal( | ||
"TableSource was not DefaultTableSource".to_string(), | ||
)), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters