Skip to content

Commit

Permalink
simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
ion-elgreco committed Feb 1, 2024
1 parent 7d8ff4f commit 6efc831
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions crates/core/src/operations/drop_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,22 @@ impl std::future::IntoFuture for DropConstraintBuilder {
let mut this = self;

Box::pin(async move {
let name = this.name.ok_or(Err(DeltaTableError::Generic("No name provided".to_string())))?;
let name = this
.name
.ok_or(DeltaTableError::Generic("No name provided".to_string()))?;

let mut metadata = this.snapshot.metadata().clone();
let configuration_key = format!("delta.constraints.{}", name);

if metadata.configuration.remove(&configuration_key).is_none() {
if this.raise_if_not_exists {
return Err(DeltaTableError::Generic(format!(
"Constraint with name: {} doesn't exists",
name
)));
}
return Ok(DeltaTable::new_with_state(this.log_store, this.snapshot));
}

let contains_constraints = metadata
.configuration
.keys()
.any(|k| k.starts_with("delta.constraints"));

if metadata.configuration.remove(&configuration_key).is_none() {
if this.raise_if_not_exists {
return Err(DeltaTableError::Generic(format!(
"Constraint with name: {} doesn't exists",
name
)));
}
return Ok(DeltaTable::new_with_state(this.log_store, this.snapshot));
}
let operational_parameters = HashMap::from_iter([("name".to_string(), json!(&name))]);

let operations = DeltaOperation::DropConstraint { name: name.clone() };
Expand Down

0 comments on commit 6efc831

Please sign in to comment.