@@ -1415,15 +1415,16 @@ impl DeltaDataChecker {
1415
1415
return Ok ( ( ) ) ;
1416
1416
}
1417
1417
let table = MemTable :: try_new ( record_batch. schema ( ) , vec ! [ vec![ record_batch. clone( ) ] ] ) ?;
1418
-
1418
+ let schema = table . schema ( ) ;
1419
1419
// Use a random table name to avoid clashes when running multiple parallel tasks, e.g. when using a partitioned table
1420
1420
let table_name: String = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ;
1421
1421
self . ctx . register_table ( & table_name, Arc :: new ( table) ) ?;
1422
1422
1423
1423
let mut violations: Vec < String > = Vec :: new ( ) ;
1424
1424
1425
1425
for check in checks {
1426
- if check. get_name ( ) . contains ( '.' ) {
1426
+ let check_name = check. get_name ( ) ;
1427
+ if check_name. contains ( '.' ) {
1427
1428
return Err ( DeltaTableError :: Generic (
1428
1429
"Support for nested columns is not supported." . to_string ( ) ,
1429
1430
) ) ;
@@ -1432,12 +1433,23 @@ impl DeltaDataChecker {
1432
1433
let field_to_select = if check. as_any ( ) . is :: < Constraint > ( ) {
1433
1434
"*"
1434
1435
} else {
1435
- check . get_name ( )
1436
+ check_name
1436
1437
} ;
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
+
1437
1450
let sql = format ! (
1438
1451
"SELECT {} FROM `{table_name}` WHERE NOT ({}) LIMIT 1" ,
1439
- field_to_select,
1440
- check. get_expression( )
1452
+ field_to_select, expression
1441
1453
) ;
1442
1454
1443
1455
let dfs: Vec < RecordBatch > = self . ctx . sql ( & sql) . await ?. collect ( ) . await ?;
0 commit comments