Skip to content

Commit 2fc8889

Browse files
committed
System tables alse need a part.
1 parent 8a7d265 commit 2fc8889

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/query/storages/preludes/src/system/one_table.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use common_planners::Extras;
2424
use common_planners::Partitions;
2525
use common_planners::Statistics;
2626

27+
use super::table::SystemTablePart;
2728
use crate::sessions::TableContext;
2829
use crate::storages::system::table::SyncOneBlockSystemTable;
2930
use crate::storages::system::table::SyncSystemTable;
@@ -51,7 +52,9 @@ impl SyncSystemTable for OneTable {
5152
_ctx: Arc<dyn TableContext>,
5253
_push_downs: Option<Extras>,
5354
) -> Result<(Statistics, Partitions)> {
54-
Ok((Statistics::new_exact(1, 1, 1, 1), vec![]))
55+
Ok((Statistics::new_exact(1, 1, 1, 1), vec![Arc::new(Box::new(
56+
SystemTablePart,
57+
))]))
5558
}
5659
}
5760

src/query/storages/preludes/src/system/table.rs

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use std::sync::Arc;
1818
use common_datablocks::DataBlock;
1919
use common_exception::Result;
2020
use common_meta_app::schema::TableInfo;
21+
use common_pipeline_sources::processors::sources::EmptySource;
2122
use common_planners::Extras;
23+
use common_planners::PartInfo;
2224
use common_planners::Partitions;
2325
use common_planners::ReadDataSourcePlan;
2426
use common_planners::Statistics;
@@ -34,6 +36,23 @@ use crate::pipelines::Pipeline;
3436
use crate::sessions::TableContext;
3537
use crate::storages::Table;
3638

39+
#[derive(serde::Serialize, serde::Deserialize, PartialEq, Eq)]
40+
pub struct SystemTablePart;
41+
42+
#[typetag::serde(name = "system")]
43+
impl PartInfo for SystemTablePart {
44+
fn as_any(&self) -> &dyn Any {
45+
self
46+
}
47+
48+
fn equals(&self, info: &Box<dyn PartInfo>) -> bool {
49+
match info.as_any().downcast_ref::<SystemTablePart>() {
50+
None => false,
51+
Some(other) => self == other,
52+
}
53+
}
54+
}
55+
3756
pub trait SyncSystemTable: Send + Sync {
3857
const NAME: &'static str;
3958

@@ -45,7 +64,9 @@ pub trait SyncSystemTable: Send + Sync {
4564
_ctx: Arc<dyn TableContext>,
4665
_push_downs: Option<Extras>,
4766
) -> Result<(Statistics, Partitions)> {
48-
Ok((Statistics::default(), vec![]))
67+
Ok((Statistics::default(), vec![Arc::new(Box::new(
68+
SystemTablePart,
69+
))]))
4970
}
5071
}
5172

@@ -84,9 +105,21 @@ impl<TTable: 'static + SyncSystemTable> Table for SyncOneBlockSystemTable<TTable
84105
fn read2(
85106
&self,
86107
ctx: Arc<dyn TableContext>,
87-
_: &ReadDataSourcePlan,
108+
plan: &ReadDataSourcePlan,
88109
pipeline: &mut Pipeline,
89110
) -> Result<()> {
111+
// avoid duplicate read in cluster mode.
112+
if plan.parts.is_empty() {
113+
let output = OutputPort::create();
114+
pipeline.add_pipe(Pipe::SimplePipe {
115+
inputs_port: vec![],
116+
outputs_port: vec![output.clone()],
117+
processors: vec![EmptySource::create(output)?],
118+
});
119+
120+
return Ok(());
121+
}
122+
90123
let output = OutputPort::create();
91124
let inner_table = self.inner_table.clone();
92125
pipeline.add_pipe(Pipe::SimplePipe {
@@ -150,7 +183,9 @@ pub trait AsyncSystemTable: Send + Sync {
150183
_ctx: Arc<dyn TableContext>,
151184
_push_downs: Option<Extras>,
152185
) -> Result<(Statistics, Partitions)> {
153-
Ok((Statistics::default(), vec![]))
186+
Ok((Statistics::default(), vec![Arc::new(Box::new(
187+
SystemTablePart,
188+
))]))
154189
}
155190
}
156191

0 commit comments

Comments
 (0)