Skip to content

Commit e01fa78

Browse files
committed
fix: if field contains space in constraint expression, the check will fail
Signed-off-by: Alexander Falk <[email protected]>
1 parent 64f6369 commit e01fa78

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
@@ -1415,15 +1415,16 @@ impl DeltaDataChecker {
14151415
return Ok(());
14161416
}
14171417
let table = MemTable::try_new(record_batch.schema(), vec![vec![record_batch.clone()]])?;
1418-
1418+
let schema = table.schema();
14191419
// Use a random table name to avoid clashes when running multiple parallel tasks, e.g. when using a partitioned table
14201420
let table_name: String = uuid::Uuid::new_v4().to_string();
14211421
self.ctx.register_table(&table_name, Arc::new(table))?;
14221422

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

14251425
for check in checks {
1426-
if check.get_name().contains('.') {
1426+
let check_name = check.get_name();
1427+
if check_name.contains('.') {
14271428
return Err(DeltaTableError::Generic(
14281429
"Support for nested columns is not supported.".to_string(),
14291430
));
@@ -1432,12 +1433,23 @@ impl DeltaDataChecker {
14321433
let field_to_select = if check.as_any().is::<Constraint>() {
14331434
"*"
14341435
} else {
1435-
check.get_name()
1436+
check_name
14361437
};
1438+
1439+
// Loop through schema to find the matching field. If the field has a whitespace, we
1440+
// need to backtick it, since the expression is an unquoted string
1441+
let mut expression = check.get_expression().to_string();
1442+
for field in schema.fields() {
1443+
if expression.contains(field.name()) {
1444+
expression =
1445+
expression.replace(field.name(), format!("`{}` ", field.name()).as_str());
1446+
break;
1447+
}
1448+
}
1449+
14371450
let sql = format!(
14381451
"SELECT {} FROM `{table_name}` WHERE NOT ({}) LIMIT 1",
1439-
field_to_select,
1440-
check.get_expression()
1452+
field_to_select, expression
14411453
);
14421454

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

0 commit comments

Comments
 (0)