You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/11/30 20:35:54 UTC

[arrow-rs] branch master updated: Remove negative scale check (#3230)

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

tustvold 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 989ab8d7a Remove negative scale check (#3230)
989ab8d7a is described below

commit 989ab8d7a28745e76296a27445bf49921ec2d1cd
Author: Liang-Chi Hsieh <vi...@gmail.com>
AuthorDate: Wed Nov 30 12:35:49 2022 -0800

    Remove negative scale check (#3230)
    
    * Remove negative scale check
    
    * Update datatype doc for negative scale
    
    * Update Decimal128Array and Decimal256Array.
---
 arrow-array/src/array/primitive_array.rs | 11 ++---------
 arrow-schema/src/datatype.rs             | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/arrow-array/src/array/primitive_array.rs b/arrow-array/src/array/primitive_array.rs
index 7c201177f..4ff0ed4d9 100644
--- a/arrow-array/src/array/primitive_array.rs
+++ b/arrow-array/src/array/primitive_array.rs
@@ -203,10 +203,10 @@ pub type DurationMicrosecondArray = PrimitiveArray<DurationMicrosecondType>;
 pub type DurationNanosecondArray = PrimitiveArray<DurationNanosecondType>;
 
 /// An array where each element is a 128-bits decimal with precision in [1, 38] and
-/// scale in [-38, 38].
+/// scale less or equal to 38.
 pub type Decimal128Array = PrimitiveArray<Decimal128Type>;
 /// An array where each element is a 256-bits decimal with precision in [1, 76] and
-/// scale in [-76, 76].
+/// scale less or equal to 76.
 pub type Decimal256Array = PrimitiveArray<Decimal256Type>;
 
 /// Trait bridging the dynamic-typed nature of Arrow (via [`DataType`]) with the
@@ -1121,13 +1121,6 @@ impl<T: DecimalType + ArrowPrimitiveType> PrimitiveArray<T> {
                 T::MAX_SCALE
             )));
         }
-        if scale < -T::MAX_SCALE {
-            return Err(ArrowError::InvalidArgumentError(format!(
-                "scale {} is smaller than min {}",
-                scale,
-                -Decimal128Type::MAX_SCALE
-            )));
-        }
         if scale > 0 && scale as u8 > precision {
             return Err(ArrowError::InvalidArgumentError(format!(
                 "scale {} is greater than precision {}",
diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs
index f1d13aefd..4162d41bf 100644
--- a/arrow-schema/src/datatype.rs
+++ b/arrow-schema/src/datatype.rs
@@ -190,6 +190,13 @@ pub enum DataType {
     /// * scale is the number of digits past the decimal
     ///
     /// For example the number 123.45 has precision 5 and scale 2.
+    ///
+    /// In certain situations, scale could be negative number. For
+    /// negative scale, it is the number of padding 0 to the right
+    /// of the digits.
+    ///
+    /// For example the number 12300 could be treated as a decimal
+    /// has precision 3 and scale -2.
     Decimal128(u8, i8),
     /// Exact 256-bit width decimal value with precision and scale
     ///
@@ -197,6 +204,13 @@ pub enum DataType {
     /// * scale is the number of digits past the decimal
     ///
     /// For example the number 123.45 has precision 5 and scale 2.
+    ///
+    /// In certain situations, scale could be negative number. For
+    /// negative scale, it is the number of padding 0 to the right
+    /// of the digits.
+    ///
+    /// For example the number 12300 could be treated as a decimal
+    /// has precision 3 and scale -2.
     Decimal256(u8, i8),
     /// A Map is a logical nested type that is represented as
     ///