fix(schema): allow paths without an explicit width

Make path width nullable to preserve absent WIDTH records separately from explicit zero or negative widths in full and selected reads.
This commit is contained in:
Jan Petykiewicz 2026-11-14 14:39:08 -08:00
commit e858ec83c9

View file

@ -1,8 +1,8 @@
mod common;
use arrow::array::{
Array, BooleanArray, Float64Array, ListArray, StringArray, StructArray, UInt32Array,
UInt64Array,
Array, BooleanArray, Float64Array, Int32Array, ListArray, StringArray, StructArray,
UInt32Array, UInt64Array,
};
use arrow::ffi::{FFI_ArrowArray, FFI_ArrowSchema, from_ffi};
use common::{library_header, record};
@ -129,6 +129,41 @@ fn aref_invalid_counts_and_unrepresentable_pitches_return_errors() {
assert!(scan_library(&bytes).is_err());
}
#[test]
fn paths_preserve_missing_explicit_zero_and_negative_widths() {
let mut bytes = library_header();
record(&mut bytes, records::RTAG_BGNSTR, &[0; 24]);
record(&mut bytes, records::RTAG_STRNAME, b"top\0");
for width in [None, Some(0_i32), Some(-100)] {
record(&mut bytes, records::RTAG_PATH, &[]);
record(&mut bytes, records::RTAG_LAYER, &[0, 1]);
record(&mut bytes, records::RTAG_DATATYPE, &[0, 0]);
if let Some(width) = width {
record(&mut bytes, records::RTAG_WIDTH, &width.to_be_bytes());
}
record(&mut bytes, records::RTAG_XY, &xy(&[0, 0, 10, 10]));
record(&mut bytes, records::RTAG_ENDEL, &[]);
}
record(&mut bytes, records::RTAG_ENDSTR, &[]);
record(&mut bytes, records::RTAG_ENDLIB, &[]);
let (_, full) = read_library(&bytes).unwrap();
let (_, scan) = scan_library(&bytes).unwrap();
let (_, selected) = read_selected_library(&bytes, &ranges(&scan)).unwrap();
assert_eq!(full, selected);
let cells = list_struct(&full, "cells", 0);
let paths = list_struct(&cells, "paths", 0);
let widths = paths
.column_by_name("width")
.unwrap()
.as_any()
.downcast_ref::<Int32Array>()
.unwrap();
assert_eq!(
widths.iter().collect::<Vec<_>>(),
[None, Some(0), Some(-100)]
);
}
fn u64_value(array: &StructArray, name: &str, row: usize) -> u64 {
array
.column_by_name(name)