Skip to content

Commit 0ee15dc

Browse files
committed
remove Scalar::new
Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
1 parent 1ac4583 commit 0ee15dc

43 files changed

Lines changed: 313 additions & 214 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.

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

encodings/decimal-byte-parts/src/decimal_byte_parts/compute/compare.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ impl CompareKernel for DecimalBytePartsVTable {
4646
.vortex_expect("checked for null in entry func");
4747

4848
match decimal_value_wrapper_to_primitive(rhs_decimal, lhs.msp.as_primitive_typed().ptype())
49-
.map(|value| Scalar::new(scalar_type.clone(), Some(value)))
5049
{
51-
Ok(encoded_scalar) => {
50+
Ok(value) => {
51+
let encoded_scalar = Scalar::try_new(scalar_type, Some(value))?;
5252
let encoded_const = ConstantArray::new(encoded_scalar, rhs.len());
5353
compare(&lhs.msp, &encoded_const.to_array(), operator).map(Some)
5454
}
@@ -166,7 +166,7 @@ mod tests {
166166
.unwrap()
167167
.to_array();
168168
let rhs = ConstantArray::new(
169-
Scalar::new(dtype, Some(DecimalValue::I64(400).into())),
169+
Scalar::try_new(dtype, Some(DecimalValue::I64(400).into())).unwrap(),
170170
lhs.len(),
171171
);
172172

@@ -218,10 +218,11 @@ mod tests {
218218
.to_array();
219219
// This cannot be converted to a i32.
220220
let rhs = ConstantArray::new(
221-
Scalar::new(
221+
Scalar::try_new(
222222
dtype.clone(),
223223
Some(DecimalValue::I128(-9999999999999965304).into()),
224-
),
224+
)
225+
.unwrap(),
225226
lhs.len(),
226227
);
227228

@@ -239,7 +240,7 @@ mod tests {
239240

240241
// This cannot be converted to a i32.
241242
let rhs = ConstantArray::new(
242-
Scalar::new(dtype, Some(DecimalValue::I128(9999999999999965304).into())),
243+
Scalar::try_new(dtype, Some(DecimalValue::I128(9999999999999965304).into())).unwrap(),
243244
lhs.len(),
244245
);
245246

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ impl OperationsVTable<DecimalBytePartsVTable> for DecimalBytePartsVTable {
270270
let primitive_scalar = scalar.as_primitive();
271271
// TODO(joe): extend this to support multiple parts.
272272
let value = primitive_scalar.as_::<i64>().vortex_expect("non-null");
273-
Ok(Scalar::new(
273+
Scalar::try_new(
274274
array.dtype.clone(),
275275
Some(ScalarValue::Decimal(DecimalValue::I64(value))),
276-
))
276+
)
277277
}
278278
}
279279

@@ -325,14 +325,15 @@ mod tests {
325325

326326
assert_eq!(Scalar::null(dtype.clone()), array.scalar_at(0).unwrap());
327327
assert_eq!(
328-
Scalar::new(
328+
Scalar::try_new(
329329
dtype.clone(),
330330
Some(ScalarValue::Decimal(DecimalValue::I64(200)))
331-
),
331+
)
332+
.unwrap(),
332333
array.scalar_at(1).unwrap()
333334
);
334335
assert_eq!(
335-
Scalar::new(dtype, Some(ScalarValue::Decimal(DecimalValue::I64(400)))),
336+
Scalar::try_new(dtype, Some(ScalarValue::Decimal(DecimalValue::I64(400)))).unwrap(),
336337
array.scalar_at(2).unwrap()
337338
);
338339
}

encodings/fastlanes/src/for/vtable/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl VTable for FoRVTable {
9696

9797
let encoded = children.get(0, dtype, len)?;
9898
let scalar_value = ScalarValue::from_proto_bytes(metadata, dtype)?;
99-
let reference = Scalar::new(dtype.clone(), Some(scalar_value));
99+
let reference = Scalar::try_new(dtype.clone(), Some(scalar_value))?;
100100

101101
FoRArray::try_new(encoded, reference)
102102
}

encodings/fastlanes/src/rle/vtable/operations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ impl OperationsVTable<RLEVTable> for RLEVTable {
2727
.values()
2828
.scalar_at(value_idx_offset + chunk_relative_idx)?;
2929

30-
Ok(Scalar::new(array.dtype().clone(), scalar.into_value()))
30+
Scalar::try_new(array.dtype().clone(), scalar.into_value())
3131
}
3232
}
3333

encodings/sequence/src/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ impl BaseArrayVTable<SequenceVTable> for SequenceVTable {
347347

348348
impl OperationsVTable<SequenceVTable> for SequenceVTable {
349349
fn scalar_at(array: &SequenceArray, index: usize) -> VortexResult<Scalar> {
350-
Ok(Scalar::new(
350+
Scalar::try_new(
351351
array.dtype().clone(),
352352
Some(ScalarValue::Primitive(array.index_value(index))),
353-
))
353+
)
354354
}
355355
}
356356

@@ -415,7 +415,7 @@ mod tests {
415415

416416
assert_eq!(
417417
scalar,
418-
Scalar::new(scalar.dtype().clone(), Some(ScalarValue::from(8i64)))
418+
Scalar::try_new(scalar.dtype().clone(), Some(ScalarValue::from(8i64))).unwrap()
419419
)
420420
}
421421

encodings/sequence/src/compute/cast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,14 @@ impl CastKernel for SequenceVTable {
4848
// For type changes, we need to cast the base and multiplier
4949
if array.ptype() != *target_ptype {
5050
// Create scalars from PValues and cast them
51-
let base_scalar = Scalar::new(
51+
let base_scalar = Scalar::try_new(
5252
DType::Primitive(array.ptype(), Nullability::NonNullable),
5353
Some(ScalarValue::Primitive(array.base())),
54-
);
55-
let multiplier_scalar = Scalar::new(
54+
)?;
55+
let multiplier_scalar = Scalar::try_new(
5656
DType::Primitive(array.ptype(), Nullability::NonNullable),
5757
Some(ScalarValue::Primitive(array.multiplier())),
58-
);
58+
)?;
5959

6060
let new_base_scalar =
6161
base_scalar.cast(&DType::Primitive(*target_ptype, Nullability::NonNullable))?;

encodings/sequence/src/kernel.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,11 @@ mod tests {
349349
fn test_sequence_gte_constant() -> VortexResult<()> {
350350
let seq = SequenceArray::typed_new(0i64, 1, NonNullable, 10)?.to_array();
351351
let constant = ConstantArray::new(
352-
Scalar::new(
352+
Scalar::try_new(
353353
DType::Primitive(PType::I64, Nullability::Nullable),
354354
Some(5i64.into()),
355-
),
355+
)
356+
.unwrap(),
356357
10,
357358
)
358359
.to_array();

vortex-array/src/array/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,8 @@ impl<V: VTable> Array for ArrayAdapter<V> {
452452
stat,
453453
Stat::IsConstant | Stat::IsSorted | Stat::IsStrictSorted
454454
) && value.as_ref().as_exact().is_some_and(|v| {
455-
Scalar::new(DType::Bool(Nullability::NonNullable), Some(v.clone()))
455+
Scalar::try_new(DType::Bool(Nullability::NonNullable), Some(v.clone()))
456+
.vortex_expect("A stat that was expected to be a boolean stat was not")
456457
.as_bool()
457458
.value()
458459
.unwrap_or_default()

vortex-array/src/arrays/constant/compute/sum.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl SumKernel for ConstantVTable {
3535
.ok_or_else(|| vortex_err!("Sum not supported for dtype {}", array.dtype()))?;
3636

3737
let sum_value = sum_scalar(array.scalar(), array.len(), accumulator)?;
38-
Ok(Scalar::new(sum_dtype, sum_value))
38+
Scalar::try_new(sum_dtype, sum_value)
3939
}
4040
}
4141

0 commit comments

Comments
 (0)