Skip to content

Commit

Permalink
Cast function should convert scientific notation to correct decimal v…
Browse files Browse the repository at this point in the history
…alue
  • Loading branch information
harveyyue committed Feb 26, 2025
1 parent fc324e4 commit 54e92bd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion native-engine/datafusion-ext-commons/src/arrow/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ fn to_plain_string_array(array: &dyn Array) -> ArrayRef {
// support to convert scientific notation
if s.contains('e') || s.contains('E') {
match BigDecimal::from_str(s) {
Ok(decimal) => converted_values.push(Some(decimal.to_string())),
Ok(decimal) => converted_values.push(Some(decimal.to_plain_string())),
Err(_) => converted_values.push(Some(s.to_string())),
}
} else {
Expand Down Expand Up @@ -440,6 +440,7 @@ mod test {
fn test_string_to_decimal() {
let string_array: ArrayRef = Arc::new(StringArray::from_iter(vec![
None,
Some("1e-8"),
Some("1.012345678911111111e10"),
Some("1.42e-6"),
Some("0.00000142"),
Expand All @@ -453,6 +454,7 @@ mod test {
as_decimal128_array(&casted).unwrap(),
&Decimal128Array::from_iter(vec![
None,
Some(10000000000),
Some(10123456789111111110000000000i128),
Some(1420000000000),
Some(1420000000000),
Expand Down
2 changes: 1 addition & 1 deletion native-engine/datafusion-ext-plans/src/scan/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn schema_adapter_cast_column(col: &ArrayRef, data_type: &DataType) -> Result<Ar
DataType::Int16 => handle_decimal!(Int16, Decimal128, i128, *prec, *scale),
DataType::Int32 => handle_decimal!(Int32, Decimal128, i128, *prec, *scale),
DataType::Int64 => handle_decimal!(Int64, Decimal128, i128, *prec, *scale),
DataType::Decimal128(p, s) => {
DataType::Decimal128(..) => {
datafusion_ext_commons::arrow::cast::cast_scan_input_array(col.as_ref(), data_type)
}
_ => df_execution_err!(
Expand Down

0 comments on commit 54e92bd

Please sign in to comment.