Skip to content

Commit

Permalink
Merge branch 'main' of github.com:datafuselabs/databend into improve_…
Browse files Browse the repository at this point in the history
…filter_execution
  • Loading branch information
Dousir9 committed Dec 20, 2023
2 parents 87dfb6e + 923f589 commit f612bfb
Show file tree
Hide file tree
Showing 103 changed files with 3,667 additions and 495 deletions.
42 changes: 42 additions & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ Databend thrives on community contributions! Whether it's through ideas, code, o

Here are some resources to help you get started:

- [Building Databend From Source](https://docs.databend.com/doc/contributing/building-from-source)
- [The First Good Pull Request](https://docs.databend.com/doc/contributing/good-pr)
- [Building Databend From Source](https://docs.databend.com/doc/overview/community/contributor/building-from-source)
- [The First Good Pull Request](https://docs.databend.com/doc/overview/community/contributor/good-pr)


## 👥 Community
Expand Down
5 changes: 5 additions & 0 deletions src/common/exception/src/exception_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,11 @@ build_exceptions! {
NetworkPolicyAlreadyExists(2208),
IllegalNetworkPolicy(2209),
NetworkPolicyIsUsedByUser(2210),
UnknownPasswordPolicy(2211),
PasswordPolicyAlreadyExists(2212),
IllegalPasswordPolicy(2213),
PasswordPolicyIsUsedByUser(2214),
InvalidPassword(2215),

// Meta api error codes.
DatabaseAlreadyExists(2301),
Expand Down
39 changes: 29 additions & 10 deletions src/meta/api/src/schema_api_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1402,15 +1402,19 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
get_pb_value(self, &req.name_ident).await?;

if old_virtual_column_opt.is_some() {
return Err(KVAppError::AppError(AppError::VirtualColumnAlreadyExists(
VirtualColumnAlreadyExists::new(
req.name_ident.table_id,
format!(
"create virtual column with tenant: {} table_id: {}",
req.name_ident.tenant, req.name_ident.table_id
if req.if_not_exists {
return Ok(CreateVirtualColumnReply {});
} else {
return Err(KVAppError::AppError(AppError::VirtualColumnAlreadyExists(
VirtualColumnAlreadyExists::new(
req.name_ident.table_id,
format!(
"create virtual column with tenant: {} table_id: {}",
req.name_ident.tenant, req.name_ident.table_id
),
),
),
)));
)));
}
}
let virtual_column_meta = VirtualColumnMeta {
table_id: req.name_ident.table_id,
Expand Down Expand Up @@ -1464,7 +1468,16 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
trials.next().unwrap()?;

let (seq, old_virtual_column_meta) =
get_virtual_column_by_id_or_err(self, &req.name_ident, ctx).await?;
match get_virtual_column_by_id_or_err(self, &req.name_ident, ctx).await {
Ok((seq, old_virtual_column_meta)) => (seq, old_virtual_column_meta),
Err(err) => {
if req.if_exists {
return Ok(UpdateVirtualColumnReply {});
} else {
return Err(err);
}
}
};

let virtual_column_meta = VirtualColumnMeta {
table_id: req.name_ident.table_id,
Expand Down Expand Up @@ -1517,7 +1530,13 @@ impl<KV: kvapi::KVApi<Error = MetaError> + ?Sized> SchemaApi for KV {
loop {
trials.next().unwrap()?;

let (_, _) = get_virtual_column_by_id_or_err(self, &req.name_ident, ctx).await?;
if let Err(err) = get_virtual_column_by_id_or_err(self, &req.name_ident, ctx).await {
if req.if_exists {
return Ok(DropVirtualColumnReply {});
} else {
return Err(err);
}
}

// Drop virtual column by deleting this record:
// (tenant, table_id) -> virtual_column_meta
Expand Down
5 changes: 5 additions & 0 deletions src/meta/api/src/schema_api_test_suite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5768,6 +5768,7 @@ impl SchemaApiTestSuite {
{
info!("--- create virtual column");
let req = CreateVirtualColumnReq {
if_not_exists: false,
name_ident: name_ident.clone(),
virtual_columns: vec!["variant:k1".to_string(), "variant[1]".to_string()],
};
Expand All @@ -5776,6 +5777,7 @@ impl SchemaApiTestSuite {

info!("--- create virtual column again");
let req = CreateVirtualColumnReq {
if_not_exists: false,
name_ident: name_ident.clone(),
virtual_columns: vec!["variant:k1".to_string(), "variant[1]".to_string()],
};
Expand Down Expand Up @@ -5810,6 +5812,7 @@ impl SchemaApiTestSuite {
{
info!("--- update virtual column");
let req = UpdateVirtualColumnReq {
if_exists: false,
name_ident: name_ident.clone(),
virtual_columns: vec!["variant:k2".to_string(), "variant[2]".to_string()],
};
Expand All @@ -5835,6 +5838,7 @@ impl SchemaApiTestSuite {
{
info!("--- drop virtual column");
let req = DropVirtualColumnReq {
if_exists: false,
name_ident: name_ident.clone(),
};

Expand All @@ -5855,6 +5859,7 @@ impl SchemaApiTestSuite {
{
info!("--- update virtual column after drop");
let req = UpdateVirtualColumnReq {
if_exists: false,
name_ident: name_ident.clone(),
virtual_columns: vec!["variant:k3".to_string(), "variant[3]".to_string()],
};
Expand Down
2 changes: 2 additions & 0 deletions src/meta/app/src/principal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod connection;
mod file_format;
mod network_policy;
mod ownership_info;
mod password_policy;
mod principal_identity;
mod role_info;
mod user_auth;
Expand All @@ -35,6 +36,7 @@ pub use connection::*;
pub use file_format::*;
pub use network_policy::NetworkPolicy;
pub use ownership_info::OwnershipInfo;
pub use password_policy::PasswordPolicy;
pub use principal_identity::PrincipalIdentity;
pub use role_info::RoleInfo;
pub use role_info::RoleInfoSerdeError;
Expand Down
35 changes: 35 additions & 0 deletions src/meta/app/src/principal/password_policy.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright 2021 Datafuse Labs
//
// 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.

use chrono::DateTime;
use chrono::Utc;

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Eq, PartialEq, Default)]
pub struct PasswordPolicy {
pub name: String,
pub min_length: u64,
pub max_length: u64,
pub min_upper_case_chars: u64,
pub min_lower_case_chars: u64,
pub min_numeric_chars: u64,
pub min_special_chars: u64,
pub min_age_days: u64,
pub max_age_days: u64,
pub max_retries: u64,
pub lockout_time_mins: u64,
pub history: u64,
pub comment: String,
pub create_on: DateTime<Utc>,
pub update_on: Option<DateTime<Utc>>,
}
16 changes: 16 additions & 0 deletions src/meta/app/src/principal/user_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub struct UserOption {
default_role: Option<String>,

network_policy: Option<String>,

password_policy: Option<String>,
}

impl UserOption {
Expand All @@ -115,6 +117,7 @@ impl UserOption {
flags,
default_role: None,
network_policy: None,
password_policy: None,
}
}

Expand All @@ -137,6 +140,11 @@ impl UserOption {
self
}

pub fn with_password_policy(mut self, password_policy: Option<String>) -> Self {
self.password_policy = password_policy;
self
}

pub fn with_set_flag(mut self, flag: UserOptionFlag) -> Self {
self.flags.insert(flag);
self
Expand All @@ -154,6 +162,10 @@ impl UserOption {
self.network_policy.as_ref()
}

pub fn password_policy(&self) -> Option<&String> {
self.password_policy.as_ref()
}

pub fn set_default_role(&mut self, default_role: Option<String>) {
self.default_role = default_role;
}
Expand All @@ -162,6 +174,10 @@ impl UserOption {
self.network_policy = network_policy;
}

pub fn set_password_policy(&mut self, password_policy: Option<String>) {
self.password_policy = password_policy;
}

pub fn set_all_flag(&mut self) {
self.flags = BitFlags::all();
}
Expand Down
3 changes: 3 additions & 0 deletions src/meta/app/src/schema/virtual_column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct VirtualColumnMeta {

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct CreateVirtualColumnReq {
pub if_not_exists: bool,
pub name_ident: VirtualColumnNameIdent,
pub virtual_columns: Vec<String>,
}
Expand All @@ -75,6 +76,7 @@ pub struct CreateVirtualColumnReply {}

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct UpdateVirtualColumnReq {
pub if_exists: bool,
pub name_ident: VirtualColumnNameIdent,
pub virtual_columns: Vec<String>,
}
Expand All @@ -94,6 +96,7 @@ pub struct UpdateVirtualColumnReply {}

#[derive(serde::Serialize, serde::Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct DropVirtualColumnReq {
pub if_exists: bool,
pub name_ident: VirtualColumnNameIdent,
}

Expand Down
60 changes: 59 additions & 1 deletion src/meta/proto-conv/src/user_from_to_protobuf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ impl FromToProto for mt::principal::UserOption {
Ok(mt::principal::UserOption::default()
.with_flags(flags)
.with_default_role(p.default_role)
.with_network_policy(p.network_policy))
.with_network_policy(p.network_policy)
.with_password_policy(p.password_policy))
}

fn to_pb(&self) -> Result<pb::UserOption, Incompatible> {
Expand All @@ -109,6 +110,7 @@ impl FromToProto for mt::principal::UserOption {
flags: self.flags().bits(),
default_role: self.default_role().cloned(),
network_policy: self.network_policy().cloned(),
password_policy: self.password_policy().cloned(),
})
}
}
Expand Down Expand Up @@ -389,3 +391,59 @@ impl FromToProto for mt::principal::NetworkPolicy {
})
}
}

impl FromToProto for mt::principal::PasswordPolicy {
type PB = pb::PasswordPolicy;
fn get_pb_ver(p: &Self::PB) -> u64 {
p.ver
}
fn from_pb(p: pb::PasswordPolicy) -> Result<Self, Incompatible>
where Self: Sized {
reader_check_msg(p.ver, p.min_reader_ver)?;
Ok(mt::principal::PasswordPolicy {
name: p.name.clone(),
min_length: p.min_length,
max_length: p.max_length,
min_upper_case_chars: p.min_upper_case_chars,
min_lower_case_chars: p.min_lower_case_chars,
min_numeric_chars: p.min_numeric_chars,
min_special_chars: p.min_special_chars,
min_age_days: p.min_age_days,
max_age_days: p.max_age_days,
max_retries: p.max_retries,
lockout_time_mins: p.lockout_time_mins,
history: p.history,
comment: p.comment,
create_on: DateTime::<Utc>::from_pb(p.create_on)?,
update_on: match p.update_on {
Some(t) => Some(DateTime::<Utc>::from_pb(t)?),
None => None,
},
})
}

fn to_pb(&self) -> Result<pb::PasswordPolicy, Incompatible> {
Ok(pb::PasswordPolicy {
ver: VER,
min_reader_ver: MIN_READER_VER,
name: self.name.clone(),
min_length: self.min_length,
max_length: self.max_length,
min_upper_case_chars: self.min_upper_case_chars,
min_lower_case_chars: self.min_lower_case_chars,
min_numeric_chars: self.min_numeric_chars,
min_special_chars: self.min_special_chars,
min_age_days: self.min_age_days,
max_age_days: self.max_age_days,
max_retries: self.max_retries,
lockout_time_mins: self.lockout_time_mins,
history: self.history,
comment: self.comment.clone(),
create_on: self.create_on.to_pb()?,
update_on: match &self.update_on {
Some(t) => Some(t.to_pb()?),
None => None,
},
})
}
}
Loading

0 comments on commit f612bfb

Please sign in to comment.