@@ -1449,7 +1449,6 @@ impl DeltaDataChecker {
1449
1449
break ;
1450
1450
}
1451
1451
}
1452
-
1453
1452
let sql = format ! (
1454
1453
"SELECT {} FROM `{table_name}` WHERE NOT ({}) LIMIT 1" ,
1455
1454
field_to_select, expression
@@ -2248,6 +2247,58 @@ mod tests {
2248
2247
assert ! ( result. is_err( ) ) ;
2249
2248
}
2250
2249
2250
+ /// Ensure that constraints when there are spaces in the field name still work
2251
+ ///
2252
+ /// See <https://github.com/delta-io/delta-rs/pull/3374>
2253
+ #[ tokio:: test]
2254
+ async fn test_constraints_with_spacey_fields ( ) -> DeltaResult < ( ) > {
2255
+ let schema = Arc :: new ( Schema :: new ( vec ! [
2256
+ Field :: new( "a" , ArrowDataType :: Utf8 , false ) ,
2257
+ Field :: new( "b bop" , ArrowDataType :: Int32 , false ) ,
2258
+ ] ) ) ;
2259
+ let batch = RecordBatch :: try_new (
2260
+ Arc :: clone ( & schema) ,
2261
+ vec ! [
2262
+ Arc :: new( arrow:: array:: StringArray :: from( vec![
2263
+ "a" , "b bop" , "c" , "d" ,
2264
+ ] ) ) ,
2265
+ Arc :: new( arrow:: array:: Int32Array :: from( vec![ 1 , 10 , 10 , 100 ] ) ) ,
2266
+ ] ,
2267
+ ) ?;
2268
+
2269
+ // Valid invariants return Ok(())
2270
+ let constraints = vec ! [
2271
+ Constraint :: new( "custom a" , "a is not null" ) ,
2272
+ Constraint :: new( "custom_b" , "b bop < 1000" ) ,
2273
+ ] ;
2274
+ assert ! ( DeltaDataChecker :: new_with_constraints( constraints)
2275
+ . check_batch( & batch)
2276
+ . await
2277
+ . is_ok( ) ) ;
2278
+
2279
+ // Violated invariants returns an error with list of violations
2280
+ let constraints = vec ! [
2281
+ Constraint :: new( "custom_a" , "a is null" ) ,
2282
+ Constraint :: new( "custom_B" , "b bop < 100" ) ,
2283
+ ] ;
2284
+ let result = DeltaDataChecker :: new_with_constraints ( constraints)
2285
+ . check_batch ( & batch)
2286
+ . await ;
2287
+ assert ! ( result. is_err( ) ) ;
2288
+ assert ! ( matches!( result, Err ( DeltaTableError :: InvalidData { .. } ) ) ) ;
2289
+ if let Err ( DeltaTableError :: InvalidData { violations } ) = result {
2290
+ assert_eq ! ( violations. len( ) , 2 ) ;
2291
+ }
2292
+
2293
+ // Irrelevant constraints return a different error
2294
+ let constraints = vec ! [ Constraint :: new( "custom_c" , "c > 2000" ) ] ;
2295
+ let result = DeltaDataChecker :: new_with_constraints ( constraints)
2296
+ . check_batch ( & batch)
2297
+ . await ;
2298
+ assert ! ( result. is_err( ) ) ;
2299
+ Ok ( ( ) )
2300
+ }
2301
+
2251
2302
#[ test]
2252
2303
fn roundtrip_test_delta_exec_plan ( ) {
2253
2304
let ctx = SessionContext :: new ( ) ;
0 commit comments