table/
dist_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::SendableRecordBatchStream;
19use store_api::data_source::DataSource;
20use store_api::storage::ScanRequest;
21
22use crate::error::UnsupportedSnafu;
23use crate::metadata::{FilterPushDownType, TableInfoRef};
24use crate::table::PartitionRules;
25use crate::{Table, TableRef};
26
27#[derive(Clone)]
28pub struct DistTable;
29
30impl DistTable {
31    pub fn table(table_info: TableInfoRef) -> TableRef {
32        let data_source = Arc::new(DummyDataSource);
33        let table = Table::new(table_info, FilterPushDownType::Inexact, data_source);
34        Arc::new(table)
35    }
36
37    pub fn table_partitioned(
38        table_info: TableInfoRef,
39        partition_rule: Option<PartitionRules>,
40    ) -> TableRef {
41        let data_source = Arc::new(DummyDataSource);
42        let table = Table::new_partitioned(
43            table_info,
44            FilterPushDownType::Inexact,
45            data_source,
46            partition_rule,
47        );
48        Arc::new(table)
49    }
50}
51
52pub struct DummyDataSource;
53
54impl DataSource for DummyDataSource {
55    fn get_stream(
56        &self,
57        _request: ScanRequest,
58    ) -> std::result::Result<SendableRecordBatchStream, BoxedError> {
59        UnsupportedSnafu {
60            operation: "get stream from a distributed table",
61        }
62        .fail()
63        .map_err(BoxedError::new)
64    }
65}