Skip to content

Commit 6fe029b

Browse files
authored
Remove unnecessary work from ListArray::validate (#6004)
This PR removes some unnecessary work, relying on the previous assertion that the offsets array is sorted. Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent cb5e860 commit 6fe029b

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

vortex-array/src/arrays/list/array.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -180,36 +180,34 @@ impl ListArray {
180180
// the elements array.
181181
if let Some(min_max) = min_max(offsets)? {
182182
match_each_integer_ptype!(offsets_ptype, |P| {
183-
let max_offset = P::try_from(offsets.scalar_at(offsets.len() - 1))
184-
.vortex_expect("Offsets type must fit offsets values");
185-
186183
#[allow(clippy::absurd_extreme_comparisons, unused_comparisons)]
187184
{
188-
if let Some(min) = min_max.min.as_primitive().as_::<P>() {
189-
vortex_ensure!(
190-
min >= 0 && min <= max_offset,
191-
"offsets minimum {min} outside valid range [0, {max_offset}]"
192-
);
193-
}
185+
let max = min_max
186+
.max
187+
.as_primitive()
188+
.as_::<P>()
189+
.vortex_expect("offsets type must fit offsets values");
190+
let min = min_max
191+
.min
192+
.as_primitive()
193+
.as_::<P>()
194+
.vortex_expect("offsets type must fit offsets values");
194195

195-
if let Some(max) = min_max.max.as_primitive().as_::<P>() {
196-
vortex_ensure!(
197-
max >= 0 && max <= max_offset,
198-
"offsets maximum {max} outside valid range [0, {max_offset}]"
199-
)
200-
}
201-
}
196+
vortex_ensure!(
197+
min >= 0,
198+
"offsets minimum {min} outside valid range [0, {max}]"
199+
);
202200

203-
vortex_ensure!(
204-
max_offset
205-
<= P::try_from(elements.len()).unwrap_or_else(|_| vortex_panic!(
201+
vortex_ensure!(
202+
max <= P::try_from(elements.len()).unwrap_or_else(|_| vortex_panic!(
206203
"Offsets type {} must be able to fit elements length {}",
207204
<P as NativePType>::PTYPE,
208205
elements.len()
209206
)),
210-
"Max offset {max_offset} is beyond the length of the elements array {}",
211-
elements.len()
212-
);
207+
"Max offset {max} is beyond the length of the elements array {}",
208+
elements.len()
209+
);
210+
}
213211
})
214212
} else {
215213
// TODO(aduffy): fallback to slower validation pathway?

0 commit comments

Comments
 (0)