@@ -24,7 +24,7 @@ use crate::datasource::TableProvider;
24
24
25
25
use arrow:: datatypes:: SchemaRef ;
26
26
use datafusion_common:: { internal_err, Constraints } ;
27
- use datafusion_expr:: { Expr , TableProviderFilterPushDown , TableSource } ;
27
+ use datafusion_expr:: { Expr , TableProviderFilterPushDown , TableSource , TableType } ;
28
28
29
29
/// DataFusion default table source, wrapping TableProvider.
30
30
///
@@ -61,6 +61,11 @@ impl TableSource for DefaultTableSource {
61
61
self . table_provider . constraints ( )
62
62
}
63
63
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
+
64
69
/// Tests whether the table provider can make use of any or all filter expressions
65
70
/// to optimise data retrieval.
66
71
fn supports_filters_pushdown (
@@ -100,3 +105,41 @@ pub fn source_as_provider(
100
105
_ => internal_err ! ( "TableSource was not DefaultTableSource" ) ,
101
106
}
102
107
}
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