table/test_util/
empty_table.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::sync::Arc;
16
17use common_error::ext::BoxedError;
18use common_recordbatch::{EmptyRecordBatchStream, SendableRecordBatchStream};
19use datatypes::schema::SchemaRef;
20use store_api::data_source::DataSource;
21use store_api::storage::ScanRequest;
22
23use crate::metadata::{FilterPushDownType, TableInfo};
24use crate::{Table, TableRef};
25
26pub struct EmptyTable;
27
28impl EmptyTable {
29    pub fn from_table_info(info: &TableInfo) -> TableRef {
30        let data_source = Arc::new(EmptyDataSource {
31            schema: info.meta.schema.clone(),
32        });
33        let table = Table::new(
34            Arc::new(info.clone()),
35            FilterPushDownType::Unsupported,
36            data_source,
37        );
38        Arc::new(table)
39    }
40}
41
42struct EmptyDataSource {
43    schema: SchemaRef,
44}
45
46impl DataSource for EmptyDataSource {
47    fn get_stream(
48        &self,
49        _request: ScanRequest,
50    ) -> std::result::Result<SendableRecordBatchStream, BoxedError> {
51        Ok(Box::pin(EmptyRecordBatchStream::new(self.schema.clone())))
52    }
53}