Skip to content

Commit c247bc9

Browse files
committed
fix harder
Signed-off-by: Andrew Duffy <[email protected]>
1 parent 90d8b4a commit c247bc9

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

vortex-array/src/arrays/listview/rebuild.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,26 @@ impl ListViewArray {
7474
let offsets_ptype = self.offsets().dtype().as_ptype();
7575
let sizes_ptype = self.sizes().dtype().as_ptype();
7676

77-
match_each_integer_ptype!(offsets_ptype, |O| {
78-
match_each_integer_ptype!(sizes_ptype, |S| { self.naive_rebuild::<O, S>() })
77+
match_each_integer_ptype!(sizes_ptype, |S| {
78+
match offsets_ptype {
79+
PType::U8 => self.naive_rebuild::<u8, u32, S>(),
80+
PType::U16 => self.naive_rebuild::<u16, u32, S>(),
81+
PType::U32 => self.naive_rebuild::<u32, u32, S>(),
82+
PType::U64 => self.naive_rebuild::<u64, u64, S>(),
83+
PType::I8 => self.naive_rebuild::<i8, i32, S>(),
84+
PType::I16 => self.naive_rebuild::<i16, i32, S>(),
85+
PType::I32 => self.naive_rebuild::<i32, i32, S>(),
86+
PType::I64 => self.naive_rebuild::<i64, i64, S>(),
87+
_ => unreachable!("invalid offsets PType"),
88+
}
7989
})
8090
}
8191

8292
/// The inner function for `rebuild_zero_copy_to_list`, which naively rebuilds a `ListViewArray`
8393
/// via `append_scalar`.
84-
fn naive_rebuild<O: IntegerPType, S: IntegerPType>(&self) -> ListViewArray {
94+
fn naive_rebuild<O: IntegerPType, NewOffset: IntegerPType, S: IntegerPType>(
95+
&self,
96+
) -> ListViewArray {
8597
let element_dtype = self
8698
.dtype()
8799
.as_list_element_opt()
@@ -96,12 +108,12 @@ impl ListViewArray {
96108
let offsets_canonical = offsets_canonical.as_slice::<O>();
97109
let sizes_canonical = sizes_canonical.as_slice::<S>();
98110

99-
let mut offsets = BufferMut::<u32>::with_capacity(self.len());
111+
let mut offsets = BufferMut::<NewOffset>::with_capacity(self.len());
100112
let mut sizes = BufferMut::<S>::with_capacity(self.len());
101113

102114
let mut chunks = Vec::with_capacity(self.len());
103115

104-
let mut n_elements = 0u32;
116+
let mut n_elements = NewOffset::zero();
105117

106118
for index in 0..self.len() {
107119
if !self.is_valid(index) {
@@ -120,7 +132,7 @@ impl ListViewArray {
120132
offsets.push(n_elements);
121133
sizes.push(size);
122134

123-
n_elements += size.to_u32().vortex_expect("to_u32");
135+
n_elements += num_traits::cast(size).vortex_expect("cast");
124136
}
125137

126138
let offsets = offsets.into_array();

vortex-array/src/builders/listview.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,4 @@ mod tests {
617617
.contains("null value to non-nullable")
618618
);
619619
}
620-
621-
#[test]
622-
#[should_panic(
623-
expected = "Size type I32 (max offset 2147483647) must fit within offset type I16 (max offset 32767)"
624-
)]
625-
fn test_error_invalid_type_combination() {
626-
let dtype: Arc<DType> = Arc::new(I32.into());
627-
// This should panic because i32 (4 bytes) cannot fit within i16 (2 bytes).
628-
let _builder = ListViewBuilder::<i16, i32>::with_capacity(dtype, NonNullable, 0, 0);
629-
}
630620
}

0 commit comments

Comments
 (0)