[query] refactor: impl Configs table with embedded TableInfo
@@ -20,6 +20,7 @@ use common_catalog::TableIOContext;
use common_datablocks::DataBlock;
use common_datavalues::prelude::*;
use common_exception::Result;
+use common_meta_types::TableInfo;
use common_planners::Extras;
use common_planners::Part;
use common_planners::ReadDataSourcePlan;
@@ -29,25 +30,30 @@ use common_streams::SendableDataBlockStream;
use serde_json::Value;
use crate::catalogs::Table;
-use crate::catalogs::ToTableInfo;
use crate::sessions::DatabendQueryContext;
pub struct ConfigsTable {
- table_id: u64,
- schema: DataSchemaRef,
+ table_info: TableInfo,
}
impl ConfigsTable {
pub fn create(table_id: u64) -> Self {
- ConfigsTable {
- table_id,
- schema: DataSchemaRefExt::create(vec![
+ let schema = DataSchemaRefExt::create(vec![
DataField::new("name", DataType::String, false),
DataField::new("value", DataType::String, false),
DataField::new("group", DataType::String, false),
DataField::new("description", DataType::String, false),
- ]),
- }
+ ]);
+
+ let table_info = TableInfo {
+ name: "configs".to_string(),
+ table_id,
+ schema,
+ engine: "SystemConfigs".to_string(),
+ is_local: true,
+ ..Default::default()
+ };
+ ConfigsTable { table_info }
}
fn extract_config(
@@ -74,11 +80,11 @@ impl ConfigsTable {
#[async_trait::async_trait]
impl Table for ConfigsTable {
fn name(&self) -> &str {
- "configs"
+ &self.table_info.name
}
fn engine(&self) -> &str {
- "SystemConfigs"
+ &self.table_info.engine
}
fn as_any(&self) -> &dyn Any {
@@ -86,15 +92,15 @@ impl Table for ConfigsTable {
}
fn schema(&self) -> Result<DataSchemaRef> {
- Ok(self.schema.clone())
+ Ok(self.table_info.schema.clone())
}
fn get_id(&self) -> u64 {
- self.table_id
+ self.table_info.table_id
}
fn is_local(&self) -> bool {
- true
+ self.table_info.is_local
}
fn read_plan(
@@ -104,7 +110,7 @@ impl Table for ConfigsTable {
_partition_num_hint: Option<usize>,
) -> Result<ReadDataSourcePlan> {
Ok(ReadDataSourcePlan {
- table_info: self.to_table_info("system")?,
+ table_info: self.table_info.clone(),
parts: vec![Part {
name: "".to_string(),
version: 0,
@@ -170,14 +176,14 @@ impl Table for ConfigsTable {
let values: Vec<&str> = values.iter().map(|x| x.as_str()).collect();
let groups: Vec<&str> = groups.iter().map(|x| x.as_str()).collect();
let descs: Vec<&str> = descs.iter().map(|x| x.as_str()).collect();
- let block = DataBlock::create_by_array(self.schema.clone(), vec![
+ let block = DataBlock::create_by_array(self.table_info.schema.clone(), vec![
Series::new(names),
Series::new(values),
Series::new(groups),
Series::new(descs),
]);
Ok(Box::pin(DataBlockStream::create(
- self.schema.clone(),
+ self.table_info.schema.clone(),
None,
vec![block],
)))
