Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: changes required for migrate dev to main #1455

Merged
merged 5 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/catalog/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ test = []
async-trait = { workspace = true }
common_types = { workspace = true }
generic_error = { workspace = true }
lazy_static = { workspace = true }
logger = { workspace = true }
macros = { workspace = true }
snafu = { workspace = true }
Expand Down
9 changes: 7 additions & 2 deletions src/catalog/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@

//! Catalog constants

/// Default catalog name
pub const DEFAULT_CATALOG: &str = "horaedb";
use lazy_static::lazy_static;

lazy_static! {
/// Default catalog name
pub static ref DEFAULT_CATALOG: String =
std::env::var("HORAEDB_DEFAULT_CATALOG").unwrap_or_else(|_| "horaedb".to_string());
}
/// Default schema name
pub const DEFAULT_SCHEMA: &str = "public";
/// Catalog name of the sys catalog
Expand Down
4 changes: 2 additions & 2 deletions src/catalog_impls/src/table_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub struct TableBasedManager {

impl Manager for TableBasedManager {
fn default_catalog_name(&self) -> NameRef {
consts::DEFAULT_CATALOG
&consts::DEFAULT_CATALOG
}

fn default_schema_name(&self) -> NameRef {
Expand Down Expand Up @@ -255,7 +255,7 @@ impl TableBasedManager {

async fn maybe_create_default_catalog(&mut self) -> Result<()> {
// Try to get default catalog, create it if not exists.
let catalog = match self.catalogs.get(consts::DEFAULT_CATALOG) {
let catalog = match self.catalogs.get(consts::DEFAULT_CATALOG.as_str()) {
Some(v) => v.clone(),
None => {
// Only system catalog should exists.
Expand Down
8 changes: 6 additions & 2 deletions src/catalog_impls/src/volatile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl ManagerImpl {

impl Manager for ManagerImpl {
fn default_catalog_name(&self) -> NameRef {
consts::DEFAULT_CATALOG
&consts::DEFAULT_CATALOG
}

fn default_schema_name(&self) -> NameRef {
Expand All @@ -96,7 +96,11 @@ impl ManagerImpl {
fn maybe_create_default_catalog(&mut self) {
// TODO: we should delegate this operation to the [TableManager].
// Try to get default catalog, create it if not exists.
if self.catalogs.get(consts::DEFAULT_CATALOG).is_none() {
if self
.catalogs
.get(consts::DEFAULT_CATALOG.as_str())
.is_none()
{
// Default catalog is not exists, create and store it.
self.create_catalog(consts::DEFAULT_CATALOG.to_string());
};
Expand Down
2 changes: 1 addition & 1 deletion src/query_frontend/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ fn ensure_column_default_value_valid<P: MetaProvider>(
// TODO: support catalog/schema
pub fn get_table_ref(table_name: &str) -> TableReference {
TableReference::from(ResolvedTableReference {
catalog: Cow::from(DEFAULT_CATALOG),
catalog: Cow::from(DEFAULT_CATALOG.as_str()),
schema: Cow::from(DEFAULT_SCHEMA),
table: Cow::from(table_name),
})
Expand Down
2 changes: 1 addition & 1 deletion src/query_frontend/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Default for MockMetaProvider {

impl MetaProvider for MockMetaProvider {
fn default_catalog_name(&self) -> &str {
DEFAULT_CATALOG
&DEFAULT_CATALOG
}

fn default_schema_name(&self) -> &str {
Expand Down
10 changes: 5 additions & 5 deletions src/server/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub type SessionRef = Arc<Session>;
impl Session {
pub fn new(addr: Option<SocketAddr>, channel: Channel) -> Self {
Session {
catalog: ArcSwap::new(Arc::new(DEFAULT_CATALOG.into())),
catalog: ArcSwap::new(Arc::new(DEFAULT_CATALOG.clone())),
schema: ArcSwap::new(Arc::new(DEFAULT_SCHEMA.into())),
conn_info: ConnInfo::new(addr, channel),
}
Expand Down Expand Up @@ -166,7 +166,7 @@ pub fn parse_catalog_and_schema_from_db_string(db: &str) -> (&str, &str) {
if parts.len() == 2 {
(parts[0], parts[1])
} else {
(DEFAULT_CATALOG, db)
(&DEFAULT_CATALOG, db)
}
}

Expand All @@ -177,7 +177,7 @@ mod tests {

/// Build db name from catalog and schema string
fn build_db_string(catalog: &str, schema: &str) -> String {
if catalog == DEFAULT_CATALOG {
if catalog == DEFAULT_CATALOG.as_str() {
schema.to_string()
} else {
format!("{catalog}-{schema}")
Expand All @@ -186,14 +186,14 @@ mod tests {

#[test]
fn test_db_string() {
assert_eq!("test", build_db_string(DEFAULT_CATALOG, "test"));
assert_eq!("test", build_db_string(&DEFAULT_CATALOG, "test"));
assert_eq!("a0b1c2d3-test", build_db_string("a0b1c2d3", "test"));
}

#[test]
fn test_parse_catalog_and_schema() {
assert_eq!(
(DEFAULT_CATALOG, "fullschema"),
(DEFAULT_CATALOG.as_str(), "fullschema"),
parse_catalog_and_schema_from_db_string("fullschema")
);

Expand Down
Loading