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
4 changes: 3 additions & 1 deletion arrow-cast/src/cast/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ impl DecimalCast for i64 {
}

fn from_f64(n: f64) -> Option<Self> {
n.to_i64()
// Call implementation explicitly otherwise this resolves to `to_i64`
// in arrow-buffer that behaves differently.
num::traits::ToPrimitive::to_i64(&n)
}
}

Expand Down
29 changes: 29 additions & 0 deletions arrow-cast/src/cast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3101,6 +3101,35 @@ mod tests {
);
}

#[test]
fn test_cast_floating_to_decimals() {
for output_type in [
DataType::Decimal32(9, 3),
DataType::Decimal64(9, 3),
DataType::Decimal128(9, 3),
DataType::Decimal256(9, 3),
] {
let input_type = DataType::Float64;
assert!(can_cast_types(&input_type, &output_type));

let array = vec![Some(1.1_f64)];
let array = PrimitiveArray::<Float64Type>::from_iter(array);
let result = cast_with_options(
&array,
&output_type,
&CastOptions {
safe: false,
format_options: FormatOptions::default(),
},
);
assert!(
result.is_ok(),
"Failed to cast to {output_type} with: {}",
result.unwrap_err()
);
}
}

#[test]
fn test_cast_decimal128_to_decimal128_overflow() {
let input_type = DataType::Decimal128(38, 3);
Expand Down
2 changes: 1 addition & 1 deletion parquet-testing
Submodule parquet-testing updated 276 files
Loading