Skip to content

Commit 4c7589c

Browse files
Add more unchecked constructors (#4527)
Fixes #4420 TODO description but mostly ready to review --------- Signed-off-by: Connor Tsui <[email protected]> Signed-off-by: Robert Kruszewski <[email protected]> Co-authored-by: Robert Kruszewski <[email protected]>
1 parent 5722312 commit 4c7589c

66 files changed

Lines changed: 1142 additions & 412 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎encodings/bytebool/src/array.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl CanonicalVTable<ByteBoolVTable> for ByteBoolVTable {
116116
fn canonicalize(array: &ByteBoolArray) -> Canonical {
117117
let boolean_buffer = BooleanBuffer::from(array.as_slice());
118118
let validity = array.validity().clone();
119-
Canonical::Bool(BoolArray::new(boolean_buffer, validity))
119+
Canonical::Bool(BoolArray::from_bool_buffer(boolean_buffer, validity))
120120
}
121121
}
122122

‎encodings/datetime-parts/src/compute/cast.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mod tests {
7070
#[case(Validity::NonNullable, Nullability::NonNullable)]
7171
#[case(Validity::AllValid, Nullability::NonNullable)]
7272
#[case(Validity::from_iter([true, true, true]), Nullability::Nullable)]
73-
fn test_cast_to_compatibile_nullability(
73+
fn test_cast_to_compatible_nullability(
7474
#[case] validity: Validity,
7575
#[case] cast_to_nullability: Nullability,
7676
) {

‎encodings/decimal-byte-parts/src/decimal_byte_parts/mod.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,15 @@ impl CanonicalVTable<DecimalBytePartsVTable> for DecimalBytePartsVTable {
121121
// the correct buffer size
122122

123123
match_each_signed_integer_ptype!(prim.ptype(), |P| {
124-
Canonical::Decimal(DecimalArray::new(
125-
prim.buffer::<P>(),
126-
*array.decimal_dtype(),
127-
prim.validity().clone(),
128-
))
124+
// SAFETY: The primitive array's buffer is already validated with correct type.
125+
// The decimal dtype matches the array's dtype, and validity is preserved.
126+
Canonical::Decimal(unsafe {
127+
DecimalArray::new_unchecked(
128+
prim.buffer::<P>(),
129+
*array.decimal_dtype(),
130+
prim.validity().clone(),
131+
)
132+
})
129133
})
130134
}
131135
}

‎encodings/dict/src/builders/primitive.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,15 @@ where
142142
unsafe { codes.push_unchecked(code) }
143143
}
144144
})?;
145+
145146
PrimitiveArray::new(codes, Validity::NonNullable)
146147
};
147148

148149
Ok(codes.into_array())
149150
}
150151

151152
fn values(&mut self) -> VortexResult<ArrayRef> {
152-
Ok(PrimitiveArray::new(self.values.clone().freeze(), self.nullability.into()).into_array())
153+
Ok(PrimitiveArray::new(self.values.clone(), self.nullability.into()).into_array())
153154
}
154155
}
155156

‎encodings/fastlanes/src/delta/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub struct DeltaEncoding;
8484
/// may be less than the number of physically stored values.
8585
///
8686
/// Each chunk is stored as a vector of bases and a vector of deltas. If the chunk physically
87-
/// contains 1,024 vlaues, then there are as many bases as there are _lanes_ of this type in a
87+
/// contains 1,024 values, then there are as many bases as there are _lanes_ of this type in a
8888
/// 1024-bit register. For example, for 64-bit values, there are 16 bases because there are 16
8989
/// _lanes_. Each lane is a [delta-encoding](https://en.wikipedia.org/wiki/Delta_encoding) `1024 /
9090
/// bit_width` long vector of values. The deltas are stored in the

‎encodings/fsst/src/compute/compare.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn compare_fsst_constant(
6666
};
6767

6868
return Ok(Some(
69-
BoolArray::new(
69+
BoolArray::from_bool_buffer(
7070
buffer,
7171
Validity::copy_from_array(left.as_ref())
7272
.union_nullability(right.dtype().nullability()),

‎encodings/runend/src/compress.rs‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,9 +247,11 @@ pub fn runend_decode_typed_bool(
247247
for (end, value) in run_ends.zip_eq(values.iter()) {
248248
decoded.append_n(end - decoded.len(), value);
249249
}
250-
BoolArray::new(decoded.finish(), values_nullability.into())
250+
BoolArray::from_bool_buffer(decoded.finish(), values_nullability.into())
251+
}
252+
Mask::AllFalse(_) => {
253+
BoolArray::from_bool_buffer(BooleanBuffer::new_unset(length), Validity::AllInvalid)
251254
}
252-
Mask::AllFalse(_) => BoolArray::new(BooleanBuffer::new_unset(length), Validity::AllInvalid),
253255
Mask::Values(mask) => {
254256
let mut decoded = BooleanBufferBuilder::new(length);
255257
let mut decoded_validity = BooleanBufferBuilder::new(length);
@@ -270,7 +272,7 @@ pub fn runend_decode_typed_bool(
270272
}
271273
}
272274
}
273-
BoolArray::new(decoded.finish(), Validity::from(decoded_validity.finish()))
275+
BoolArray::from_bool_buffer(decoded.finish(), Validity::from(decoded_validity.finish()))
274276
}
275277
}
276278
}

‎encodings/sequence/src/compute/compare.rs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ impl CompareKernel for SequenceVTable {
4646

4747
if let Some(set_idx) = set_idx {
4848
let buffer = BooleanBuffer::from_iter((0..lhs.len()).map(|idx| idx == set_idx));
49-
Ok(Some(BoolArray::new(buffer, validity).to_array()))
49+
Ok(Some(
50+
BoolArray::from_bool_buffer(buffer, validity).to_array(),
51+
))
5052
} else {
5153
Ok(Some(
5254
ConstantArray::new(

‎encodings/sparse/src/canonical.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ fn canonicalize_sparse_bools(patches: &Patches, fill_value: &Scalar) -> Canonica
389389
)
390390
};
391391

392-
let bools = BoolArray::new(
392+
let bools = BoolArray::from_bool_buffer(
393393
if fill_bool {
394394
BooleanBuffer::new_set(patches.array_len())
395395
} else {
@@ -642,7 +642,7 @@ mod test {
642642
buffer.append(maybe_bool.unwrap_or_else(|| fill_value.unwrap_or_default()));
643643
validity.append(maybe_bool.is_some());
644644
}
645-
BoolArray::new(buffer.finish(), Validity::from(validity.finish()))
645+
BoolArray::from_bool_buffer(buffer.finish(), Validity::from(validity.finish()))
646646
}
647647

648648
#[rstest]

‎fuzz/src/array/compare.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ pub fn compare_canonical_array(
2020
operator: Operator,
2121
) -> VortexResult<ArrayRef> {
2222
if value.is_null() {
23-
return Ok(
24-
BoolArray::new(BooleanBuffer::new_unset(array.len()), Validity::AllInvalid)
25-
.into_array(),
26-
);
23+
return Ok(BoolArray::from_bool_buffer(
24+
BooleanBuffer::new_unset(array.len()),
25+
Validity::AllInvalid,
26+
)
27+
.into_array());
2728
}
2829

2930
match array.dtype() {

0 commit comments

Comments
 (0)