Skip to content

Commit

Permalink
Catalog1 -> Catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
BohuTANG committed Nov 29, 2021
1 parent ba03a3e commit 1069a60
Show file tree
Hide file tree
Showing 86 changed files with 191 additions and 180 deletions.
2 changes: 1 addition & 1 deletion query/src/api/http/v1/logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use poem::web::Data;
use poem::IntoResponse;
use tokio_stream::StreamExt;

use crate::catalogs1::ToReadDataSourcePlan;
use crate::catalogs::ToReadDataSourcePlan;
use crate::sessions::QueryContext;
use crate::sessions::SessionManager;

Expand Down
File renamed without changes.
File renamed without changes.
52 changes: 30 additions & 22 deletions query/src/catalogs1/catalog.rs → query/src/catalogs/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ use common_meta_types::UpsertTableOptionReply;
use common_meta_types::UpsertTableOptionReq;
use dyn_clone::DynClone;

use crate::catalogs1::Database;
use crate::catalogs1::Table;
use crate::catalogs1::TableFunction;
use crate::catalogs::Database;
use crate::catalogs::Table;
use crate::catalogs::TableFunction;
use crate::table_functions::TableArgs;

/// Catalog is the global view of all the databases of the user.
Expand All @@ -42,6 +42,10 @@ use crate::table_functions::TableArgs;
/// and use the engine to create them.
#[async_trait::async_trait]
pub trait Catalog: DynClone + Send + Sync {
///
/// Database.
///

// Get the database by name.
async fn get_database(&self, db_name: &str) -> Result<Arc<dyn Database>>;

Expand All @@ -66,30 +70,16 @@ pub trait Catalog: DynClone + Send + Sync {
}
}

// Build a `Arc<dyn Table>` from `TableInfo`.
fn build_table(&self, table_info: &TableInfo) -> Result<Arc<dyn Table>>;
///
/// Table.
///

async fn upsert_table_option(
&self,
req: UpsertTableOptionReq,
) -> Result<UpsertTableOptionReply>;

// Get function by name.
fn get_table_function(
&self,
_func_name: &str,
_tbl_args: TableArgs,
) -> Result<Arc<dyn TableFunction>> {
unimplemented!()
}
// Build a `Arc<dyn Table>` from `TableInfo`.
fn get_table_by_info(&self, table_info: &TableInfo) -> Result<Arc<dyn Table>>;

// Get the table meta by meta id.
async fn get_table_meta_by_id(&self, table_id: MetaId) -> Result<(TableIdent, Arc<TableMeta>)>;

async fn init(&self) -> Result<()> {
Ok(())
}

// Get one table by db and table name.
async fn get_table(&self, db_name: &str, table_name: &str) -> Result<Arc<dyn Table>>;

Expand All @@ -112,4 +102,22 @@ pub trait Catalog: DynClone + Send + Sync {
}
}
}

async fn upsert_table_option(
&self,
req: UpsertTableOptionReq,
) -> Result<UpsertTableOptionReply>;

///
/// Table function
///

