Skip to content

Commit

Permalink
feat: add default schema config (apache#782)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed Mar 28, 2023
1 parent 818b025 commit eb4b0a2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cluster/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use meta_client::meta_impl::MetaClientConfig;
use serde::{Deserialize, Serialize};
use table_engine::ANALYTIC_ENGINE_TYPE;

#[derive(Debug, Clone, Deserialize)]
#[derive(Debug, Clone, Deserialize, Serialize)]
#[serde(default)]
// TODO: move this to table_engine crates
pub struct SchemaConfig {
Expand Down
5 changes: 4 additions & 1 deletion server/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,16 @@ pub struct ServerConfig {
/// used in gRPC
pub auto_create_table: bool,

pub default_schema_config: SchemaConfig,

// Config of route
pub route_cache: router::RouteCacheConfig,
}

impl Default for ServerConfig {
fn default() -> Self {
Self {
bind_addr: String::from("0.0.0.0"),
bind_addr: String::from("127.0.0.1"),
http_port: 5440,
mysql_port: 3307,
grpc_port: 8831,
Expand All @@ -128,6 +130,7 @@ impl Default for ServerConfig {
resp_compress_min_length: ReadableSize::mb(4),
forward: forward::Config::default(),
auto_create_table: true,
default_schema_config: Default::default(),
route_cache: router::RouteCacheConfig::default(),
}
}
Expand Down
14 changes: 11 additions & 3 deletions server/src/schema_config_provider/config_based.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,24 @@ pub type SchemaConfigs = HashMap<String, SchemaConfig>;
#[derive(Debug)]
pub struct ConfigBasedProvider {
schema_configs: SchemaConfigs,
default: SchemaConfig,
}

impl ConfigBasedProvider {
pub fn new(schema_configs: SchemaConfigs) -> Self {
Self { schema_configs }
pub fn new(schema_configs: SchemaConfigs, default: SchemaConfig) -> Self {
Self {
schema_configs,
default,
}
}
}

impl SchemaConfigProvider for ConfigBasedProvider {
fn schema_config(&self, schema_name: &str) -> Result<Option<&SchemaConfig>> {
Ok(self.schema_configs.get(schema_name))
Ok(Some(
self.schema_configs
.get(schema_name)
.unwrap_or(&self.default),
))
}
}
5 changes: 4 additions & 1 deletion src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,10 @@ async fn build_without_meta<Q: Executor + 'static, T: WalsOpener>(
cluster_view,
static_route_config.rules.clone(),
));
let schema_config_provider = Arc::new(ConfigBasedProvider::new(schema_configs));
let schema_config_provider = Arc::new(ConfigBasedProvider::new(
schema_configs,
config.server.default_schema_config.clone(),
));

builder
.table_engine(engine_proxy)
Expand Down

0 comments on commit eb4b0a2

Please sign in to comment.