Skip to content

Commit

Permalink
Merge remote-tracking branch 'up/main' into session
Browse files Browse the repository at this point in the history
  • Loading branch information
youngsofun committed Aug 21, 2024
2 parents 9d860de + 6d1a7ee commit 847e767
Show file tree
Hide file tree
Showing 28 changed files with 1,178 additions and 6 deletions.
5 changes: 5 additions & 0 deletions src/common/exception/src/exception_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,11 @@ build_exceptions! {
// dictionary
DictionaryAlreadyExists(3113),
UnknownDictionary(3114),
UnknownDictionaryId(3115),
UnsupportedDictionaryOption(3116),
UnsupportedDictionarySource(3117),
MissingDictionaryOption(3118),
WrongDictionaryFieldExpr(3119),
}

// Storage errors [3001, 4000].
Expand Down
2 changes: 1 addition & 1 deletion src/meta/app/src/app_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1749,7 +1749,7 @@ impl AppErrorMessage for SequenceError {
// dictionary
impl AppErrorMessage for DictionaryAlreadyExists {
fn message(&self) -> String {
format!("dictionary '{}' already exists", self.dictionary_name)
format!("Dictionary '{}' already exists", self.dictionary_name)
}
}

Expand Down
59 changes: 59 additions & 0 deletions src/query/catalog/src/catalog/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,14 @@ use std::sync::Arc;
use databend_common_config::InnerConfig;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;
use databend_common_meta_app::schema::tenant_dictionary_ident::TenantDictionaryIdent;
use databend_common_meta_app::schema::CatalogInfo;
use databend_common_meta_app::schema::CommitTableMetaReply;
use databend_common_meta_app::schema::CommitTableMetaReq;
use databend_common_meta_app::schema::CreateDatabaseReply;
use databend_common_meta_app::schema::CreateDatabaseReq;
use databend_common_meta_app::schema::CreateDictionaryReply;
use databend_common_meta_app::schema::CreateDictionaryReq;
use databend_common_meta_app::schema::CreateIndexReply;
use databend_common_meta_app::schema::CreateIndexReq;
use databend_common_meta_app::schema::CreateLockRevReply;
Expand All @@ -37,6 +40,8 @@ use databend_common_meta_app::schema::CreateTableReq;
use databend_common_meta_app::schema::CreateVirtualColumnReply;
use databend_common_meta_app::schema::CreateVirtualColumnReq;
use databend_common_meta_app::schema::DeleteLockRevReq;
use databend_common_meta_app::schema::DictionaryIdentity;
use databend_common_meta_app::schema::DictionaryMeta;
use databend_common_meta_app::schema::DropDatabaseReply;
use databend_common_meta_app::schema::DropDatabaseReq;
use databend_common_meta_app::schema::DropIndexReply;
Expand All @@ -53,6 +58,7 @@ use databend_common_meta_app::schema::DroppedId;
use databend_common_meta_app::schema::ExtendLockRevReq;
use databend_common_meta_app::schema::GcDroppedTableReq;
use databend_common_meta_app::schema::GcDroppedTableResp;
use databend_common_meta_app::schema::GetDictionaryReply;
use databend_common_meta_app::schema::GetIndexReply;
use databend_common_meta_app::schema::GetIndexReq;
use databend_common_meta_app::schema::GetSequenceNextValueReply;
Expand All @@ -62,6 +68,7 @@ use databend_common_meta_app::schema::GetSequenceReq;
use databend_common_meta_app::schema::GetTableCopiedFileReply;
use databend_common_meta_app::schema::GetTableCopiedFileReq;
use databend_common_meta_app::schema::IndexMeta;
use databend_common_meta_app::schema::ListDictionaryReq;
use databend_common_meta_app::schema::ListDroppedTableReq;
use databend_common_meta_app::schema::ListIndexesByIdReq;
use databend_common_meta_app::schema::ListIndexesReq;
Expand All @@ -85,6 +92,8 @@ use databend_common_meta_app::schema::UndropDatabaseReq;
use databend_common_meta_app::schema::UndropTableByIdReq;
use databend_common_meta_app::schema::UndropTableReply;
use databend_common_meta_app::schema::UndropTableReq;
use databend_common_meta_app::schema::UpdateDictionaryReply;
use databend_common_meta_app::schema::UpdateDictionaryReq;
use databend_common_meta_app::schema::UpdateIndexReply;
use databend_common_meta_app::schema::UpdateIndexReq;
use databend_common_meta_app::schema::UpdateMultiTableMetaReq;
Expand Down Expand Up @@ -296,6 +305,36 @@ pub trait Catalog: DynClone + Send + Sync + Debug {
}
}

