Skip to content

Commit 78e8493

Browse files
authored
Improve docs TableSource and DefaultTableSource (#14665)
1 parent 9dc7fe9 commit 78e8493

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

datafusion/catalog/src/table.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,19 @@ use datafusion_expr::{
3333
};
3434
use datafusion_physical_plan::ExecutionPlan;
3535

36-
/// A named table which can be queried.
36+
/// A table which can be queried and modified.
3737
///
3838
/// Please see [`CatalogProvider`] for details of implementing a custom catalog.
3939
///
4040
/// [`TableProvider`] represents a source of data which can provide data as
41-
/// Apache Arrow `RecordBatch`es. Implementations of this trait provide
41+
/// Apache Arrow [`RecordBatch`]es. Implementations of this trait provide
4242
/// important information for planning such as:
4343
///
4444
/// 1. [`Self::schema`]: The schema (columns and their types) of the table
4545
/// 2. [`Self::supports_filters_pushdown`]: Should filters be pushed into this scan
4646
/// 2. [`Self::scan`]: An [`ExecutionPlan`] that can read data
4747
///
48+
/// [`RecordBatch`]: https://docs.rs/arrow/latest/arrow/record_batch/struct.RecordBatch.html
4849
/// [`CatalogProvider`]: super::CatalogProvider
4950
#[async_trait]
5051
pub trait TableProvider: Debug + Sync + Send {

datafusion/core/src/datasource/default_table_source.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ use arrow::datatypes::SchemaRef;
2626
use datafusion_common::{internal_err, Constraints};
2727
use datafusion_expr::{Expr, TableProviderFilterPushDown, TableSource, TableType};
2828

29-
/// DataFusion default table source, wrapping TableProvider.
29+
/// Implements [`TableSource`] for a [`TableProvider`]
3030
///
31-
/// This structure adapts a `TableProvider` (physical plan trait) to the `TableSource`
32-
/// (logical plan trait) and is necessary because the logical plan is contained in
33-
/// the `datafusion_expr` crate, and is not aware of table providers, which exist in
34-
/// the core `datafusion` crate.
31+
/// This structure adapts a [`TableProvider`] (a physical plan trait) to the
32+
/// [`TableSource`] (logical plan trait).
33+
///
34+
/// It is used so logical plans in the `datafusion_expr` crate do not have a
35+
/// direct dependency on physical plans, such as [`TableProvider`]s.
36+
///
37+
/// [`TableProvider`]: https://docs.rs/datafusion/latest/datafusion/datasource/provider/trait.TableProvider.html
3538
pub struct DefaultTableSource {
3639
/// table provider
3740
pub table_provider: Arc<dyn TableProvider>,

datafusion/expr/src/table_source.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,33 @@ impl std::fmt::Display for TableType {
7171
}
7272
}
7373

74-
/// Access schema information and filter push-down capabilities.
74+
/// Planning time information about a table.
7575
///
76-
/// The TableSource trait is used during logical query planning and
77-
/// optimizations and provides a subset of the functionality of the
78-
/// `TableProvider` trait in the (core) `datafusion` crate. The `TableProvider`
79-
/// trait provides additional capabilities needed for physical query execution
80-
/// (such as the ability to perform a scan).
76+
/// This trait is used during logical query planning and optimizations, and
77+
/// provides a subset of the [`TableProvider`] trait, such as schema information
78+
/// and filter push-down capabilities. The [`TableProvider`] trait provides
79+
/// additional information needed for physical query execution, such as the
80+
/// ability to perform a scan or insert data.
81+
///
82+
/// # See Also:
83+
///
84+
/// [`DefaultTableSource`] to go from [`TableProvider`], to `TableSource`
85+
///
86+
/// # Rationale
8187
///
8288
/// The reason for having two separate traits is to avoid having the logical
8389
/// plan code be dependent on the DataFusion execution engine. Some projects use
8490
/// DataFusion's logical plans and have their own execution engine.
91+
///
92+
/// [`TableProvider`]: https://docs.rs/datafusion/latest/datafusion/datasource/provider/trait.TableProvider.html
93+
/// [`DefaultTableSource`]: https://docs.rs/datafusion/latest/datafusion/datasource/default_table_source/struct.DefaultTableSource.html
8594
pub trait TableSource: Sync + Send {
8695
fn as_any(&self) -> &dyn Any;
8796

8897
/// Get a reference to the schema for this table
8998
fn schema(&self) -> SchemaRef;
9099

91-
/// Get primary key indices, if one exists.
100+
/// Get primary key indices, if any
92101
fn constraints(&self) -> Option<&Constraints> {
93102
None
94103
}
@@ -110,6 +119,8 @@ pub trait TableSource: Sync + Send {
110119
}
111120

112121
/// Get the Logical plan of this table provider, if available.
122+
///
123+
/// For example, a view may have a logical plan, but a CSV file does not.
113124
fn get_logical_plan(&self) -> Option<Cow<LogicalPlan>> {
114125
None
115126
}

0 commit comments

Comments
 (0)