Skip to content

Commit 7738768

Browse files
committed
move the mod.rs tests for parse_string_to_decimal_native to parse_decimal
1 parent 746387a commit 7738768

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

arrow-cast/src/cast/decimal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ mod tests {
615615
);
616616
assert_eq!(
617617
parse_decimal::<Decimal128Type>("123.4567891", 38, 5)?,
618-
12345679_i128
618+
12345678_i128
619619
);
620620
Ok(())
621621
}

arrow-cast/src/cast/mod.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -2383,6 +2383,7 @@ where
23832383
#[cfg(test)]
23842384
mod tests {
23852385
use super::*;
2386+
use crate::parse::parse_decimal;
23862387
use arrow_buffer::{Buffer, IntervalDayTime, NullBuffer};
23872388
use chrono::NaiveDate;
23882389
use half::f16;
@@ -8416,92 +8417,92 @@ mod tests {
84168417
fn test_parse_string_to_decimal() {
84178418
assert_eq!(
84188419
Decimal128Type::format_decimal(
8419-
parse_string_to_decimal_native::<Decimal128Type>("123.45", 2).unwrap(),
8420+
parse_decimal::<Decimal128Type>("123.45", 38, 2).unwrap(),
84208421
38,
84218422
2,
84228423
),
84238424
"123.45"
84248425
);
84258426
assert_eq!(
84268427
Decimal128Type::format_decimal(
8427-
parse_string_to_decimal_native::<Decimal128Type>("12345", 2).unwrap(),
8428+
parse_decimal::<Decimal128Type>("12345", 38, 2).unwrap(),
84288429
38,
84298430
2,
84308431
),
84318432
"12345.00"
84328433
);
84338434
assert_eq!(
84348435
Decimal128Type::format_decimal(
8435-
parse_string_to_decimal_native::<Decimal128Type>("0.12345", 2).unwrap(),
8436+
parse_decimal::<Decimal128Type>("0.12345", 38, 2).unwrap(),
84368437
38,
84378438
2,
84388439
),
84398440
"0.12"
84408441
);
84418442
assert_eq!(
84428443
Decimal128Type::format_decimal(
8443-
parse_string_to_decimal_native::<Decimal128Type>(".12345", 2).unwrap(),
8444+
parse_decimal::<Decimal128Type>(".12345", 38, 2).unwrap(),
84448445
38,
84458446
2,
84468447
),
84478448
"0.12"
84488449
);
84498450
assert_eq!(
84508451
Decimal128Type::format_decimal(
8451-
parse_string_to_decimal_native::<Decimal128Type>(".1265", 2).unwrap(),
8452+
parse_decimal::<Decimal128Type>(".1265", 38, 2).unwrap(),
84528453
38,
84538454
2,
84548455
),
8455-
"0.13"
8456+
"0.12"
84568457
);
84578458
assert_eq!(
84588459
Decimal128Type::format_decimal(
8459-
parse_string_to_decimal_native::<Decimal128Type>(".1265", 2).unwrap(),
8460+
parse_decimal::<Decimal128Type>(".1265", 38, 2).unwrap(),
84608461
38,
84618462
2,
84628463
),
8463-
"0.13"
8464+
"0.12"
84648465
);
84658466

84668467
assert_eq!(
84678468
Decimal256Type::format_decimal(
8468-
parse_string_to_decimal_native::<Decimal256Type>("123.45", 3).unwrap(),
8469+
parse_decimal::<Decimal256Type>("123.45", 38, 3).unwrap(),
84698470
38,
84708471
3,
84718472
),
84728473
"123.450"
84738474
);
84748475
assert_eq!(
84758476
Decimal256Type::format_decimal(
8476-
parse_string_to_decimal_native::<Decimal256Type>("12345", 3).unwrap(),
8477+
parse_decimal::<Decimal256Type>("12345", 38, 3).unwrap(),
84778478
38,
84788479
3,
84798480
),
84808481
"12345.000"
84818482
);
84828483
assert_eq!(
84838484
Decimal256Type::format_decimal(
8484-
parse_string_to_decimal_native::<Decimal256Type>("0.12345", 3).unwrap(),
8485+
parse_decimal::<Decimal256Type>("0.12345", 38, 3).unwrap(),
84858486
38,
84868487
3,
84878488
),
84888489
"0.123"
84898490
);
84908491
assert_eq!(
84918492
Decimal256Type::format_decimal(
8492-
parse_string_to_decimal_native::<Decimal256Type>(".12345", 3).unwrap(),
8493+
parse_decimal::<Decimal256Type>(".12345", 38, 3).unwrap(),
84938494
38,
84948495
3,
84958496
),
84968497
"0.123"
84978498
);
84988499
assert_eq!(
84998500
Decimal256Type::format_decimal(
8500-
parse_string_to_decimal_native::<Decimal256Type>(".1265", 3).unwrap(),
8501+
parse_decimal::<Decimal256Type>(".1265", 38, 3).unwrap(),
85018502
38,
85028503
3,
85038504
),
8504-
"0.127"
8505+
"0.126"
85058506
);
85068507
}
85078508

arrow-cast/src/parse.rs

+5
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,11 @@ pub fn parse_decimal<T: DecimalType>(
988988
}
989989
}
990990

991+
//handle scale = 0 , scale down by fractional digits
992+
if scale == 0 {
993+
result = result.div_wrapping(base.pow_wrapping(fractionals as u32))
994+
}
995+
991996
Ok(if negative {
992997
result.neg_wrapping()
993998
} else {

0 commit comments

Comments
 (0)