Skip to content

Commit e25f5e7

Browse files
authored
impl table_type for DefaultTableSource (#13416)
1 parent 57235c2 commit e25f5e7

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

datafusion/core/src/datasource/default_table_source.rs

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::datasource::TableProvider;
2424

2525
use arrow::datatypes::SchemaRef;
2626
use datafusion_common::{internal_err, Constraints};
27-
use datafusion_expr::{Expr, TableProviderFilterPushDown, TableSource};
27+
use datafusion_expr::{Expr, TableProviderFilterPushDown, TableSource, TableType};
2828

2929
/// DataFusion default table source, wrapping TableProvider.
3030
///
@@ -61,6 +61,11 @@ impl TableSource for DefaultTableSource {
6161
self.table_provider.constraints()
6262
}
6363

64+
/// Get the type of this table for metadata/catalog purposes.
65+
fn table_type(&self) -> TableType {
66+
self.table_provider.table_type()
67+
}
68+
6469
/// Tests whether the table provider can make use of any or all filter expressions
6570
/// to optimise data retrieval.
6671
fn supports_filters_pushdown(
@@ -100,3 +105,41 @@ pub fn source_as_provider(
100105
_ => internal_err!("TableSource was not DefaultTableSource"),
101106
}
102107
}
108+
109+
#[test]
110+
fn preserves_table_type() {
111+
use async_trait::async_trait;
112+
use datafusion_common::DataFusionError;
113+
114+
#[derive(Debug)]
115+
struct TestTempTable;
116+
117+
#[async_trait]
118+
impl TableProvider for TestTempTable {
119+
fn as_any(&self) -> &dyn Any {
120+
self
121+
}
122+
123+
fn table_type(&self) -> TableType {
124+
TableType::Temporary
125+
}
126+
127+
fn schema(&self) -> SchemaRef {
128+
unimplemented!()
129+
}
130+
131+
async fn scan(
132+
&self,
133+
_: &dyn datafusion_catalog::Session,
134+
_: Option<&Vec<usize>>,
135+
_: &[Expr],
136+
_: Option<usize>,
137+
) -> Result<Arc<dyn datafusion_physical_plan::ExecutionPlan>, DataFusionError>
138+
{
139+
unimplemented!()
140+
}
141+
}
142+
143+
let table_source = DefaultTableSource::new(Arc::new(TestTempTable));
144+
assert_eq!(table_source.table_type(), TableType::Temporary);
145+
}

0 commit comments

Comments
 (0)