Skip to content

Commit a5a9619

Browse files
committed
change with_constraint to insert and with_constraints for bulk insert
Signed-off-by: JustinRush80 <[email protected]>
1 parent a6bc2c7 commit a5a9619

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

crates/core/src/operations/constraints.rs

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,25 @@ impl ConstraintBuilder {
6464

6565
/// Specify the constraint to be added
6666
pub fn with_constraint<S: Into<String>, E: Into<Expression>>(
67+
mut self,
68+
name: S,
69+
expression: E,
70+
) -> Self {
71+
self.check_constraints
72+
.insert(name.into(), expression.into());
73+
self
74+
}
75+
76+
/// Specify multiple constraints to be added
77+
pub fn with_constraints<S: Into<String>, E: Into<Expression>>(
6778
mut self,
6879
constraints: HashMap<S, E>,
6980
) -> Self {
70-
self.check_constraints = constraints
71-
.into_iter()
72-
.map(|(name, expression)| (name.into(), expression.into()))
73-
.collect();
81+
self.check_constraints.extend(
82+
constraints
83+
.into_iter()
84+
.map(|(name, expr)| (name.into(), expr.into())),
85+
);
7486
self
7587
}
7688

@@ -321,7 +333,7 @@ mod tests {
321333

322334
let constraint = table
323335
.add_constraint()
324-
.with_constraint(HashMap::from([("my_custom_constraint", "value < 100")]))
336+
.with_constraint("my_custom_constraint", "value < 100")
325337
.await;
326338
assert!(constraint.is_ok());
327339
let constraints = constraint
@@ -345,7 +357,7 @@ mod tests {
345357

346358
let constraint = table
347359
.add_constraint()
348-
.with_constraint(HashMap::from([("id", "value > 5")]))
360+
.with_constraint("id", "value > 5")
349361
.await;
350362
assert!(constraint.is_err());
351363
Ok(())
@@ -361,7 +373,7 @@ mod tests {
361373

362374
let mut table = table
363375
.add_constraint()
364-
.with_constraint(HashMap::from([("id", "value < 1000")]))
376+
.with_constraint("id", "value < 1000")
365377
.await?;
366378
let version = table.version();
367379
assert_eq!(version, Some(1));
@@ -391,7 +403,7 @@ mod tests {
391403

392404
let constraints = HashMap::from([("id", "value < 1000"), ("id2", "value < 20")]);
393405

394-
let mut table = table.add_constraint().with_constraint(constraints).await?;
406+
let mut table = table.add_constraint().with_constraints(constraints).await?;
395407
let version = table.version();
396408
assert_eq!(version, Some(1));
397409

@@ -422,10 +434,7 @@ mod tests {
422434

423435
let mut table = table
424436
.add_constraint()
425-
.with_constraint(HashMap::from([(
426-
"valid_values",
427-
col("value").lt(lit(1000)),
428-
)]))
437+
.with_constraint("valid_values", col("value").lt(lit(1000)))
429438
.await?;
430439
let version = table.version();
431440
assert_eq!(version, Some(1));
@@ -472,7 +481,7 @@ mod tests {
472481

473482
let mut table = DeltaOps(table)
474483
.add_constraint()
475-
.with_constraint(HashMap::from([("valid_values", "vAlue < 1000")])) // spellchecker:disable-line
484+
.with_constraint("valid_values", "vAlue < 1000") // spellchecker:disable-line
476485
.await?;
477486
let version = table.version();
478487
assert_eq!(version, Some(1));
@@ -503,13 +512,13 @@ mod tests {
503512

504513
let new_table = table
505514
.add_constraint()
506-
.with_constraint(HashMap::from([("id", "value < 60")]))
515+
.with_constraint("id", "value < 60")
507516
.await?;
508517

509518
let new_table = DeltaOps(new_table);
510519
let second_constraint = new_table
511520
.add_constraint()
512-
.with_constraint(HashMap::from([("id", "value < 10")]))
521+
.with_constraint("id", "value < 10")
513522
.await;
514523
assert!(second_constraint.is_err());
515524
Ok(())
@@ -524,7 +533,7 @@ mod tests {
524533

525534
let table = DeltaOps(write)
526535
.add_constraint()
527-
.with_constraint(HashMap::from([("id", "value > 0")]))
536+
.with_constraint("id", "value > 0")
528537
.await?;
529538
let table = DeltaOps(table);
530539
let invalid_values: Vec<Arc<dyn Array>> = vec![
@@ -546,7 +555,7 @@ mod tests {
546555

547556
let table = DeltaOps(write)
548557
.add_constraint()
549-
.with_constraint(HashMap::from([
558+
.with_constraints(HashMap::from([
550559
("id", "value > 0"),
551560
("custom_cons", "value < 30"),
552561
]))

crates/core/src/operations/drop_constraints.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ mod tests {
164164

165165
let table = table
166166
.add_constraint()
167-
.with_constraint(HashMap::from([("id", "value < 1000")]))
167+
.with_constraint("id", "value < 1000")
168168
.await?;
169169

170170
let mut table = DeltaOps(table)

crates/core/src/operations/restore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ mod tests {
397397

398398
let constraint = DeltaOps(table)
399399
.add_constraint()
400-
.with_constraint(HashMap::from([("my_custom_constraint", "value < 100")]))
400+
.with_constraint("my_custom_constraint", "value < 100")
401401
.await;
402402
let table = constraint.expect("Failed to add constraint to table");
403403

python/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ impl RawDeltaTable {
794794
let table = self._table.lock().map_err(to_rt_err)?.clone();
795795
let mut cmd = DeltaOps(table).add_constraint();
796796

797-
cmd = cmd.with_constraint(constraints);
797+
cmd = cmd.with_constraints(constraints);
798798

799799
if let Some(commit_properties) =
800800
maybe_create_commit_properties(commit_properties, post_commithook_properties)

0 commit comments

Comments
 (0)