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/24 18:18:55 UTC
[arrow-rs] branch master updated: Move decimal constants from `arrow-data` to `arrow-schema` crate (#3177)
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 22deab006 Move decimal constants from `arrow-data` to `arrow-schema` crate (#3177)
22deab006 is described below
commit 22deab00696f4fac2a587c59bf9b0ce2c2ec3ac6
Author: Matthijs Brobbel <m1...@gmail.com>
AuthorDate: Thu Nov 24 19:18:49 2022 +0100
Move decimal constants from `arrow-data` to `arrow-schema` crate (#3177)
* Move decimal constants from `arrow-data` to `arrow-schema` crate
* Remove `arrow-schema` crate prefix from intra doc links
* Avoid breaking change and move non-schema constants back to `arrow-data`
* Update arrow/src/row/mod.rs
Co-authored-by: Raphael Taylor-Davies <17...@users.noreply.github.com>
Co-authored-by: Raphael Taylor-Davies <17...@users.noreply.github.com>
---
arrow-array/src/types.rs | 6 +++---
arrow-data/src/decimal.rs | 29 +++++++++--------------------
arrow-schema/src/datatype.rs | 16 ++++++++++++++++
3 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/arrow-array/src/types.rs b/arrow-array/src/types.rs
index 40d262e8e..13194d61f 100644
--- a/arrow-array/src/types.rs
+++ b/arrow-array/src/types.rs
@@ -21,12 +21,12 @@ use crate::array::ArrowPrimitiveType;
use crate::delta::shift_months;
use crate::OffsetSizeTrait;
use arrow_buffer::i256;
-use arrow_data::decimal::{
- validate_decimal256_precision, validate_decimal_precision, DECIMAL128_MAX_PRECISION,
+use arrow_data::decimal::{validate_decimal256_precision, validate_decimal_precision};
+use arrow_schema::{
+ ArrowError, DataType, IntervalUnit, TimeUnit, DECIMAL128_MAX_PRECISION,
DECIMAL128_MAX_SCALE, DECIMAL256_MAX_PRECISION, DECIMAL256_MAX_SCALE,
DECIMAL_DEFAULT_SCALE,
};
-use arrow_schema::{ArrowError, DataType, IntervalUnit, TimeUnit};
use chrono::{Duration, NaiveDate};
use half::f16;
use std::marker::PhantomData;
diff --git a/arrow-data/src/decimal.rs b/arrow-data/src/decimal.rs
index 7011c4085..9367d4ec2 100644
--- a/arrow-data/src/decimal.rs
+++ b/arrow-data/src/decimal.rs
@@ -18,6 +18,11 @@
use arrow_buffer::i256;
use arrow_schema::ArrowError;
+pub use arrow_schema::{
+ DECIMAL128_MAX_PRECISION, DECIMAL128_MAX_SCALE, DECIMAL256_MAX_PRECISION,
+ DECIMAL256_MAX_SCALE, DECIMAL_DEFAULT_SCALE,
+};
+
// MAX decimal256 value of little-endian format for each precision.
// Each element is the max value of signed 256-bit integer for the specified precision which
// is encoded to the 32-byte width format of little-endian.
@@ -638,8 +643,8 @@ pub(crate) const MIN_DECIMAL_BYTES_FOR_LARGER_EACH_PRECISION: [i256; 76] = [
]),
];
-/// `MAX_DECIMAL_FOR_EACH_PRECISION[p]` holds the maximum `i128` value
-/// that can be stored in [arrow_schema::DataType::Decimal128] value of precision `p`
+/// `MAX_DECIMAL_FOR_EACH_PRECISION[p]` holds the maximum `i128` value that can
+/// be stored in [arrow_schema::DataType::Decimal128] value of precision `p`
pub const MAX_DECIMAL_FOR_EACH_PRECISION: [i128; 38] = [
9,
99,
@@ -681,8 +686,8 @@ pub const MAX_DECIMAL_FOR_EACH_PRECISION: [i128; 38] = [
99999999999999999999999999999999999999,
];
-/// `MIN_DECIMAL_FOR_EACH_PRECISION[p]` holds the minimum `i128` value
-/// that can be stored in a [arrow_schema::DataType::Decimal128] value of precision `p`
+/// `MIN_DECIMAL_FOR_EACH_PRECISION[p]` holds the minimum `i128` value that can
+/// be stored in a [arrow_schema::DataType::Decimal128] value of precision `p`
pub const MIN_DECIMAL_FOR_EACH_PRECISION: [i128; 38] = [
-9,
-99,
@@ -724,22 +729,6 @@ pub const MIN_DECIMAL_FOR_EACH_PRECISION: [i128; 38] = [
-99999999999999999999999999999999999999,
];
-/// The maximum precision for [arrow_schema::DataType::Decimal128] values
-pub const DECIMAL128_MAX_PRECISION: u8 = 38;
-
-/// The maximum scale for [arrow_schema::DataType::Decimal128] values
-pub const DECIMAL128_MAX_SCALE: i8 = 38;
-
-/// The maximum precision for [arrow_schema::DataType::Decimal256] values
-pub const DECIMAL256_MAX_PRECISION: u8 = 76;
-
-/// The maximum scale for [arrow_schema::DataType::Decimal256] values
-pub const DECIMAL256_MAX_SCALE: i8 = 76;
-
-/// The default scale for [arrow_schema::DataType::Decimal128] and
-/// [arrow_schema::DataType::Decimal256] values
-pub const DECIMAL_DEFAULT_SCALE: i8 = 10;
-
/// Validates that the specified `i128` value can be properly
/// interpreted as a Decimal number with precision `precision`
#[inline]
diff --git a/arrow-schema/src/datatype.rs b/arrow-schema/src/datatype.rs
index f74e2a24b..6e0f626ef 100644
--- a/arrow-schema/src/datatype.rs
+++ b/arrow-schema/src/datatype.rs
@@ -412,6 +412,22 @@ impl DataType {
}
}
+/// The maximum precision for [DataType::Decimal128] values
+pub const DECIMAL128_MAX_PRECISION: u8 = 38;
+
+/// The maximum scale for [DataType::Decimal128] values
+pub const DECIMAL128_MAX_SCALE: i8 = 38;
+
+/// The maximum precision for [DataType::Decimal256] values
+pub const DECIMAL256_MAX_PRECISION: u8 = 76;
+
+/// The maximum scale for [DataType::Decimal256] values
+pub const DECIMAL256_MAX_SCALE: i8 = 76;
+
+/// The default scale for [DataType::Decimal128] and [DataType::Decimal256]
+/// values
+pub const DECIMAL_DEFAULT_SCALE: i8 = 10;
+
#[cfg(test)]
mod tests {
use super::*;