// Check a db.dictionary is exists or not.
#[async_backtrace::framed]
async fn exists_dictionary(
&self,
tenant: &Tenant,
db_name: &str,
dict_name: &str,
) -> Result<bool> {
let db_id = self
.get_database(tenant, db_name)
.await?
.get_db_info()
.database_id
.db_id;
let req = TenantDictionaryIdent::new(
tenant,
DictionaryIdentity::new(db_id, dict_name.to_string()),
);
match self.get_dictionary(req).await {
Ok(_) => Ok(true),
Err(err) => {
if err.code() == ErrorCode::UNKNOWN_DICTIONARY {
Ok(false)
} else {
Err(err)
}
}
}
}

async fn upsert_table_option(
&self,
tenant: &Tenant,
Expand Down Expand Up @@ -433,4 +472,24 @@ pub trait Catalog: DynClone + Send + Sync + Debug {
) -> Result<GetSequenceNextValueReply>;

async fn drop_sequence(&self, req: DropSequenceReq) -> Result<DropSequenceReply>;

/// Dictionary
async fn create_dictionary(&self, req: CreateDictionaryReq) -> Result<CreateDictionaryReply>;

async fn update_dictionary(&self, req: UpdateDictionaryReq) -> Result<UpdateDictionaryReply>;

async fn drop_dictionary(
&self,
dict_ident: TenantDictionaryIdent,
) -> Result<Option<SeqV<DictionaryMeta>>>;

async fn get_dictionary(
&self,
req: TenantDictionaryIdent,
) -> Result<Option<GetDictionaryReply>>;

async fn list_dictionaries(
&self,
req: ListDictionaryReq,
) -> Result<Vec<(String, DictionaryMeta)>>;
}
38 changes: 38 additions & 0 deletions src/query/catalog/src/catalog/session_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ use std::fmt::Debug;
use std::sync::Arc;

