Skip to content

Commit 6babfb6

Browse files
Nordalfrtyler
authored andcommitted
fix: if field contains space in constraint expression, the check will fail
Signed-off-by: Alexander Falk <[email protected]>
1 parent 13acb2f commit 6babfb6

File tree

1 file changed

+17
-5
lines changed
  • crates/core/src/delta_datafusion

1 file changed

+17
-5
lines changed

crates/core/src/delta_datafusion/mod.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,15 +1418,16 @@ impl DeltaDataChecker {
14181418
return Ok(());
14191419
}
14201420
let table = MemTable::try_new(record_batch.schema(), vec![vec![record_batch.clone()]])?;
1421-
1421+
let schema = table.schema();
14221422
// Use a random table name to avoid clashes when running multiple parallel tasks, e.g. when using a partitioned table
14231423
let table_name: String = uuid::Uuid::new_v4().to_string();
14241424
self.ctx.register_table(&table_name, Arc::new(table))?;
14251425

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

14281428
for check in checks {
1429-
if check.get_name().contains('.') {
1429+
let check_name = check.get_name();
1430+
if check_name.contains('.') {
14301431
return Err(DeltaTableError::Generic(
14311432
"Support for nested columns is not supported.".to_string(),
14321433
));
@@ -1435,12 +1436,23 @@ impl DeltaDataChecker {
14351436
let field_to_select = if check.as_any().is::<Constraint>() {
14361437
"*"
14371438
} else {
1438-
check.get_name()
1439+
check_name
14391440
};
1441+
1442+
// Loop through schema to find the matching field. If the field has a whitespace, we
1443+
// need to backtick it, since the expression is an unquoted string
1444+
let mut expression = check.get_expression().to_string();
1445+
for field in schema.fields() {
1446+
if expression.contains(field.name()) {
1447+
expression =
1448+
expression.replace(field.name(), format!("`{}` ", field.name()).as_str());
1449+
break;
1450+
}
1451+
}
1452+
14401453
let sql = format!(
14411454
"SELECT {} FROM `{table_name}` WHERE NOT ({}) LIMIT 1",
1442-
field_to_select,
1443-
check.get_expression()
1455+
field_to_select, expression
14441456
);
14451457

14461458
let dfs: Vec<RecordBatch> = self.ctx.sql(&sql).await?.collect().await?;

0 commit comments

Comments
 (0)