Skip to main content

DecimalType

Trait DecimalType 

pub trait DecimalType:
    'static
    + Send
    + Sync
    + ArrowPrimitiveType
    + DecimalTypeSealed{
    const BYTE_LENGTH: usize;
    const MAX_PRECISION: u8;
    const MAX_SCALE: i8;
    const MAX_FOR_EACH_PRECISION: &'static [Self::Native];
    const TYPE_CONSTRUCTOR: fn(u8, i8) -> DataType;
    const DEFAULT_TYPE: DataType;
    const PREFIX: &'static str;

    // Required methods
    fn validate_decimal_precision(
        value: Self::Native,
        precision: u8,
        scale: i8,
    ) -> Result<(), ArrowError>;
    fn is_valid_decimal_precision(value: Self::Native, precision: u8) -> bool;

    // Provided method
    fn format_decimal(value: Self::Native, _precision: u8, scale: i8) -> String { ... }
}
Expand description

A trait over the decimal types, used by PrimitiveArray to provide a generic implementation across the various decimal types

Implemented by Decimal32Type, Decimal64Type, Decimal128Type and Decimal256Type for Decimal32Array, Decimal64Array, Decimal128Array and Decimal256Array respectively

Required Associated Constants§

const BYTE_LENGTH: usize

Width of the type

const MAX_PRECISION: u8

Maximum number of significant digits

const MAX_SCALE: i8

Maximum no of digits after the decimal point (note the scale can be negative)

const MAX_FOR_EACH_PRECISION: &'static [Self::Native]

The maximum value for each precision in 0..=MAX_PRECISION: [0, 9, 99, …]

const TYPE_CONSTRUCTOR: fn(u8, i8) -> DataType

fn to create its DataType

const DEFAULT_TYPE: DataType

Default values for DataType

const PREFIX: &'static str

“Decimal32”, “Decimal64”, “Decimal128” or “Decimal256”, for use in error messages

Required Methods§

fn validate_decimal_precision( value: Self::Native, precision: u8, scale: i8, ) -> Result<(), ArrowError>

Validates that value contains no more than precision decimal digits

fn is_valid_decimal_precision(value: Self::Native, precision: u8) -> bool

Determines whether value contains no more than precision decimal digits

Provided Methods§

fn format_decimal(value: Self::Native, _precision: u8, scale: i8) -> String

Formats value with scale fractional digits. The value is always formatted in full: precision is ignored and retained for API compatibility.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

§

impl DecimalType for Decimal32Type

§

const BYTE_LENGTH: usize = 4

§

const MAX_PRECISION: u8 = DECIMAL32_MAX_PRECISION

§

const MAX_SCALE: i8 = DECIMAL32_MAX_SCALE

§

const MAX_FOR_EACH_PRECISION: &'static [i32]

§

const TYPE_CONSTRUCTOR: fn(u8, i8) -> DataType = DataType::Decimal32

§

const DEFAULT_TYPE: DataType

§

const PREFIX: &'static str = "Decimal32"

§

impl DecimalType for Decimal64Type

§

const BYTE_LENGTH: usize = 8

§

const MAX_PRECISION: u8 = DECIMAL64_MAX_PRECISION

§

const MAX_SCALE: i8 = DECIMAL64_MAX_SCALE

§

const MAX_FOR_EACH_PRECISION: &'static [i64]

§

const TYPE_CONSTRUCTOR: fn(u8, i8) -> DataType = DataType::Decimal64

§

const DEFAULT_TYPE: DataType

§

const PREFIX: &'static str = "Decimal64"

§

impl DecimalType for Decimal128Type

§

const BYTE_LENGTH: usize = 16

§

const MAX_PRECISION: u8 = DECIMAL128_MAX_PRECISION

§

const MAX_SCALE: i8 = DECIMAL128_MAX_SCALE

§

const MAX_FOR_EACH_PRECISION: &'static [i128]

§

const TYPE_CONSTRUCTOR: fn(u8, i8) -> DataType = DataType::Decimal128

§

const DEFAULT_TYPE: DataType

§

const PREFIX: &'static str = "Decimal128"

§

impl DecimalType for Decimal256Type

§

const BYTE_LENGTH: usize = 32

§

const MAX_PRECISION: u8 = DECIMAL256_MAX_PRECISION

§

const MAX_SCALE: i8 = DECIMAL256_MAX_SCALE

§

const MAX_FOR_EACH_PRECISION: &'static [i256]

§

const TYPE_CONSTRUCTOR: fn(u8, i8) -> DataType = DataType::Decimal256

§

const DEFAULT_TYPE: DataType

§

const PREFIX: &'static str = "Decimal256"