Skip to content

Commit

Permalink
use temporary table names during the constraint checks
Browse files Browse the repository at this point in the history
Signed-off-by: Nikolay Ulmasov <[email protected]>
  • Loading branch information
r3stl355 committed Jan 2, 2024
1 parent 4cb754b commit 68f7484
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions crates/deltalake-core/src/delta_datafusion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1128,7 +1128,10 @@ impl DeltaDataChecker {
return Ok(());
}
let table = MemTable::try_new(record_batch.schema(), vec![vec![record_batch.clone()]])?;
self.ctx.register_table("data", Arc::new(table))?;

// Use a random table name to avoid clashes when running multiple parallel tasks, e.g. when using a partitioned table
let table_name: String = uuid::Uuid::new_v4().to_string();
self.ctx.register_table(&table_name, Arc::new(table))?;

let mut violations: Vec<String> = Vec::new();

Expand All @@ -1140,8 +1143,9 @@ impl DeltaDataChecker {
}

let sql = format!(
"SELECT {} FROM data WHERE NOT ({}) LIMIT 1",
"SELECT {} FROM `{}` WHERE NOT ({}) LIMIT 1",
check.get_name(),
table_name,
check.get_expression()
);

Expand All @@ -1162,7 +1166,7 @@ impl DeltaDataChecker {
}
}

self.ctx.deregister_table("data")?;
self.ctx.deregister_table(&table_name)?;
if !violations.is_empty() {
Err(DeltaTableError::InvalidData { violations })
} else {
Expand Down

0 comments on commit 68f7484

Please sign in to comment.