diff --git a/Cargo.lock b/Cargo.lock index 7b076d9273..130eaaeb61 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2033,6 +2033,9 @@ dependencies = [ [[package]] name = "common-catalog" version = "0.18.0" +dependencies = [ + "const_format", +] [[package]] name = "common-config" diff --git a/Cargo.toml b/Cargo.toml index e51b0d7632..3ce3ff48dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -121,6 +121,7 @@ chrono = { version = "0.4", features = ["serde"] } chrono-tz = "0.10.1" clap = { version = "4.4", features = ["derive"] } config = "0.13.0" +const_format = "0.2" crossbeam-utils = "0.8" dashmap = "6.1" datafusion = "50" diff --git a/src/cli/src/data.rs b/src/cli/src/data.rs index bac7f3e308..86d2b43a98 100644 --- a/src/cli/src/data.rs +++ b/src/cli/src/data.rs @@ -16,6 +16,7 @@ mod export; mod import; use clap::Subcommand; +use client::DEFAULT_CATALOG_NAME; use common_error::ext::BoxedError; use crate::Tool; @@ -37,3 +38,7 @@ impl DataCommand { } } } + +pub(crate) fn default_database() -> String { + format!("{DEFAULT_CATALOG_NAME}-*") +} diff --git a/src/cli/src/data/export.rs b/src/cli/src/data/export.rs index a9f68bf9c9..33ce5a7746 100644 --- a/src/cli/src/data/export.rs +++ b/src/cli/src/data/export.rs @@ -30,6 +30,7 @@ use snafu::{OptionExt, ResultExt}; use tokio::sync::Semaphore; use tokio::time::Instant; +use crate::data::default_database; use crate::database::{DatabaseClient, parse_proxy_opts}; use crate::error::{ EmptyResultSnafu, Error, OpenDalSnafu, OutputDirNotSetSnafu, Result, S3ConfigNotSetSnafu, @@ -63,7 +64,7 @@ pub struct ExportCommand { output_dir: Option, /// The name of the catalog to export. - #[clap(long, default_value = "greptime-*")] + #[clap(long, default_value_t = default_database())] database: String, /// Parallelism of the export. diff --git a/src/cli/src/data/import.rs b/src/cli/src/data/import.rs index 102de8ac91..db2fd42e37 100644 --- a/src/cli/src/data/import.rs +++ b/src/cli/src/data/import.rs @@ -25,6 +25,7 @@ use snafu::{OptionExt, ResultExt}; use tokio::sync::Semaphore; use tokio::time::Instant; +use crate::data::default_database; use crate::database::{DatabaseClient, parse_proxy_opts}; use crate::error::{Error, FileIoSnafu, Result, SchemaNotFoundSnafu}; use crate::{Tool, database}; @@ -52,7 +53,7 @@ pub struct ImportCommand { input_dir: String, /// The name of the catalog to import. - #[clap(long, default_value = "greptime-*")] + #[clap(long, default_value_t = default_database())] database: String, /// Parallelism of the import. diff --git a/src/common/catalog/Cargo.toml b/src/common/catalog/Cargo.toml index 051675fe93..357f180a33 100644 --- a/src/common/catalog/Cargo.toml +++ b/src/common/catalog/Cargo.toml @@ -8,5 +8,6 @@ license.workspace = true workspace = true [dependencies] +const_format.workspace = true [dev-dependencies] diff --git a/src/common/catalog/build.rs b/src/common/catalog/build.rs new file mode 100644 index 0000000000..311d6eef3f --- /dev/null +++ b/src/common/catalog/build.rs @@ -0,0 +1,27 @@ +// Copyright 2023 Greptime Team +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +fn main() { + // Set DEFAULT_CATALOG_NAME from environment variable or use default value + let default_catalog_name = + std::env::var("DEFAULT_CATALOG_NAME").unwrap_or_else(|_| "greptime".to_string()); + + println!( + "cargo:rustc-env=DEFAULT_CATALOG_NAME={}", + default_catalog_name + ); + + // Rerun build script if the environment variable changes + println!("cargo:rerun-if-env-changed=DEFAULT_CATALOG_NAME"); +} diff --git a/src/common/catalog/src/consts.rs b/src/common/catalog/src/consts.rs index 7dd6da9b4f..8a59a15cc6 100644 --- a/src/common/catalog/src/consts.rs +++ b/src/common/catalog/src/consts.rs @@ -12,13 +12,15 @@ // See the License for the specific language governing permissions and // limitations under the License. +use const_format::concatcp; + pub const SYSTEM_CATALOG_NAME: &str = "system"; pub const INFORMATION_SCHEMA_NAME: &str = "information_schema"; pub const PG_CATALOG_NAME: &str = "pg_catalog"; pub const SYSTEM_CATALOG_TABLE_NAME: &str = "system_catalog"; -pub const DEFAULT_CATALOG_NAME: &str = "greptime"; +pub const DEFAULT_CATALOG_NAME: &str = env!("DEFAULT_CATALOG_NAME"); pub const DEFAULT_SCHEMA_NAME: &str = "public"; -pub const DEFAULT_PRIVATE_SCHEMA_NAME: &str = "greptime_private"; +pub const DEFAULT_PRIVATE_SCHEMA_NAME: &str = concatcp!(DEFAULT_CATALOG_NAME, "_private"); /// Reserves [0,MIN_USER_FLOW_ID) for internal usage. /// User defined table id starts from this value. diff --git a/src/common/function/src/system/pg_catalog.rs b/src/common/function/src/system/pg_catalog.rs index 4ea378b53a..07e7d2abaf 100644 --- a/src/common/function/src/system/pg_catalog.rs +++ b/src/common/function/src/system/pg_catalog.rs @@ -16,6 +16,9 @@ mod version; use std::sync::Arc; +use common_catalog::consts::{ + DEFAULT_PRIVATE_SCHEMA_NAME, INFORMATION_SCHEMA_NAME, PG_CATALOG_NAME, +}; use datafusion::arrow::array::{ArrayRef, StringArray, as_boolean_array}; use datafusion::catalog::TableFunction; use datafusion::common::ScalarValue; @@ -143,9 +146,9 @@ impl Function for CurrentSchemasFunction { let mut values = vec!["public"]; // include implicit schemas if input.value(0) { - values.push("information_schema"); - values.push("pg_catalog"); - values.push("greptime_private"); + values.push(INFORMATION_SCHEMA_NAME); + values.push(PG_CATALOG_NAME); + values.push(DEFAULT_PRIVATE_SCHEMA_NAME); } let list_array = SingleRowListArrayBuilder::new(Arc::new(StringArray::from(values))); diff --git a/src/common/version/Cargo.toml b/src/common/version/Cargo.toml index 3a8a2a511e..adee41afd7 100644 --- a/src/common/version/Cargo.toml +++ b/src/common/version/Cargo.toml @@ -11,7 +11,7 @@ workspace = true codec = ["dep:serde"] [dependencies] -const_format = "0.2" +const_format.workspace = true serde = { workspace = true, optional = true } shadow-rs = { version = "1.2.1", default-features = false } diff --git a/src/flow/src/adapter/refill.rs b/src/flow/src/adapter/refill.rs index 89b7344c0c..6d66505e89 100644 --- a/src/flow/src/adapter/refill.rs +++ b/src/flow/src/adapter/refill.rs @@ -18,6 +18,7 @@ use std::collections::BTreeSet; use std::sync::Arc; use catalog::CatalogManagerRef; +use client::{DEFAULT_CATALOG_NAME, DEFAULT_SCHEMA_NAME}; use common_error::ext::BoxedError; use common_meta::key::flow::FlowMetadataManagerRef; use common_recordbatch::{RecordBatch, RecordBatches, SendableRecordBatchStream}; @@ -396,8 +397,8 @@ impl RefillTask { // we don't need information from query context in this query so a default query context is enough let query_ctx = Arc::new( QueryContextBuilder::default() - .current_catalog("greptime".to_string()) - .current_schema("public".to_string()) + .current_catalog(DEFAULT_CATALOG_NAME.to_string()) + .current_schema(DEFAULT_SCHEMA_NAME.to_string()) .build(), );