// Get function by name.
fn get_table_function(
&self,
_func_name: &str,
_tbl_args: TableArgs,
) -> Result<Arc<dyn TableFunction>> {
unimplemented!()
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ use common_meta_types::TableMeta;
use common_meta_types::UpsertTableOptionReply;
use common_meta_types::UpsertTableOptionReq;

use crate::catalogs1::catalog::Catalog;
use crate::catalogs1::impls::ImmutableCatalog;
use crate::catalogs1::impls::MutableCatalog;
use crate::catalogs1::Database;
use crate::catalogs1::Table;
use crate::catalogs1::TableFunction;
use crate::catalogs::catalog::Catalog;
use crate::catalogs::impls::ImmutableCatalog;
use crate::catalogs::impls::MutableCatalog;
use crate::catalogs::Database;
use crate::catalogs::Table;
use crate::catalogs::TableFunction;
use crate::configs::Config;
use crate::table_functions::TableArgs;
use crate::table_functions::TableFunctionFactory;
Expand Down Expand Up @@ -125,36 +125,20 @@ impl Catalog for DatabaseCatalog {
self.mutable_catalog.drop_database(req).await
}

fn build_table(&self, table_info: &TableInfo) -> Result<Arc<dyn Table>> {
let res = self.immutable_catalog.build_table(table_info);
fn get_table_by_info(&self, table_info: &TableInfo) -> Result<Arc<dyn Table>> {
let res = self.immutable_catalog.get_table_by_info(table_info);
match res {
Ok(t) => Ok(t),
Err(e) => {
if e.code() == ErrorCode::UnknownTable("").code() {
self.mutable_catalog.build_table(table_info)
self.mutable_catalog.get_table_by_info(table_info)
} else {
Err(e)
}
}
}
}

async fn upsert_table_option(
&self,
req: UpsertTableOptionReq,
) -> Result<UpsertTableOptionReply> {
// upsert table option in BOTTOM layer only
self.mutable_catalog.upsert_table_option(req).await
}

fn get_table_function(
&self,
func_name: &str,
tbl_args: TableArgs,
) -> Result<Arc<dyn TableFunction>> {
self.table_function_factory.get(func_name, tbl_args)
}

async fn get_table_meta_by_id(&self, table_id: MetaId) -> Result<(TableIdent, Arc<TableMeta>)> {
let res = self.immutable_catalog.get_table_meta_by_id(table_id).await;

Expand Down Expand Up @@ -210,4 +194,20 @@ impl Catalog for DatabaseCatalog {
Ok(x) => Ok(x),
}
}

async fn upsert_table_option(
&self,
req: UpsertTableOptionReq,
) -> Result<UpsertTableOptionReply> {
// upsert table option in BOTTOM layer only
self.mutable_catalog.upsert_table_option(req).await
}

fn get_table_function(
&self,
func_name: &str,
tbl_args: TableArgs,
) -> Result<Arc<dyn TableFunction>> {
self.table_function_factory.get(func_name, tbl_args)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ use common_meta_types::TableMeta;
use common_meta_types::UpsertTableOptionReply;
use common_meta_types::UpsertTableOptionReq;

use crate::catalogs1::catalog::Catalog;
use crate::catalogs1::Database;
use crate::catalogs1::InMemoryMetas;
use crate::catalogs1::Table;
use crate::catalogs1::SYS_TBL_ID_BEGIN;
use crate::catalogs::catalog::Catalog;
use crate::catalogs::Database;
use crate::catalogs::InMemoryMetas;
use crate::catalogs::Table;
use crate::catalogs::SYS_TBL_ID_BEGIN;
use crate::configs::Config;
use crate::storages::SystemDatabase;

Expand Down Expand Up @@ -86,7 +86,7 @@ impl Catalog for ImmutableCatalog {
Err(ErrorCode::UnImplement("Cannot drop system database"))
}

fn build_table(&self, table_info: &TableInfo) -> Result<Arc<dyn Table>> {
fn get_table_by_info(&self, table_info: &TableInfo) -> Result<Arc<dyn Table>> {
let table_id = table_info.ident.table_id;

let table = self
Expand All @@ -96,16 +96,6 @@ impl Catalog for ImmutableCatalog {
Ok(table.clone())
}

async fn upsert_table_option(
&self,
req: UpsertTableOptionReq,
) -> Result<UpsertTableOptionReply> {
Err(ErrorCode::UnImplement(format!(
"Commit table not allowed for system database {:?}",
req
)))
}

async fn get_table_meta_by_id(&self, table_id: MetaId) -> Result<(TableIdent, Arc<TableMeta>)> {
let table = self
.sys_db_meta
Expand Down Expand Up @@ -151,4 +141,14 @@ impl Catalog for ImmutableCatalog {
table_name
)));
}

async fn upsert_table_option(
&self,
req: UpsertTableOptionReq,
) -> Result<UpsertTableOptionReply> {
Err(ErrorCode::UnImplement(format!(
"Commit table not allowed for system database {:?}",
req
)))
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ use common_meta_types::UpsertTableOptionReply;
use common_meta_types::UpsertTableOptionReq;
use common_tracing::tracing;

use crate::catalogs1::backends::MetaRemote;
use crate::catalogs1::catalog::Catalog;
use crate::catalogs1::database::Database;
use crate::catalogs1::CatalogContext;
use crate::catalogs1::DefaultDatabase;
use crate::catalogs1::Table;
use crate::catalogs::backends::MetaRemote;
use crate::catalogs::catalog::Catalog;
use crate::catalogs::database::Database;
use crate::catalogs::CatalogContext;
use crate::catalogs::DefaultDatabase;
use crate::catalogs::Table;
use crate::common::MetaClientProvider;
use crate::configs::Config;
use crate::storages::StorageContext;
Expand Down Expand Up @@ -145,7 +145,7 @@ impl Catalog for MutableCatalog {
Ok(())
}

fn build_table(&self, table_info: &TableInfo) -> Result<Arc<dyn Table>> {
fn get_table_by_info(&self, table_info: &TableInfo) -> Result<Arc<dyn Table>> {
let storage = self.ctx.storage_factory.clone();
let ctx = StorageContext {
meta: self.ctx.meta.clone(),
Expand All @@ -154,13 +154,6 @@ impl Catalog for MutableCatalog {
storage.get_table(ctx, table_info)
}

async fn upsert_table_option(
&self,
req: UpsertTableOptionReq,
) -> Result<UpsertTableOptionReply> {
self.ctx.meta.upsert_table_option(req).await
}

async fn get_table_meta_by_id(
&self,
table_id: MetaId,
Expand All @@ -174,7 +167,7 @@ impl Catalog for MutableCatalog {
.meta
.get_table(GetTableReq::new(db_name, table_name))
.await?;
self.build_table(table_info.as_ref())
self.get_table_by_info(table_info.as_ref())
}

async fn list_tables(&self, db_name: &str) -> Result<Vec<Arc<dyn Table>>> {
Expand All @@ -185,7 +178,7 @@ impl Catalog for MutableCatalog {
.await?;

table_infos.iter().try_fold(vec![], |mut acc, item| {
let tbl = self.build_table(item.as_ref())?;
let tbl = self.get_table_by_info(item.as_ref())?;
acc.push(tbl);
Ok(acc)
})
Expand All @@ -199,4 +192,11 @@ impl Catalog for MutableCatalog {
async fn drop_table(&self, req: DropTableReq) -> Result<DropTableReply> {
self.ctx.meta.drop_table(req).await
}

async fn upsert_table_option(
&self,
req: UpsertTableOptionReq,
) -> Result<UpsertTableOptionReply> {
self.ctx.meta.upsert_table_option(req).await
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use std::sync::Arc;

use crate::catalogs1::Table;
use crate::catalogs::Table;

pub trait TableFunction: Sync + Send + Table {
fn function_name(&self) -> &str;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use common_exception::Result;
use common_infallible::RwLock;
use common_meta_types::MetaId;

use crate::catalogs1::Table;
use crate::catalogs::Table;

pub struct InMemoryMetas {
next_id: AtomicU64,
Expand Down
2 changes: 1 addition & 1 deletion query/src/interpreters/interpreter_database_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use common_streams::DataBlockStream;
use common_streams::SendableDataBlockStream;
use common_tracing::tracing;

use crate::catalogs1::Catalog;
use crate::catalogs::Catalog;
use crate::interpreters::Interpreter;
use crate::interpreters::InterpreterPtr;
use crate::sessions::QueryContext;
Expand Down
2 changes: 1 addition & 1 deletion query/src/interpreters/interpreter_database_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use common_planners::DropDatabasePlan;
use common_streams::DataBlockStream;
use common_streams::SendableDataBlockStream;

use crate::catalogs1::Catalog;
use crate::catalogs::Catalog;
use crate::interpreters::Interpreter;
use crate::interpreters::InterpreterPtr;
use crate::sessions::QueryContext;
Expand Down
2 changes: 1 addition & 1 deletion query/src/interpreters/interpreter_grant_privilege.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use common_streams::DataBlockStream;
use common_streams::SendableDataBlockStream;
use common_tracing::tracing;

use crate::catalogs1::Catalog;
use crate::catalogs::Catalog;
use crate::interpreters::Interpreter;
use crate::interpreters::InterpreterPtr;
use crate::sessions::QueryContext;
Expand Down
2 changes: 1 addition & 1 deletion query/src/interpreters/interpreter_insert_into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use common_streams::ProgressStream;
use common_streams::SendableDataBlockStream;
use futures::TryStreamExt;

use crate::catalogs1::Table;
use crate::catalogs::Table;
use crate::interpreters::plan_scheduler_ext;
use crate::interpreters::utils::apply_plan_rewrite;
use crate::interpreters::Interpreter;
Expand Down
2 changes: 1 addition & 1 deletion query/src/interpreters/interpreter_show_create_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use common_streams::DataBlockStream;
use common_streams::SendableDataBlockStream;
use log::debug;

use crate::catalogs1::Catalog;
use crate::catalogs::Catalog;
use crate::interpreters::Interpreter;
use crate::interpreters::InterpreterPtr;
use crate::sessions::QueryContext;
Expand Down
2 changes: 1 addition & 1 deletion query/src/interpreters/interpreter_table_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use common_planners::CreateTablePlan;
use common_streams::DataBlockStream;
use common_streams::SendableDataBlockStream;

use crate::catalogs1::Catalog;
use crate::catalogs::Catalog;
use crate::interpreters::Interpreter;
use crate::interpreters::InterpreterPtr;
use crate::sessions::QueryContext;
Expand Down
2 changes: 1 addition & 1 deletion query/src/interpreters/interpreter_table_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use common_planners::DropTablePlan;
use common_streams::DataBlockStream;
use common_streams::SendableDataBlockStream;

use crate::catalogs1::Catalog;
use crate::catalogs::Catalog;
use crate::interpreters::Interpreter;
use crate::interpreters::InterpreterPtr;
use crate::sessions::QueryContext;
Expand Down
2 changes: 1 addition & 1 deletion query/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pub mod tests;

pub mod api;
pub mod catalogs1;
pub mod catalogs;
pub mod clusters;
pub mod common;
pub mod configs;
Expand Down
Loading

0 comments on commit 1069a60

Please sign in to comment.