From 56fc5aa95380fec6ed6ae8ed9cc57db89bcacb4c Mon Sep 17 00:00:00 2001 From: caicancai <2356672992@qq.com> Date: Wed, 15 Nov 2023 14:56:05 +0800 Subject: [PATCH 1/3] chore/catalog: add root test and fix doc Signed-off-by: caicancai <2356672992@qq.com> --- docs/03-architecture-overview.md | 4 +++- src/catalog/root.rs | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/03-architecture-overview.md b/docs/03-architecture-overview.md index b0ca9a0eb..2461c810e 100644 --- a/docs/03-architecture-overview.md +++ b/docs/03-architecture-overview.md @@ -20,7 +20,9 @@ After that, the table will be created, and the table information will be stored ```plain > \dt -| 0 | postgres | 0 | postgres | 18 | t | +| 0 | postgres | 0 | users | +| 0 | postgres | 4 | t | +| 1 | pg_catalog | 0 | contributors | ``` ## Parser diff --git a/src/catalog/root.rs b/src/catalog/root.rs index 093b0142e..a66e9fc3a 100644 --- a/src/catalog/root.rs +++ b/src/catalog/root.rs @@ -143,3 +143,28 @@ fn split_name(name: &str) -> Option<(&str, &str)> { _ => None, } } + +#[cfg(test)] +mod tests { + use std::sync::Arc; + + use super::*; + + #[test] + fn test_root_catalog() { + let catalog = Arc::new(RootCatalog::new()); + let schema_catalog1 = catalog.get_schema_by_id(0).unwrap(); + assert_eq!(schema_catalog1.id(), 0); + assert_eq!(schema_catalog1.name(), DEFAULT_SCHEMA_NAME); + + let schema_catalog2 = catalog.get_schema_by_name(DEFAULT_SCHEMA_NAME).unwrap(); + assert_eq!(schema_catalog2.id(), 0); + assert_eq!(schema_catalog2.name(), DEFAULT_SCHEMA_NAME); + + let col = ColumnCatalog::new(0, DataTypeKind::Int32.not_null().to_column("a".into())); + let table_id = catalog + .add_table(0, "t".into(), vec![col], false, vec![]) + .unwrap(); + assert_eq!(table_id, 0); + } +} From c95df5250eabed7a5322bb2a0af183114de268a5 Mon Sep 17 00:00:00 2001 From: caicancai <2356672992@qq.com> Date: Wed, 15 Nov 2023 15:00:48 +0800 Subject: [PATCH 2/3] chore/catalog: add root test and fix doc Signed-off-by: caicancai <2356672992@qq.com> --- docs/03-architecture-overview.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/03-architecture-overview.md b/docs/03-architecture-overview.md index 2461c810e..2549067e9 100644 --- a/docs/03-architecture-overview.md +++ b/docs/03-architecture-overview.md @@ -21,7 +21,7 @@ After that, the table will be created, and the table information will be stored ```plain > \dt | 0 | postgres | 0 | users | -| 0 | postgres | 4 | t | +| 0 | postgres | 1 | t | | 1 | pg_catalog | 0 | contributors | ``` From 3ff23b2641b8111a6a98a1631a92d5d2266c303b Mon Sep 17 00:00:00 2001 From: caicancai <2356672992@qq.com> Date: Wed, 15 Nov 2023 15:25:22 +0800 Subject: [PATCH 3/3] chore/catalog: add root test and fix doc Signed-off-by: caicancai <2356672992@qq.com> --- src/catalog/root.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/catalog/root.rs b/src/catalog/root.rs index a66e9fc3a..94d1539fc 100644 --- a/src/catalog/root.rs +++ b/src/catalog/root.rs @@ -158,8 +158,8 @@ mod tests { assert_eq!(schema_catalog1.name(), DEFAULT_SCHEMA_NAME); let schema_catalog2 = catalog.get_schema_by_name(DEFAULT_SCHEMA_NAME).unwrap(); - assert_eq!(schema_catalog2.id(), 0); - assert_eq!(schema_catalog2.name(), DEFAULT_SCHEMA_NAME); + assert_eq!(schema_catalog1.id(), schema_catalog2.id()); + assert_eq!(schema_catalog1.name(), schema_catalog2.name()); let col = ColumnCatalog::new(0, DataTypeKind::Int32.not_null().to_column("a".into())); let table_id = catalog