@@ -331,9 +331,9 @@ impl InvariantChecker {
331
331
///
332
332
/// This traverses the entire schema to check for the presence of the "delta.invariants"
333
333
/// metadata key.
334
- pub ( crate ) fn has_invariants ( schema : & Schema ) -> bool {
334
+ pub ( crate ) fn has_invariants ( schema : SchemaRef ) -> bool {
335
335
let mut checker = InvariantChecker :: default ( ) ;
336
- let _ = checker. transform_struct ( schema) ;
336
+ let _ = checker. transform_struct ( schema. as_ref ( ) ) ;
337
337
checker. has_invariants
338
338
}
339
339
}
@@ -1251,11 +1251,11 @@ mod tests {
1251
1251
#[ test]
1252
1252
fn test_has_invariants ( ) {
1253
1253
// Schema with no invariants
1254
- let schema = StructType :: new ( [
1254
+ let schema = Arc :: new ( StructType :: new ( [
1255
1255
StructField :: nullable ( "a" , DataType :: STRING ) ,
1256
1256
StructField :: nullable ( "b" , DataType :: INTEGER ) ,
1257
- ] ) ;
1258
- assert ! ( !InvariantChecker :: has_invariants( & schema) ) ;
1257
+ ] ) ) ;
1258
+ assert ! ( !InvariantChecker :: has_invariants( schema) ) ;
1259
1259
1260
1260
// Schema with top-level invariant
1261
1261
let mut field = StructField :: nullable ( "c" , DataType :: STRING ) ;
@@ -1264,8 +1264,11 @@ mod tests {
1264
1264
MetadataValue :: String ( "c > 0" . to_string ( ) ) ,
1265
1265
) ;
1266
1266
1267
- let schema = StructType :: new ( [ StructField :: nullable ( "a" , DataType :: STRING ) , field] ) ;
1268
- assert ! ( InvariantChecker :: has_invariants( & schema) ) ;
1267
+ let schema = Arc :: new ( StructType :: new ( [
1268
+ StructField :: nullable ( "a" , DataType :: STRING ) ,
1269
+ field,
1270
+ ] ) ) ;
1271
+ assert ! ( InvariantChecker :: has_invariants( schema) ) ;
1269
1272
1270
1273
// Schema with nested invariant in a struct
1271
1274
let nested_field = StructField :: nullable (
@@ -1280,12 +1283,12 @@ mod tests {
1280
1283
} ] ) ,
1281
1284
) ;
1282
1285
1283
- let schema = StructType :: new ( [
1286
+ let schema = Arc :: new ( StructType :: new ( [
1284
1287
StructField :: nullable ( "a" , DataType :: STRING ) ,
1285
1288
StructField :: nullable ( "b" , DataType :: INTEGER ) ,
1286
1289
nested_field,
1287
- ] ) ;
1288
- assert ! ( InvariantChecker :: has_invariants( & schema) ) ;
1290
+ ] ) ) ;
1291
+ assert ! ( InvariantChecker :: has_invariants( schema) ) ;
1289
1292
1290
1293
// Schema with nested invariant in an array of structs
1291
1294
let array_field = StructField :: nullable (
@@ -1303,12 +1306,12 @@ mod tests {
1303
1306
) ,
1304
1307
) ;
1305
1308
1306
- let schema = StructType :: new ( [
1309
+ let schema = Arc :: new ( StructType :: new ( [
1307
1310
StructField :: nullable ( "a" , DataType :: STRING ) ,
1308
1311
StructField :: nullable ( "b" , DataType :: INTEGER ) ,
1309
1312
array_field,
1310
- ] ) ;
1311
- assert ! ( InvariantChecker :: has_invariants( & schema) ) ;
1313
+ ] ) ) ;
1314
+ assert ! ( InvariantChecker :: has_invariants( schema) ) ;
1312
1315
1313
1316
// Schema with nested invariant in a map value that's a struct
1314
1317
let map_field = StructField :: nullable (
@@ -1327,11 +1330,11 @@ mod tests {
1327
1330
) ,
1328
1331
) ;
1329
1332
1330
- let schema = StructType :: new ( [
1333
+ let schema = Arc :: new ( StructType :: new ( [
1331
1334
StructField :: nullable ( "a" , DataType :: STRING ) ,
1332
1335
StructField :: nullable ( "b" , DataType :: INTEGER ) ,
1333
1336
map_field,
1334
- ] ) ;
1335
- assert ! ( InvariantChecker :: has_invariants( & schema) ) ;
1337
+ ] ) ) ;
1338
+ assert ! ( InvariantChecker :: has_invariants( schema) ) ;
1336
1339
}
1337
1340
}
0 commit comments