Skip to content

Commit 89ddf07

Browse files
committed
chore: add test for handling fields with spaces in constraints
Signed-off-by: R. Tyler Croy <[email protected]>
1 parent 6babfb6 commit 89ddf07

File tree

1 file changed

+52
-1
lines changed
  • crates/core/src/delta_datafusion

1 file changed

+52
-1
lines changed

crates/core/src/delta_datafusion/mod.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,6 @@ impl DeltaDataChecker {
14491449
break;
14501450
}
14511451
}
1452-
14531452
let sql = format!(
14541453
"SELECT {} FROM `{table_name}` WHERE NOT ({}) LIMIT 1",
14551454
field_to_select, expression
@@ -2248,6 +2247,58 @@ mod tests {
22482247
assert!(result.is_err());
22492248
}
22502249

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+
22512302
#[test]
22522303
fn roundtrip_test_delta_exec_plan() {
22532304
let ctx = SessionContext::new();

0 commit comments

Comments
 (0)