datafusion_catalog/
empty.rs1use std::sync::Arc;
8
9use arrow::datatypes::*;
10use async_trait::async_trait;
11use datafusion_common::{Result, project_schema};
12use datafusion_expr::{Expr, TableType};
13use datafusion_physical_plan::ExecutionPlan;
14use datafusion_physical_plan::empty::EmptyExec;
15
16use crate::Session;
17use crate::TableProvider;
18
19#[derive(Debug)]
22pub struct EmptyTable {
23 schema: SchemaRef,
24 partitions: usize,
25}
26
27impl EmptyTable {
28 pub fn new(schema: SchemaRef) -> Self {
30 Self {
31 schema,
32 partitions: 1,
33 }
34 }
35
36 pub fn with_partitions(mut self, partitions: usize) -> Self {
38 self.partitions = partitions;
39 self
40 }
41}
42
43#[async_trait]
44impl TableProvider for EmptyTable {
45 fn schema(&self) -> SchemaRef {
46 Arc::clone(&self.schema)
47 }
48
49 fn table_type(&self) -> TableType {
50 TableType::Base
51 }
52
53 async fn scan(
54 &self,
55 _state: &dyn Session,
56 projection: Option<&[usize]>,
57 _filters: &[Expr],
58 _limit: Option<usize>,
59 ) -> Result<Arc<dyn ExecutionPlan>> {
60 let projected_schema = project_schema(&self.schema, projection)?;
62 Ok(Arc::new(
63 EmptyExec::new(projected_schema).with_partitions(self.partitions),
64 ))
65 }
66}