You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by li...@apache.org on 2022/08/15 01:54:09 UTC

[arrow-rs] branch master updated: minor: move decimal256 impl to decimal.rs (#2443)

This is an automated email from the ASF dual-hosted git repository.

liukun pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 49d53c7d9 minor: move decimal256 impl to decimal.rs (#2443)
49d53c7d9 is described below

commit 49d53c7d9d2aeaab69fdfd67bbc2e203586968b6
Author: Kun Liu <li...@apache.org>
AuthorDate: Mon Aug 15 09:54:03 2022 +0800

    minor: move decimal256 impl to decimal.rs (#2443)
---
 arrow/src/array/array_decimal.rs | 14 +++-----------
 arrow/src/util/decimal.rs        |  7 +++++++
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/arrow/src/array/array_decimal.rs b/arrow/src/array/array_decimal.rs
index ed1d3102a..d051c4b9d 100644
--- a/arrow/src/array/array_decimal.rs
+++ b/arrow/src/array/array_decimal.rs
@@ -16,7 +16,7 @@
 // under the License.
 
 use crate::array::ArrayAccessor;
-use num::BigInt;
+
 use std::borrow::Borrow;
 use std::convert::From;
 use std::fmt;
@@ -29,10 +29,8 @@ use super::{BasicDecimalIter, BooleanBufferBuilder, FixedSizeBinaryArray};
 #[allow(deprecated)]
 pub use crate::array::DecimalIter;
 use crate::buffer::{Buffer, MutableBuffer};
+use crate::datatypes::validate_decimal_precision;
 use crate::datatypes::{validate_decimal256_precision_with_lt_bytes, DataType};
-use crate::datatypes::{
-    validate_decimal_precision, DECIMAL256_MAX_PRECISION, DECIMAL_DEFAULT_SCALE,
-};
 use crate::error::{ArrowError, Result};
 use crate::util::decimal::{BasicDecimal, Decimal256};
 
@@ -435,13 +433,6 @@ impl<'a> Decimal128Array {
     }
 }
 
-impl From<BigInt> for Decimal256 {
-    fn from(bigint: BigInt) -> Self {
-        Decimal256::from_big_int(&bigint, DECIMAL256_MAX_PRECISION, DECIMAL_DEFAULT_SCALE)
-            .unwrap()
-    }
-}
-
 fn build_decimal_array_from<const BYTE_WIDTH: usize>(
     null_buf: BooleanBufferBuilder,
     buffer: Buffer,
@@ -578,6 +569,7 @@ impl<'a, const BYTE_WIDTH: usize> BasicDecimalArray<BYTE_WIDTH> {
 #[cfg(test)]
 mod tests {
     use crate::array::Decimal256Builder;
+    use crate::datatypes::{DECIMAL256_MAX_PRECISION, DECIMAL_DEFAULT_SCALE};
     use crate::{array::Decimal128Builder, datatypes::Field};
     use num::{BigInt, Num};
 
diff --git a/arrow/src/util/decimal.rs b/arrow/src/util/decimal.rs
index 1b9cf80fd..043e37ddb 100644
--- a/arrow/src/util/decimal.rs
+++ b/arrow/src/util/decimal.rs
@@ -252,6 +252,13 @@ impl Decimal256 {
     }
 }
 
+impl From<BigInt> for Decimal256 {
+    fn from(bigint: BigInt) -> Self {
+        Decimal256::from_big_int(&bigint, DECIMAL256_MAX_PRECISION, DECIMAL_DEFAULT_SCALE)
+            .unwrap()
+    }
+}
+
 // compare two signed integer which are encoded with little endian.
 // left bytes and right bytes must have the same length.
 #[inline]