Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

Change signature of PrimitiveScalar::value to return reference #1129

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compute/arithmetics/decimal/div.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ pub fn div(lhs: &PrimitiveArray<i128>, rhs: &PrimitiveArray<i128>) -> PrimitiveA
pub fn div_scalar(lhs: &PrimitiveArray<i128>, rhs: &PrimitiveScalar<i128>) -> PrimitiveArray<i128> {
let (precision, scale) = get_parameters(lhs.data_type(), rhs.data_type()).unwrap();

let rhs = if let Some(rhs) = rhs.value() {
let rhs = if let Some(rhs) = *rhs.value() {
rhs
} else {
return PrimitiveArray::<i128>::new_null(lhs.data_type().clone(), lhs.len());
Expand Down
2 changes: 1 addition & 1 deletion src/compute/arithmetics/decimal/mul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn mul(lhs: &PrimitiveArray<i128>, rhs: &PrimitiveArray<i128>) -> PrimitiveA
pub fn mul_scalar(lhs: &PrimitiveArray<i128>, rhs: &PrimitiveScalar<i128>) -> PrimitiveArray<i128> {
let (precision, scale) = get_parameters(lhs.data_type(), rhs.data_type()).unwrap();

let rhs = if let Some(rhs) = rhs.value() {
let rhs = if let Some(rhs) = *rhs.value() {
rhs
} else {
return PrimitiveArray::<i128>::new_null(lhs.data_type().clone(), lhs.len());
Expand Down
2 changes: 1 addition & 1 deletion src/compute/arithmetics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn binary_scalar<T: NativeType, F: Fn(&PrimitiveArray<T>, &T) -> PrimitiveArray<
rhs: &PrimitiveScalar<T>,
op: F,
) -> PrimitiveArray<T> {
let rhs = if let Some(rhs) = rhs.value() {
let rhs = if let Some(rhs) = *rhs.value() {
rhs
} else {
return PrimitiveArray::<T>::new_null(lhs.data_type().clone(), lhs.len());
Expand Down
8 changes: 4 additions & 4 deletions src/compute/arithmetics/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ where
T: NativeType + Add<T, Output = T>,
{
let scale = create_scale(time.data_type(), duration.data_type()).unwrap();
let duration = if let Some(duration) = duration.value() {
let duration = if let Some(duration) = *duration.value() {
duration
} else {
return PrimitiveArray::<T>::new_null(time.data_type().clone(), time.len());
Expand Down Expand Up @@ -211,7 +211,7 @@ where
T: NativeType + Sub<T, Output = T>,
{
let scale = create_scale(time.data_type(), duration.data_type()).unwrap();
let duration = if let Some(duration) = duration.value() {
let duration = if let Some(duration) = *duration.value() {
duration
} else {
return PrimitiveArray::<T>::new_null(time.data_type().clone(), time.len());
Expand Down Expand Up @@ -297,7 +297,7 @@ pub fn sub_timestamps_scalar(
));
};

let rhs = if let Some(value) = rhs.value() {
let rhs = if let Some(value) = *rhs.value() {
value
} else {
return Ok(PrimitiveArray::<i64>::new_null(
Expand Down Expand Up @@ -374,7 +374,7 @@ pub fn add_interval_scalar(
timestamp: &PrimitiveArray<i64>,
interval: &PrimitiveScalar<months_days_ns>,
) -> Result<PrimitiveArray<i64>> {
let interval = if let Some(interval) = interval.value() {
let interval = if let Some(interval) = *interval.value() {
interval
} else {
return Ok(PrimitiveArray::<i64>::new_null(
Expand Down
4 changes: 2 additions & 2 deletions src/scalar/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ impl<T: NativeType> PrimitiveScalar<T> {

/// Returns the optional value.
#[inline]
pub fn value(&self) -> Option<T> {
self.value
pub fn value(&self) -> &Option<T> {
&self.value
}

/// Returns a new `PrimitiveScalar` with the same value but different [`DataType`]
Expand Down
16 changes: 8 additions & 8 deletions tests/it/array/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ fn iter_sparse() -> Result<()> {

assert_eq!(
next_unchecked::<PrimitiveScalar<i32>, _>(&mut iter).value(),
Some(1)
&Some(1)
);
assert_eq!(
next_unchecked::<PrimitiveScalar<i32>, _>(&mut iter).value(),
None
&None
);
assert_eq!(
next_unchecked::<Utf8Scalar<i32>, _>(&mut iter).value(),
Expand Down Expand Up @@ -140,11 +140,11 @@ fn iter_dense() -> Result<()> {

assert_eq!(
next_unchecked::<PrimitiveScalar<i32>, _>(&mut iter).value(),
Some(1)
&Some(1)
);
assert_eq!(
next_unchecked::<PrimitiveScalar<i32>, _>(&mut iter).value(),
None
&None
);
assert_eq!(
next_unchecked::<Utf8Scalar<i32>, _>(&mut iter).value(),
Expand Down Expand Up @@ -174,7 +174,7 @@ fn iter_sparse_slice() -> Result<()> {

assert_eq!(
next_unchecked::<PrimitiveScalar<i32>, _>(&mut iter).value(),
Some(3)
&Some(3)
);
assert_eq!(iter.next(), None);

Expand All @@ -201,7 +201,7 @@ fn iter_dense_slice() -> Result<()> {

assert_eq!(
next_unchecked::<PrimitiveScalar<i32>, _>(&mut iter).value(),
Some(3)
&Some(3)
);
assert_eq!(iter.next(), None);

Expand Down Expand Up @@ -233,7 +233,7 @@ fn scalar() -> Result<()> {
.downcast_ref::<PrimitiveScalar<i32>>()
.unwrap()
.value(),
Some(1)
&Some(1)
);
assert_eq!(union_scalar.type_(), 0);
let scalar = new_scalar(&array, 1);
Expand All @@ -245,7 +245,7 @@ fn scalar() -> Result<()> {
.downcast_ref::<PrimitiveScalar<i32>>()
.unwrap()
.value(),
None
&None
);
assert_eq!(union_scalar.type_(), 0);

Expand Down
2 changes: 1 addition & 1 deletion tests/it/scalar/primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn equal() {
fn basics() {
let a = PrimitiveScalar::from(Some(2i32));

assert_eq!(a.value(), Some(2i32));
assert_eq!(a.value(), &Some(2i32));
assert_eq!(a.data_type(), &DataType::Int32);

let a = a.to(DataType::Date32);
Expand Down