use databend_common_exception::Result;
use databend_common_meta_app::schema::tenant_dictionary_ident::TenantDictionaryIdent;
use databend_common_meta_app::schema::CatalogInfo;
use databend_common_meta_app::schema::CommitTableMetaReply;
use databend_common_meta_app::schema::CommitTableMetaReq;
use databend_common_meta_app::schema::CreateDatabaseReply;
use databend_common_meta_app::schema::CreateDatabaseReq;
use databend_common_meta_app::schema::CreateDictionaryReply;
use databend_common_meta_app::schema::CreateDictionaryReq;
use databend_common_meta_app::schema::CreateIndexReply;
use databend_common_meta_app::schema::CreateIndexReq;
use databend_common_meta_app::schema::CreateLockRevReply;
Expand All @@ -35,6 +38,7 @@ use databend_common_meta_app::schema::CreateTableReq;
use databend_common_meta_app::schema::CreateVirtualColumnReply;
use databend_common_meta_app::schema::CreateVirtualColumnReq;
use databend_common_meta_app::schema::DeleteLockRevReq;
use databend_common_meta_app::schema::DictionaryMeta;
use databend_common_meta_app::schema::DropDatabaseReply;
use databend_common_meta_app::schema::DropDatabaseReq;
use databend_common_meta_app::schema::DropIndexReply;
Expand All @@ -51,6 +55,7 @@ use databend_common_meta_app::schema::DroppedId;
use databend_common_meta_app::schema::ExtendLockRevReq;
use databend_common_meta_app::schema::GcDroppedTableReq;
use databend_common_meta_app::schema::GcDroppedTableResp;
use databend_common_meta_app::schema::GetDictionaryReply;
use databend_common_meta_app::schema::GetIndexReply;
use databend_common_meta_app::schema::GetIndexReq;
use databend_common_meta_app::schema::GetSequenceNextValueReply;
Expand All @@ -60,6 +65,7 @@ use databend_common_meta_app::schema::GetSequenceReq;
use databend_common_meta_app::schema::GetTableCopiedFileReply;
use databend_common_meta_app::schema::GetTableCopiedFileReq;
use databend_common_meta_app::schema::IndexMeta;
use databend_common_meta_app::schema::ListDictionaryReq;
use databend_common_meta_app::schema::ListDroppedTableReq;
use databend_common_meta_app::schema::ListIndexesByIdReq;
use databend_common_meta_app::schema::ListIndexesReq;
Expand All @@ -83,6 +89,8 @@ use databend_common_meta_app::schema::UndropDatabaseReq;
use databend_common_meta_app::schema::UndropTableByIdReq;
use databend_common_meta_app::schema::UndropTableReply;
use databend_common_meta_app::schema::UndropTableReq;
use databend_common_meta_app::schema::UpdateDictionaryReply;
use databend_common_meta_app::schema::UpdateDictionaryReq;
use databend_common_meta_app::schema::UpdateIndexReply;
use databend_common_meta_app::schema::UpdateIndexReq;
use databend_common_meta_app::schema::UpdateMultiTableMetaReq;
Expand Down Expand Up @@ -501,4 +509,34 @@ impl Catalog for SessionCatalog {
async fn drop_sequence(&self, req: DropSequenceReq) -> Result<DropSequenceReply> {
self.inner.drop_sequence(req).await
}

/// Dictionary
async fn create_dictionary(&self, req: CreateDictionaryReq) -> Result<CreateDictionaryReply> {
self.inner.create_dictionary(req).await
}

async fn update_dictionary(&self, req: UpdateDictionaryReq) -> Result<UpdateDictionaryReply> {
self.inner.update_dictionary(req).await
}

async fn drop_dictionary(
&self,
dict_ident: TenantDictionaryIdent,
) -> Result<Option<SeqV<DictionaryMeta>>> {
self.inner.drop_dictionary(dict_ident).await
}

async fn get_dictionary(
&self,
req: TenantDictionaryIdent,
) -> Result<Option<GetDictionaryReply>> {
self.inner.get_dictionary(req).await
}

async fn list_dictionaries(
&self,
req: ListDictionaryReq,
) -> Result<Vec<(String, DictionaryMeta)>> {
self.inner.list_dictionaries(req).await
}
}
43 changes: 43 additions & 0 deletions src/query/service/src/catalogs/default/database_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,14 @@ use databend_common_catalog::table_function::TableFunction;
use databend_common_config::InnerConfig;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;
use databend_common_meta_app::schema::tenant_dictionary_ident::TenantDictionaryIdent;
use databend_common_meta_app::schema::CatalogInfo;
use databend_common_meta_app::schema::CommitTableMetaReply;
use databend_common_meta_app::schema::CommitTableMetaReq;
use databend_common_meta_app::schema::CreateDatabaseReply;
use databend_common_meta_app::schema::CreateDatabaseReq;
use databend_common_meta_app::schema::CreateDictionaryReply;
use databend_common_meta_app::schema::CreateDictionaryReq;
use databend_common_meta_app::schema::CreateIndexReply;
use databend_common_meta_app::schema::CreateIndexReq;
use databend_common_meta_app::schema::CreateLockRevReply;
Expand All @@ -43,6 +46,7 @@ use databend_common_meta_app::schema::CreateTableReq;
use databend_common_meta_app::schema::CreateVirtualColumnReply;
use databend_common_meta_app::schema::CreateVirtualColumnReq;
use databend_common_meta_app::schema::DeleteLockRevReq;
use databend_common_meta_app::schema::DictionaryMeta;
use databend_common_meta_app::schema::DropDatabaseReply;
use databend_common_meta_app::schema::DropDatabaseReq;
use databend_common_meta_app::schema::DropIndexReply;
Expand All @@ -59,6 +63,7 @@ use databend_common_meta_app::schema::DroppedId;
use databend_common_meta_app::schema::ExtendLockRevReq;
use databend_common_meta_app::schema::GcDroppedTableReq;
use databend_common_meta_app::schema::GcDroppedTableResp;
use databend_common_meta_app::schema::GetDictionaryReply;
use databend_common_meta_app::schema::GetIndexReply;
use databend_common_meta_app::schema::GetIndexReq;
use databend_common_meta_app::schema::GetSequenceNextValueReply;
Expand All @@ -68,6 +73,7 @@ use databend_common_meta_app::schema::GetSequenceReq;
use databend_common_meta_app::schema::GetTableCopiedFileReply;
use databend_common_meta_app::schema::GetTableCopiedFileReq;
use databend_common_meta_app::schema::IndexMeta;
use databend_common_meta_app::schema::ListDictionaryReq;
use databend_common_meta_app::schema::ListDroppedTableReq;
use databend_common_meta_app::schema::ListIndexesByIdReq;
use databend_common_meta_app::schema::ListIndexesReq;
Expand All @@ -91,6 +97,8 @@ use databend_common_meta_app::schema::UndropDatabaseReq;
use databend_common_meta_app::schema::UndropTableByIdReq;
use databend_common_meta_app::schema::UndropTableReply;
use databend_common_meta_app::schema::UndropTableReq;
use databend_common_meta_app::schema::UpdateDictionaryReply;
use databend_common_meta_app::schema::UpdateDictionaryReq;
use databend_common_meta_app::schema::UpdateIndexReply;
use databend_common_meta_app::schema::UpdateIndexReq;
use databend_common_meta_app::schema::UpdateMultiTableMetaReq;
Expand Down Expand Up @@ -732,4 +740,39 @@ impl Catalog for DatabaseCatalog {
async fn drop_sequence(&self, req: DropSequenceReq) -> Result<DropSequenceReply> {
self.mutable_catalog.drop_sequence(req).await
}

/// Dictionary
#[async_backtrace::framed]
async fn create_dictionary(&self, req: CreateDictionaryReq) -> Result<CreateDictionaryReply> {
self.mutable_catalog.create_dictionary(req).await
}

#[async_backtrace::framed]
async fn update_dictionary(&self, req: UpdateDictionaryReq) -> Result<UpdateDictionaryReply> {
self.mutable_catalog.update_dictionary(req).await
}

#[async_backtrace::framed]
async fn drop_dictionary(
&self,
dict_ident: TenantDictionaryIdent,
) -> Result<Option<SeqV<DictionaryMeta>>> {
self.mutable_catalog.drop_dictionary(dict_ident).await
}

#[async_backtrace::framed]
async fn get_dictionary(
&self,
req: TenantDictionaryIdent,
) -> Result<Option<GetDictionaryReply>> {
self.mutable_catalog.get_dictionary(req).await
}

#[async_backtrace::framed]
async fn list_dictionaries(
&self,
req: ListDictionaryReq,
) -> Result<Vec<(String, DictionaryMeta)>> {
self.mutable_catalog.list_dictionaries(req).await
}
}
43 changes: 43 additions & 0 deletions src/query/service/src/catalogs/default/immutable_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,14 @@ use databend_common_catalog::catalog::Catalog;
use databend_common_config::InnerConfig;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;
use databend_common_meta_app::schema::tenant_dictionary_ident::TenantDictionaryIdent;
use databend_common_meta_app::schema::CatalogInfo;
use databend_common_meta_app::schema::CommitTableMetaReply;
use databend_common_meta_app::schema::CommitTableMetaReq;
use databend_common_meta_app::schema::CreateDatabaseReply;
use databend_common_meta_app::schema::CreateDatabaseReq;
use databend_common_meta_app::schema::CreateDictionaryReply;
use databend_common_meta_app::schema::CreateDictionaryReq;
use databend_common_meta_app::schema::CreateIndexReply;
use databend_common_meta_app::schema::CreateIndexReq;
use databend_common_meta_app::schema::CreateLockRevReply;
Expand All @@ -39,6 +42,7 @@ use databend_common_meta_app::schema::CreateTableReq;
use databend_common_meta_app::schema::CreateVirtualColumnReply;
use databend_common_meta_app::schema::CreateVirtualColumnReq;
use databend_common_meta_app::schema::DeleteLockRevReq;
use databend_common_meta_app::schema::DictionaryMeta;
use databend_common_meta_app::schema::DropDatabaseReply;
use databend_common_meta_app::schema::DropDatabaseReq;
use databend_common_meta_app::schema::DropIndexReply;
Expand All @@ -52,6 +56,7 @@ use databend_common_meta_app::schema::DropTableReply;
use databend_common_meta_app::schema::DropVirtualColumnReply;
use databend_common_meta_app::schema::DropVirtualColumnReq;
use databend_common_meta_app::schema::ExtendLockRevReq;
use databend_common_meta_app::schema::GetDictionaryReply;
use databend_common_meta_app::schema::GetIndexReply;
use databend_common_meta_app::schema::GetIndexReq;
use databend_common_meta_app::schema::GetSequenceNextValueReply;
Expand All @@ -61,6 +66,7 @@ use databend_common_meta_app::schema::GetSequenceReq;
use databend_common_meta_app::schema::GetTableCopiedFileReply;
use databend_common_meta_app::schema::GetTableCopiedFileReq;
use databend_common_meta_app::schema::IndexMeta;
use databend_common_meta_app::schema::ListDictionaryReq;
use databend_common_meta_app::schema::ListIndexesByIdReq;
use databend_common_meta_app::schema::ListIndexesReq;
use databend_common_meta_app::schema::ListLockRevReq;
Expand All @@ -83,6 +89,8 @@ use databend_common_meta_app::schema::UndropDatabaseReq;
use databend_common_meta_app::schema::UndropTableByIdReq;
use databend_common_meta_app::schema::UndropTableReply;
use databend_common_meta_app::schema::UndropTableReq;
use databend_common_meta_app::schema::UpdateDictionaryReply;
use databend_common_meta_app::schema::UpdateDictionaryReq;
use databend_common_meta_app::schema::UpdateIndexReply;
use databend_common_meta_app::schema::UpdateIndexReq;
use databend_common_meta_app::schema::UpdateVirtualColumnReply;
Expand Down Expand Up @@ -511,4 +519,39 @@ impl Catalog for ImmutableCatalog {
async fn drop_sequence(&self, _req: DropSequenceReq) -> Result<DropSequenceReply> {
unimplemented!()
}

/// Dictionary
#[async_backtrace::framed]
async fn create_dictionary(&self, _req: CreateDictionaryReq) -> Result<CreateDictionaryReply> {
unimplemented!()
}

#[async_backtrace::framed]
async fn update_dictionary(&self, _req: UpdateDictionaryReq) -> Result<UpdateDictionaryReply> {
unimplemented!()
}

#[async_backtrace::framed]
async fn drop_dictionary(
&self,
_dict_ident: TenantDictionaryIdent,
) -> Result<Option<SeqV<DictionaryMeta>>> {
unimplemented!()
}

#[async_backtrace::framed]
async fn get_dictionary(
&self,
_req: TenantDictionaryIdent,
) -> Result<Option<GetDictionaryReply>> {
unimplemented!()
}

#[async_backtrace::framed]
async fn list_dictionaries(
&self,
_req: ListDictionaryReq,
) -> Result<Vec<(String, DictionaryMeta)>> {
unimplemented!()
}
}
Loading

0 comments on commit 847e767

Please sign in to comment.