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
3 changed files with 39 additions and 4 deletions

View file

@ -119,7 +119,7 @@ Boundaries are grouped into batches for efficiency when they share properties or
- `path_type`: `Int16` (Optional) - `path_type`: `Int16` (Optional)
- `extension_start`: `Int32` (Optional) - `extension_start`: `Int32` (Optional)
- `extension_end`: `Int32` (Optional) - `extension_end`: `Int32` (Optional)
- `width`: `Int32` - `width`: `Int32` (Optional; null when `WIDTH` is absent)
- `xy`: `List(Int32)` (centerline coordinates) - `xy`: `List(Int32)` (centerline coordinates)
- `properties`: `List(Property)` - `properties`: `List(Property)`

View file

@ -226,7 +226,7 @@ fn make_library_builder() -> StructBuilder {
Field::new("path_type", DataType::Int16, true), Field::new("path_type", DataType::Int16, true),
Field::new("extension_start", DataType::Int32, true), Field::new("extension_start", DataType::Int32, true),
Field::new("extension_end", DataType::Int32, true), Field::new("extension_end", DataType::Int32, true),
Field::new("width", DataType::Int32, false), Field::new("width", DataType::Int32, true),
Field::new("xy", coords_t.clone(), false), Field::new("xy", coords_t.clone(), false),
Field::new("properties", property_list_t.clone(), true), Field::new("properties", property_list_t.clone(), true),
])); ]));

View file

@ -1,8 +1,8 @@
mod common; mod common;
use arrow::array::{ use arrow::array::{
Array, BooleanArray, Float64Array, ListArray, StringArray, StructArray, UInt32Array, Array, BooleanArray, Float64Array, Int32Array, ListArray, StringArray, StructArray,
UInt64Array, UInt32Array, UInt64Array,
}; };
use arrow::ffi::{FFI_ArrowArray, FFI_ArrowSchema, from_ffi}; use arrow::ffi::{FFI_ArrowArray, FFI_ArrowSchema, from_ffi};
use common::{library_header, record}; use common::{library_header, record};
@ -129,6 +129,41 @@ fn aref_invalid_counts_and_unrepresentable_pitches_return_errors() {
assert!(scan_library(&bytes).is_err()); 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 { fn u64_value(array: &StructArray, name: &str, row: usize) -> u64 {
array array
.column_by_name(name) .column_by_name(name)