From 43e3a772636f04e1b4efd30816d511a4dadcf5c8 Mon Sep 17 00:00:00 2001 From: Wei <15172118655@163.com> Date: Wed, 27 Dec 2023 18:03:37 +0800 Subject: [PATCH] fix: decimal128 ScalarValue to Value (#3019) fix: decimal128 scalarvalue to value --- src/datatypes/src/value.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/datatypes/src/value.rs b/src/datatypes/src/value.rs index b53a96a2c434..943f563a0a64 100644 --- a/src/datatypes/src/value.rs +++ b/src/datatypes/src/value.rs @@ -827,8 +827,10 @@ impl TryFrom for Value { ScalarValue::DurationNanosecond(d) => d .map(|x| Value::Duration(Duration::new(x, TimeUnit::Nanosecond))) .unwrap_or(Value::Null), - ScalarValue::Decimal128(_, _, _) - | ScalarValue::Decimal256(_, _, _) + ScalarValue::Decimal128(v, p, s) => v + .map(|v| Value::Decimal128(Decimal128::new(v, p, s))) + .unwrap_or(Value::Null), + ScalarValue::Decimal256(_, _, _) | ScalarValue::Struct(_, _) | ScalarValue::Dictionary(_, _) => { return error::UnsupportedArrowTypeSnafu { @@ -1475,11 +1477,14 @@ mod tests { ScalarValue::DurationNanosecond(None).try_into().unwrap() ); - let result: Result = ScalarValue::Decimal128(Some(1), 0, 0).try_into(); - assert!(result - .unwrap_err() - .to_string() - .contains("Unsupported arrow data type, type: Decimal128(0, 0)")); + assert_eq!( + Value::Decimal128(Decimal128::new(1, 38, 10)), + ScalarValue::Decimal128(Some(1), 38, 10).try_into().unwrap() + ); + assert_eq!( + Value::Null, + ScalarValue::Decimal128(None, 0, 0).try_into().unwrap() + ); } #[test]