Skip to content
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
5 changes: 2 additions & 3 deletions arrow-arith/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ fn get_fixed_point_info(

if required_scale > product_scale {
return Err(ArrowError::ComputeError(format!(
"Required scale {} is greater than product scale {}",
required_scale, product_scale
"Required scale {required_scale} is greater than product scale {product_scale}",
)));
}

Expand Down Expand Up @@ -122,7 +121,7 @@ pub fn multiply_fixed_point_checked(
let mut mul = a.wrapping_mul(b);
mul = divide_and_round::<Decimal256Type>(mul, divisor);
mul.to_i128().ok_or_else(|| {
ArrowError::ArithmeticOverflow(format!("Overflow happened on: {:?} * {:?}", a, b))
ArrowError::ArithmeticOverflow(format!("Overflow happened on: {a:?} * {b:?}"))
})
})
.and_then(|a| a.with_precision_and_scale(precision, required_scale))
Expand Down
18 changes: 6 additions & 12 deletions arrow-arith/src/numeric.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,10 +574,7 @@ impl DateOp for Date32Type {
impl DateOp for Date64Type {
fn add_year_month(left: Self::Native, right: i32) -> Result<Self::Native, ArrowError> {
Self::add_year_months_opt(left, right).ok_or_else(|| {
ArrowError::ComputeError(format!(
"Date arithmetic overflow: {} + {} months",
left, right
))
ArrowError::ComputeError(format!("Date arithmetic overflow: {left} + {right} months",))
})
}

Expand All @@ -586,7 +583,7 @@ impl DateOp for Date64Type {
right: IntervalDayTime,
) -> Result<Self::Native, ArrowError> {
Self::add_day_time_opt(left, right).ok_or_else(|| {
ArrowError::ComputeError(format!("Date arithmetic overflow: {} + {:?}", left, right))
ArrowError::ComputeError(format!("Date arithmetic overflow: {left} + {right:?}"))
})
}

Expand All @@ -595,16 +592,13 @@ impl DateOp for Date64Type {
right: IntervalMonthDayNano,
) -> Result<Self::Native, ArrowError> {
Self::add_month_day_nano_opt(left, right).ok_or_else(|| {
ArrowError::ComputeError(format!("Date arithmetic overflow: {} + {:?}", left, right))
ArrowError::ComputeError(format!("Date arithmetic overflow: {left} + {right:?}"))
})
}

fn sub_year_month(left: Self::Native, right: i32) -> Result<Self::Native, ArrowError> {
Self::subtract_year_months_opt(left, right).ok_or_else(|| {
ArrowError::ComputeError(format!(
"Date arithmetic overflow: {} - {} months",
left, right
))
ArrowError::ComputeError(format!("Date arithmetic overflow: {left} - {right} months",))
})
}

Expand All @@ -613,7 +607,7 @@ impl DateOp for Date64Type {
right: IntervalDayTime,
) -> Result<Self::Native, ArrowError> {
Self::subtract_day_time_opt(left, right).ok_or_else(|| {
ArrowError::ComputeError(format!("Date arithmetic overflow: {} - {:?}", left, right))
ArrowError::ComputeError(format!("Date arithmetic overflow: {left} - {right:?}"))
})
}

Expand All @@ -622,7 +616,7 @@ impl DateOp for Date64Type {
right: IntervalMonthDayNano,
) -> Result<Self::Native, ArrowError> {
Self::subtract_month_day_nano_opt(left, right).ok_or_else(|| {
ArrowError::ComputeError(format!("Date arithmetic overflow: {} - {:?}", left, right))
ArrowError::ComputeError(format!("Date arithmetic overflow: {left} - {right:?}"))
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion arrow-arith/src/temporal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub enum DatePart {

impl std::fmt::Display for DatePart {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
write!(f, "{self:?}")
}
}

Expand Down
28 changes: 24 additions & 4 deletions arrow-array/src/arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,35 @@ native_type_float_op!(
f32,
0.,
1.,
unsafe { std::mem::transmute(-1_i32) },
unsafe { std::mem::transmute(i32::MAX) }
unsafe {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't remove the transmute here yet because the MSRV is too low (needs to be 1.87 before we can remove the transmute)

// Need to allow in clippy because
// current MSRV (Minimum Supported Rust Version) is `1.81.0` but this item is stable since `1.87.0`
#[allow(unnecessary_transmutes)]
std::mem::transmute(-1_i32)
},
unsafe {
// Need to allow in clippy because
// current MSRV (Minimum Supported Rust Version) is `1.81.0` but this item is stable since `1.87.0`
#[allow(unnecessary_transmutes)]
std::mem::transmute(i32::MAX)
}
);
native_type_float_op!(
f64,
0.,
1.,
unsafe { std::mem::transmute(-1_i64) },
unsafe { std::mem::transmute(i64::MAX) }
unsafe {
// Need to allow in clippy because
// current MSRV (Minimum Supported Rust Version) is `1.81.0` but this item is stable since `1.87.0`
#[allow(unnecessary_transmutes)]
std::mem::transmute(-1_i64)
},
unsafe {
// Need to allow in clippy because
// current MSRV (Minimum Supported Rust Version) is `1.81.0` but this item is stable since `1.87.0`
#[allow(unnecessary_transmutes)]
std::mem::transmute(i64::MAX)
}
);

#[cfg(test)]
Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/array/fixed_size_binary_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl FixedSizeBinaryArray {
) -> Result<Self, ArrowError> {
let data_type = DataType::FixedSizeBinary(size);
let s = size.to_usize().ok_or_else(|| {
ArrowError::InvalidArgumentError(format!("Size cannot be negative, got {}", size))
ArrowError::InvalidArgumentError(format!("Size cannot be negative, got {size}"))
})?;

let len = values.len() / s;
Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/array/fixed_size_list_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ impl FixedSizeListArray {
nulls: Option<NullBuffer>,
) -> Result<Self, ArrowError> {
let s = size.to_usize().ok_or_else(|| {
ArrowError::InvalidArgumentError(format!("Size cannot be negative, got {}", size))
ArrowError::InvalidArgumentError(format!("Size cannot be negative, got {size}"))
})?;

let len = match s {
Expand Down
12 changes: 6 additions & 6 deletions arrow-array/src/array/primitive_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ mod tests {
.with_timezone("Asia/Taipei".to_string());
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"Asia/Taipei\"))>\n[\n 2018-12-31T08:00:00+08:00,\n 2018-12-31T08:00:00+08:00,\n 1921-01-02T08:00:00+08:00,\n]",
format!("{:?}", arr)
format!("{arr:?}")
);
}

Expand Down Expand Up @@ -2067,7 +2067,7 @@ mod tests {
.with_timezone("America/Denver".to_string());
assert_eq!(
"PrimitiveArray<Timestamp(Millisecond, Some(\"America/Denver\"))>\n[\n 2022-03-13T01:59:59-07:00,\n 2022-03-13T03:00:00-06:00,\n 2022-11-06T00:59:59-06:00,\n 2022-11-06T01:00:00-06:00,\n]",
format!("{:?}", arr)
format!("{arr:?}")
);
}

Expand Down Expand Up @@ -2641,7 +2641,7 @@ mod tests {
None,
]
.into();
let debug_str = format!("{:?}", array);
let debug_str = format!("{array:?}");
assert_eq!("PrimitiveArray<Time32(Second)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(Second),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400 to temporal for Time32(Second),\n Cast error: Failed to convert 86401 to temporal for Time32(Second),\n null,\n]",
debug_str
);
Expand All @@ -2658,7 +2658,7 @@ mod tests {
None,
]
.into();
let debug_str = format!("{:?}", array);
let debug_str = format!("{array:?}");
assert_eq!("PrimitiveArray<Time32(Millisecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time32(Millisecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000 to temporal for Time32(Millisecond),\n Cast error: Failed to convert 86401000 to temporal for Time32(Millisecond),\n null,\n]",
debug_str
);
Expand All @@ -2675,7 +2675,7 @@ mod tests {
None,
]
.into();
let debug_str = format!("{:?}", array);
let debug_str = format!("{array:?}");
assert_eq!(
"PrimitiveArray<Time64(Nanosecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(Nanosecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000000 to temporal for Time64(Nanosecond),\n Cast error: Failed to convert 86401000000000 to temporal for Time64(Nanosecond),\n null,\n]",
debug_str
Expand All @@ -2693,7 +2693,7 @@ mod tests {
None,
]
.into();
let debug_str = format!("{:?}", array);
let debug_str = format!("{array:?}");
assert_eq!("PrimitiveArray<Time64(Microsecond)>\n[\n Cast error: Failed to convert -1 to temporal for Time64(Microsecond),\n 00:00:00,\n 23:59:59,\n Cast error: Failed to convert 86400000000 to temporal for Time64(Microsecond),\n Cast error: Failed to convert 86401000000 to temporal for Time64(Microsecond),\n null,\n]", debug_str);
}

Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/array/union_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ impl std::fmt::Debug for UnionArray {

if let Some(offsets) = &self.offsets {
writeln!(f, "-- offsets buffer:")?;
writeln!(f, "{:?}", offsets)?;
writeln!(f, "{offsets:?}")?;
}

let fields = match self.data_type() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ mod tests {
fn test_try_new_from_builder_cast_fails() {
let mut source_builder = StringDictionaryBuilder::<UInt16Type>::new();
for i in 0..257 {
source_builder.append_value(format!("val{}", i));
source_builder.append_value(format!("val{i}"));
}

// there should be too many values that we can't downcast to the underlying type
Expand Down
2 changes: 1 addition & 1 deletion arrow-array/src/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,7 @@ mod tests_from_ffi {
let mut strings = vec![];

for i in 0..1000 {
strings.push(format!("string: {}", i));
strings.push(format!("string: {i}"));
}

let string_array = StringArray::from(strings);
Expand Down
28 changes: 6 additions & 22 deletions arrow-array/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,10 +1077,7 @@ impl Date64Type {
delta: <IntervalYearMonthType as ArrowPrimitiveType>::Native,
) -> <Date64Type as ArrowPrimitiveType>::Native {
Self::add_year_months_opt(date, delta).unwrap_or_else(|| {
panic!(
"Date64Type::add_year_months overflowed for date: {}, delta: {}",
date, delta
)
panic!("Date64Type::add_year_months overflowed for date: {date}, delta: {delta}",)
})
}

Expand Down Expand Up @@ -1117,10 +1114,7 @@ impl Date64Type {
delta: <IntervalDayTimeType as ArrowPrimitiveType>::Native,
) -> <Date64Type as ArrowPrimitiveType>::Native {
Self::add_day_time_opt(date, delta).unwrap_or_else(|| {
panic!(
"Date64Type::add_day_time overflowed for date: {}, delta: {:?}",
date, delta
)
panic!("Date64Type::add_day_time overflowed for date: {date}, delta: {delta:?}",)
})
}

Expand Down Expand Up @@ -1158,10 +1152,7 @@ impl Date64Type {
delta: <IntervalMonthDayNanoType as ArrowPrimitiveType>::Native,
) -> <Date64Type as ArrowPrimitiveType>::Native {
Self::add_month_day_nano_opt(date, delta).unwrap_or_else(|| {
panic!(
"Date64Type::add_month_day_nano overflowed for date: {}, delta: {:?}",
date, delta
)
panic!("Date64Type::add_month_day_nano overflowed for date: {date}, delta: {delta:?}",)
})
}

Expand Down Expand Up @@ -1200,10 +1191,7 @@ impl Date64Type {
delta: <IntervalYearMonthType as ArrowPrimitiveType>::Native,
) -> <Date64Type as ArrowPrimitiveType>::Native {
Self::subtract_year_months_opt(date, delta).unwrap_or_else(|| {
panic!(
"Date64Type::subtract_year_months overflowed for date: {}, delta: {}",
date, delta
)
panic!("Date64Type::subtract_year_months overflowed for date: {date}, delta: {delta}",)
})
}

Expand Down Expand Up @@ -1240,10 +1228,7 @@ impl Date64Type {
delta: <IntervalDayTimeType as ArrowPrimitiveType>::Native,
) -> <Date64Type as ArrowPrimitiveType>::Native {
Self::subtract_day_time_opt(date, delta).unwrap_or_else(|| {
panic!(
"Date64Type::subtract_day_time overflowed for date: {}, delta: {:?}",
date, delta
)
panic!("Date64Type::subtract_day_time overflowed for date: {date}, delta: {delta:?}",)
})
}

Expand Down Expand Up @@ -1282,8 +1267,7 @@ impl Date64Type {
) -> <Date64Type as ArrowPrimitiveType>::Native {
Self::subtract_month_day_nano_opt(date, delta).unwrap_or_else(|| {
panic!(
"Date64Type::subtract_month_day_nano overflowed for date: {}, delta: {:?}",
date, delta
"Date64Type::subtract_month_day_nano overflowed for date: {date}, delta: {delta:?}",
)
})
}
Expand Down
16 changes: 8 additions & 8 deletions arrow-avro/benches/avro_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use tempfile::NamedTempFile;

fn create_test_data(count: usize, str_length: usize) -> Vec<String> {
(0..count)
.map(|i| format!("str_{}", i) + &"a".repeat(str_length))
.map(|i| format!("str_{i}") + &"a".repeat(str_length))
.collect()
}

Expand Down Expand Up @@ -101,7 +101,7 @@ fn read_avro_test_file(
reader.read_exact(&mut buf)?;

let s = String::from_utf8(buf)
.map_err(|e| ArrowError::ParseError(format!("Invalid UTF-8: {}", e)))?;
.map_err(|e| ArrowError::ParseError(format!("Invalid UTF-8: {e}")))?;

strings.push(s);

Expand Down Expand Up @@ -143,7 +143,7 @@ fn bench_array_creation(c: &mut Criterion) {
let data = create_test_data(10000, str_length);
let row_count = 1000;

group.bench_function(format!("string_array_{}_chars", str_length), |b| {
group.bench_function(format!("string_array_{str_length}_chars"), |b| {
b.iter(|| {
let string_array =
StringArray::from_iter(data[0..row_count].iter().map(|s| Some(s.as_str())));
Expand All @@ -167,7 +167,7 @@ fn bench_array_creation(c: &mut Criterion) {
})
});

group.bench_function(format!("string_view_{}_chars", str_length), |b| {
group.bench_function(format!("string_view_{str_length}_chars"), |b| {
b.iter(|| {
let string_array =
StringViewArray::from_iter(data[0..row_count].iter().map(|s| Some(s.as_str())));
Expand Down Expand Up @@ -208,7 +208,7 @@ fn bench_string_operations(c: &mut Criterion) {
let string_view_array =
StringViewArray::from_iter(data[0..rows].iter().map(|s| Some(s.as_str())));

group.bench_function(format!("string_array_value_{}_chars", str_length), |b| {
group.bench_function(format!("string_array_value_{str_length}_chars"), |b| {
b.iter(|| {
let mut sum_len = 0;
for i in 0..rows {
Expand All @@ -218,7 +218,7 @@ fn bench_string_operations(c: &mut Criterion) {
})
});

group.bench_function(format!("string_view_value_{}_chars", str_length), |b| {
group.bench_function(format!("string_view_value_{str_length}_chars"), |b| {
b.iter(|| {
let mut sum_len = 0;
for i in 0..rows {
Expand All @@ -242,15 +242,15 @@ fn bench_avro_reader(c: &mut Criterion) {
let temp_file = create_avro_test_file(row_count, str_length).unwrap();
let file_path = temp_file.path();

group.bench_function(format!("string_array_{}_chars", str_length), |b| {
group.bench_function(format!("string_array_{str_length}_chars"), |b| {
b.iter(|| {
let options = ReadOptions::default();
let batch = read_avro_test_file(file_path, &options).unwrap();
criterion::black_box(batch)
})
});

group.bench_function(format!("string_view_{}_chars", str_length), |b| {
group.bench_function(format!("string_view_{str_length}_chars"), |b| {
b.iter(|| {
let options = ReadOptions::default().with_utf8view(true);
let batch = read_avro_test_file(file_path, &options).unwrap();
Expand Down
6 changes: 3 additions & 3 deletions arrow-avro/examples/read_with_utf8view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let view_duration = start.elapsed();

println!("Read {} rows from {}", batch.num_rows(), file_path);
println!("Reading with StringArray: {:?}", regular_duration);
println!("Reading with StringViewArray: {:?}", view_duration);
println!("Reading with StringArray: {regular_duration:?}");
println!("Reading with StringViewArray: {view_duration:?}");

if regular_duration > view_duration {
println!(
Expand Down Expand Up @@ -117,5 +117,5 @@ fn read_avro_with_options(
let int_array: ArrayRef = Arc::new(Int32Array::from(int_data));

RecordBatch::try_new(Arc::new(mock_schema), vec![string_array, int_array])
.map_err(|e| ArrowError::ComputeError(format!("Failed to create record batch: {}", e)))
.map_err(|e| ArrowError::ComputeError(format!("Failed to create record batch: {e}")))
}
Loading
Loading