Skip to content

Commit

Permalink
feat: add a default internal schema (#2974)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunng87 authored Dec 22, 2023
1 parent 675767c commit 43f01cc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 5 deletions.
10 changes: 9 additions & 1 deletion src/catalog/src/memory/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use std::collections::HashMap;
use std::sync::{Arc, RwLock, Weak};

use common_catalog::build_db_string;
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME, INFORMATION_SCHEMA_NAME};
use common_catalog::consts::{
DEFAULT_CATALOG_NAME, DEFAULT_PRIVATE_SCHEMA_NAME, DEFAULT_SCHEMA_NAME, INFORMATION_SCHEMA_NAME,
};
use snafu::OptionExt;
use table::TableRef;

Expand Down Expand Up @@ -135,6 +137,12 @@ impl MemoryCatalogManager {
schema: DEFAULT_SCHEMA_NAME.to_string(),
})
.unwrap();
manager
.register_schema_sync(RegisterSchemaRequest {
catalog: DEFAULT_CATALOG_NAME.to_string(),
schema: DEFAULT_PRIVATE_SCHEMA_NAME.to_string(),
})
.unwrap();

manager
}
Expand Down
1 change: 1 addition & 0 deletions src/common/catalog/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub const INFORMATION_SCHEMA_NAME: &str = "information_schema";
pub const SYSTEM_CATALOG_TABLE_NAME: &str = "system_catalog";
pub const DEFAULT_CATALOG_NAME: &str = "greptime";
pub const DEFAULT_SCHEMA_NAME: &str = "public";
pub const DEFAULT_PRIVATE_SCHEMA_NAME: &str = "greptime_private";

/// Reserves [0,MIN_USER_TABLE_ID) for internal usage.
/// User defined table id starts from this value.
Expand Down
13 changes: 10 additions & 3 deletions src/common/meta/src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ use std::ops::Deref;
use std::sync::Arc;

use bytes::Bytes;
use common_catalog::consts::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME};
use common_catalog::consts::{
DEFAULT_CATALOG_NAME, DEFAULT_PRIVATE_SCHEMA_NAME, DEFAULT_SCHEMA_NAME,
};
use common_telemetry::warn;
use datanode_table::{DatanodeTableKey, DatanodeTableManager, DatanodeTableValue};
use lazy_static::lazy_static;
Expand Down Expand Up @@ -295,11 +297,16 @@ impl TableMetadataManager {

pub async fn init(&self) -> Result<()> {
let catalog_name = CatalogNameKey::new(DEFAULT_CATALOG_NAME);
let schema_name = SchemaNameKey::new(DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME);
let public_schema_name = SchemaNameKey::new(DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME);
let private_schema_name =
SchemaNameKey::new(DEFAULT_CATALOG_NAME, DEFAULT_PRIVATE_SCHEMA_NAME);

self.catalog_manager().create(catalog_name, true).await?;
self.schema_manager()
.create(schema_name, None, true)
.create(public_schema_name, None, true)
.await?;
self.schema_manager()
.create(private_schema_name, None, true)
.await?;

Ok(())
Expand Down
3 changes: 2 additions & 1 deletion tests-integration/src/tests/instance_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,11 +444,12 @@ async fn test_execute_show_databases_tables(instance: Arc<dyn MockInstance>) {
Output::RecordBatches(databases) => {
let databases = databases.take();
assert_eq!(1, databases[0].num_columns());
assert_eq!(databases[0].column(0).len(), 2);
assert_eq!(databases[0].column(0).len(), 3);

assert_eq!(
*databases[0].column(0),
Arc::new(StringVector::from(vec![
Some("greptime_private"),
Some("information_schema"),
Some("public")
])) as VectorRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ show databases;
+--------------------+
| Schemas |
+--------------------+
| greptime_private |
| illegal-database |
| information_schema |
| public |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ show databases;
+-----------------------+
| Schemas |
+-----------------------+
| greptime_private |
| illegal-database |
| information_schema |
| public |
Expand Down

0 comments on commit 43f01cc

Please sign in to comment.