Skip to content

Commit 7b6d984

Browse files
committed
fixes
Signed-off-by: Robert Kruszewski <github@robertk.io>
1 parent ce5a9f7 commit 7b6d984

3 files changed

Lines changed: 16 additions & 33 deletions

File tree

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

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
use std::fmt::Display;
55
use std::fmt::Formatter;
66

7+
use num_traits::AsPrimitive;
78
use vortex_buffer::BitBuffer;
89
use vortex_error::VortexExpect;
910
use vortex_error::VortexResult;
@@ -133,7 +134,7 @@ pub trait DictArrayExt: TypedArrayRef<Dict> + DictArraySlotsExt {
133134
}
134135

135136
let referenced_mask = self.compute_referenced_values_mask(true)?;
136-
let all_referenced = referenced_mask.iter().all(|v| v);
137+
let all_referenced = referenced_mask.true_count() == referenced_mask.len();
137138

138139
vortex_ensure!(all_referenced, "value in dict not referenced");
139140
}
@@ -157,28 +158,19 @@ pub trait DictArrayExt: TypedArrayRef<Dict> + DictArraySlotsExt {
157158
match codes_validity.bit_buffer() {
158159
AllOr::All => {
159160
match_each_integer_ptype!(codes_primitive.ptype(), |P| {
160-
#[allow(
161-
clippy::cast_possible_truncation,
162-
clippy::cast_sign_loss,
163-
reason = "codes are non-negative indices; a negative signed code would wrap to a large usize and panic on the bounds-checked array index"
164-
)]
165-
for &idx in codes_primitive.as_slice::<P>() {
166-
values_vec[idx as usize] = referenced_value;
161+
for idx in codes_primitive.as_slice::<P>() {
162+
let idxu: usize = idx.as_();
163+
values_vec[idxu] = referenced_value;
167164
}
168165
});
169166
}
170167
AllOr::None => {}
171168
AllOr::Some(mask) => {
172169
match_each_integer_ptype!(codes_primitive.ptype(), |P| {
173170
let codes = codes_primitive.as_slice::<P>();
174-
175-
#[allow(
176-
clippy::cast_possible_truncation,
177-
clippy::cast_sign_loss,
178-
reason = "codes are non-negative indices; a negative signed code would wrap to a large usize and panic on the bounds-checked array index"
179-
)]
180171
mask.set_indices().for_each(|idx| {
181-
values_vec[codes[idx] as usize] = referenced_value;
172+
let idxu: usize = codes[idx].as_();
173+
values_vec[idxu] = referenced_value;
182174
});
183175
});
184176
}

vortex-array/src/builders/dict/bytes.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -175,14 +175,11 @@ impl<Code: UnsignedPType> BytesDictBuilder<Code> {
175175
for (w, valid) in slice_offsets.windows(2).zip_eq(b.iter()) {
176176
if !valid {
177177
let code = self.null_code.get_or_init(|| {
178+
let code = self.views.len();
178179
self.views.push(BinaryView::default());
179180
self.values_nulls.append_false();
180-
Code::from_usize(self.values.len()).unwrap_or_else(|| {
181-
vortex_panic!(
182-
"{} has to fit into {}",
183-
self.values.len(),
184-
Code::PTYPE
185-
)
181+
Code::from_usize(code).unwrap_or_else(|| {
182+
vortex_panic!("{} has to fit into {}", code, Code::PTYPE)
186183
})
187184
});
188185
unsafe { codes.push_unchecked(*code) }
@@ -255,14 +252,11 @@ impl<Code: UnsignedPType> BytesDictBuilder<Code> {
255252
for (view, valid) in views.iter().zip_eq(b.iter()) {
256253
if !valid {
257254
let code = self.null_code.get_or_init(|| {
255+
let code = self.views.len();
258256
self.views.push(BinaryView::default());
259257
self.values_nulls.append_false();
260-
Code::from_usize(self.values.len()).unwrap_or_else(|| {
261-
vortex_panic!(
262-
"{} has to fit into {}",
263-
self.values.len(),
264-
Code::PTYPE
265-
)
258+
Code::from_usize(code).unwrap_or_else(|| {
259+
vortex_panic!("{} has to fit into {}", code, Code::PTYPE)
266260
})
267261
});
268262
unsafe { codes.push_unchecked(*code) }

vortex-array/src/builders/dict/primitive.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,11 @@ where
146146
for (&value, valid) in prim.as_slice::<T>().iter().zip(bit_buff) {
147147
if !valid {
148148
let code = self.null_code.get_or_init(|| {
149+
let code = self.values.len();
149150
self.values.push(T::default());
150151
self.values_nulls.append_false();
151-
Code::from_usize(self.values.len()).unwrap_or_else(|| {
152-
vortex_panic!(
153-
"{} has to fit into {}",
154-
self.values.len(),
155-
Code::PTYPE
156-
)
152+
Code::from_usize(code).unwrap_or_else(|| {
153+
vortex_panic!("{} has to fit into {}", code, Code::PTYPE)
157154
})
158155
});
159156
unsafe { codes.push_unchecked(*code) }

0 commit comments

Comments
 (0)