Skip to content

Commit 6855f2b

Browse files
authored
fix: address clippy collapsible_match warnings (#3863)
## Which issue does this PR close? Closes #3862. ## Rationale for this change Although this `collapsible_match` error happens on a nightly version (1.96.0), I'm making the PR since they need to be fixed anyway. ## What changes are included in this PR? Collapse `if` into outer `match` to fix clippy error. ## How are these changes tested? Existing tests.
1 parent 423b572 commit 6855f2b

2 files changed

Lines changed: 17 additions & 41 deletions

File tree

native/core/src/execution/columnar_to_row.rs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -286,13 +286,7 @@ impl<'a> TypedArray<'a> {
286286
#[inline]
287287
fn get_fixed_value(&self, row_idx: usize) -> i64 {
288288
match self {
289-
TypedArray::Boolean(arr) => {
290-
if arr.value(row_idx) {
291-
1i64
292-
} else {
293-
0i64
294-
}
295-
}
289+
TypedArray::Boolean(arr) => arr.value(row_idx) as i64,
296290
TypedArray::Int8(arr) => arr.value(row_idx) as i64,
297291
TypedArray::Int16(arr) => arr.value(row_idx) as i64,
298292
TypedArray::Int32(arr) => arr.value(row_idx) as i64,
@@ -301,13 +295,10 @@ impl<'a> TypedArray<'a> {
301295
TypedArray::Float64(arr) => arr.value(row_idx).to_bits() as i64,
302296
TypedArray::Date32(arr) => arr.value(row_idx) as i64,
303297
TypedArray::TimestampMicro(arr) => arr.value(row_idx),
304-
TypedArray::Decimal128(arr, precision) => {
305-
if *precision <= MAX_LONG_DIGITS {
306-
arr.value(row_idx) as i64
307-
} else {
308-
0 // Variable-length decimal, handled elsewhere
309-
}
298+
TypedArray::Decimal128(arr, precision) if *precision <= MAX_LONG_DIGITS => {
299+
arr.value(row_idx) as i64
310300
}
301+
TypedArray::Decimal128(_, _) => 0, // Variable-length decimal, handled elsewhere
311302
// Variable-length types return 0, actual value written separately
312303
_ => 0,
313304
}
@@ -521,13 +512,7 @@ impl<'a> TypedElements<'a> {
521512
#[inline]
522513
fn get_fixed_value(&self, idx: usize) -> i64 {
523514
match self {
524-
TypedElements::Boolean(arr) => {
525-
if arr.value(idx) {
526-
1
527-
} else {
528-
0
529-
}
530-
}
515+
TypedElements::Boolean(arr) => arr.value(idx) as i64,
531516
TypedElements::Int8(arr) => arr.value(idx) as i64,
532517
TypedElements::Int16(arr) => arr.value(idx) as i64,
533518
TypedElements::Int32(arr) => arr.value(idx) as i64,
@@ -1353,7 +1338,7 @@ fn get_field_value(data_type: &DataType, array: &ArrayRef, row_idx: usize) -> Co
13531338
match actual_type {
13541339
DataType::Boolean => {
13551340
let arr = downcast_array!(array, BooleanArray)?;
1356-
Ok(if arr.value(row_idx) { 1i64 } else { 0i64 })
1341+
Ok(arr.value(row_idx) as i64)
13571342
}
13581343
DataType::Int8 => get_field_value_primitive!(array, row_idx, Int8Array, |v: i8| v as i64),
13591344
DataType::Int16 => {

native/spark-expr/src/math_funcs/negative.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -158,25 +158,17 @@ impl PhysicalExpr for NegativeExpr {
158158
ColumnarValue::Scalar(scalar) => {
159159
if self.fail_on_error {
160160
match scalar {
161-
ScalarValue::Int8(value) => {
162-
if value == Some(i8::MIN) {
163-
return Err(arithmetic_overflow_error(" caused").into());
164-
}
161+
ScalarValue::Int8(Some(i8::MIN)) => {
162+
return Err(arithmetic_overflow_error(" caused").into());
165163
}
166-
ScalarValue::Int16(value) => {
167-
if value == Some(i16::MIN) {
168-
return Err(arithmetic_overflow_error(" caused").into());
169-
}
164+
ScalarValue::Int16(Some(i16::MIN)) => {
165+
return Err(arithmetic_overflow_error(" caused").into());
170166
}
171-
ScalarValue::Int32(value) => {
172-
if value == Some(i32::MIN) {
173-
return Err(arithmetic_overflow_error("integer").into());
174-
}
167+
ScalarValue::Int32(Some(i32::MIN)) => {
168+
return Err(arithmetic_overflow_error("integer").into());
175169
}
176-
ScalarValue::Int64(value) => {
177-
if value == Some(i64::MIN) {
178-
return Err(arithmetic_overflow_error("long").into());
179-
}
170+
ScalarValue::Int64(Some(i64::MIN)) => {
171+
return Err(arithmetic_overflow_error("long").into());
180172
}
181173
ScalarValue::IntervalDayTime(value) => {
182174
let (days, ms) =
@@ -185,11 +177,10 @@ impl PhysicalExpr for NegativeExpr {
185177
return Err(arithmetic_overflow_error("interval").into());
186178
}
187179
}
188-
ScalarValue::IntervalYearMonth(value) => {
189-
if value == Some(i32::MIN) {
190-
return Err(arithmetic_overflow_error("interval").into());
191-
}
180+
ScalarValue::IntervalYearMonth(Some(i32::MIN)) => {
181+
return Err(arithmetic_overflow_error("interval").into());
192182
}
183+
ScalarValue::IntervalYearMonth(_) => {}
193184
_ => {
194185
// Overflow checks are not supported for other datatypes
195186
}

0 commit comments

Comments
 (0)