Skip to content

Commit cd8ea9d

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

44 files changed

Lines changed: 313 additions & 215 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
@@ -276,10 +276,10 @@ impl OperationsVTable<DecimalBytePartsVTable> for DecimalBytePartsVTable {
276276
let primitive_scalar = scalar.as_primitive();
277277
// TODO(joe): extend this to support multiple parts.
278278
let value = primitive_scalar.as_::<i64>().vortex_expect("non-null");
279-
Ok(Scalar::new(
279+
Scalar::try_new(
280280
array.dtype.clone(),
281281
Some(ScalarValue::Decimal(DecimalValue::I64(value))),
282-
))
282+
)
283283
}
284284
}
285285

@@ -331,14 +331,15 @@ mod tests {
331331

332332
assert_eq!(Scalar::null(dtype.clone()), array.scalar_at(0).unwrap());
333333
assert_eq!(
334-
Scalar::new(
334+
Scalar::try_new(
335335
dtype.clone(),
336336
Some(ScalarValue::Decimal(DecimalValue::I64(200)))
337-
),
337+
)
338+
.unwrap(),
338339
array.scalar_at(1).unwrap()
339340
);
340341
assert_eq!(
341-
Scalar::new(dtype, Some(ScalarValue::Decimal(DecimalValue::I64(400)))),
342+
Scalar::try_new(dtype, Some(ScalarValue::Decimal(DecimalValue::I64(400)))).unwrap(),
342343
array.scalar_at(2).unwrap()
343344
);
344345
}

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

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

102102
let encoded = children.get(0, dtype, len)?;
103103
let scalar_value = ScalarValue::from_proto_bytes(metadata, dtype)?;
104-
let reference = Scalar::new(dtype.clone(), Some(scalar_value));
104+
let reference = Scalar::try_new(dtype.clone(), Some(scalar_value))?;
105105

106106
FoRArray::try_new(encoded, reference)
107107
}

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
@@ -353,10 +353,10 @@ impl BaseArrayVTable<SequenceVTable> for SequenceVTable {
353353

354354
impl OperationsVTable<SequenceVTable> for SequenceVTable {
355355
fn scalar_at(array: &SequenceArray, index: usize) -> VortexResult<Scalar> {
356-
Ok(Scalar::new(
356+
Scalar::try_new(
357357
array.dtype().clone(),
358358
Some(ScalarValue::Primitive(array.index_value(index))),
359-
))
359+
)
360360
}
361361
}
362362

@@ -421,7 +421,7 @@ mod tests {
421421

422422
assert_eq!(
423423
scalar,
424-
Scalar::new(scalar.dtype().clone(), Some(ScalarValue::from(8i64)))
424+
Scalar::try_new(scalar.dtype().clone(), Some(ScalarValue::from(8i64))).unwrap()
425425
)
426426
}
427427

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)