@@ -27,13 +27,12 @@ use arrow_array::{
2727 TimestampMicrosecondArray ,
2828} ;
2929use arrow_schema:: { DataType , Field , Fields , Schema as ArrowSchema , TimeUnit } ;
30- use num_bigint:: BigInt ;
3130use parquet:: arrow:: PARQUET_FIELD_ID_META_KEY ;
3231use parquet:: file:: statistics:: Statistics ;
33- use rust_decimal:: prelude:: ToPrimitive ;
3432use uuid:: Uuid ;
3533
3634use crate :: error:: Result ;
35+ use crate :: spec:: decimal_utils:: i128_from_be_bytes;
3736use crate :: spec:: {
3837 Datum , FIRST_FIELD_ID , ListType , MapType , NestedField , NestedFieldRef , PrimitiveLiteral ,
3938 PrimitiveType , Schema , SchemaVisitor , StructType , Type ,
@@ -680,7 +679,8 @@ impl SchemaVisitor for ToArrowSchemaConverter {
680679 DataType :: FixedSizeBinary ( 16 ) ,
681680 ) ) ,
682681 crate :: spec:: PrimitiveType :: Fixed ( len) => Ok ( ArrowSchemaOrFieldOrType :: Type (
683- len. to_i32 ( )
682+ i32:: try_from ( * len)
683+ . ok ( )
684684 . map ( DataType :: FixedSizeBinary )
685685 . unwrap_or ( DataType :: LargeBinary ) ,
686686 ) ) ,
@@ -722,10 +722,10 @@ pub(crate) fn get_arrow_datum(datum: &Datum) -> Result<Arc<dyn ArrowDatum + Send
722722 Ok ( Arc :: new ( Int64Array :: new_scalar ( * value) ) )
723723 }
724724 ( PrimitiveType :: Float , PrimitiveLiteral :: Float ( value) ) => {
725- Ok ( Arc :: new ( Float32Array :: new_scalar ( value. to_f32 ( ) . unwrap ( ) ) ) )
725+ Ok ( Arc :: new ( Float32Array :: new_scalar ( value. into_inner ( ) ) ) )
726726 }
727727 ( PrimitiveType :: Double , PrimitiveLiteral :: Double ( value) ) => {
728- Ok ( Arc :: new ( Float64Array :: new_scalar ( value. to_f64 ( ) . unwrap ( ) ) ) )
728+ Ok ( Arc :: new ( Float64Array :: new_scalar ( value. into_inner ( ) ) ) )
729729 }
730730 ( PrimitiveType :: String , PrimitiveLiteral :: String ( value) ) => {
731731 Ok ( Arc :: new ( StringArray :: new_scalar ( value. as_str ( ) ) ) )
@@ -835,10 +835,9 @@ pub(crate) fn get_parquet_stat_min_as_datum(
835835 let Some ( bytes) = stats. min_bytes_opt ( ) else {
836836 return Ok ( None ) ;
837837 } ;
838- let unscaled_value = BigInt :: from_signed_bytes_be ( bytes) ;
839838 Some ( Datum :: new (
840839 primitive_type. clone ( ) ,
841- PrimitiveLiteral :: Int128 ( unscaled_value . to_i128 ( ) . ok_or_else ( || {
840+ PrimitiveLiteral :: Int128 ( i128_from_be_bytes ( bytes ) . ok_or_else ( || {
842841 Error :: new (
843842 ErrorKind :: DataInvalid ,
844843 format ! ( "Can't convert bytes to i128: {bytes:?}" ) ,
@@ -982,10 +981,9 @@ pub(crate) fn get_parquet_stat_max_as_datum(
982981 let Some ( bytes) = stats. max_bytes_opt ( ) else {
983982 return Ok ( None ) ;
984983 } ;
985- let unscaled_value = BigInt :: from_signed_bytes_be ( bytes) ;
986984 Some ( Datum :: new (
987985 primitive_type. clone ( ) ,
988- PrimitiveLiteral :: Int128 ( unscaled_value . to_i128 ( ) . ok_or_else ( || {
986+ PrimitiveLiteral :: Int128 ( i128_from_be_bytes ( bytes ) . ok_or_else ( || {
989987 Error :: new (
990988 ErrorKind :: DataInvalid ,
991989 format ! ( "Can't convert bytes to i128: {bytes:?}" ) ,
@@ -1295,9 +1293,9 @@ mod tests {
12951293 use std:: sync:: Arc ;
12961294
12971295 use arrow_schema:: { DataType , Field , Schema as ArrowSchema , TimeUnit } ;
1298- use rust_decimal:: Decimal ;
12991296
13001297 use super :: * ;
1298+ use crate :: spec:: decimal_utils:: decimal_new;
13011299 use crate :: spec:: { Literal , Schema } ;
13021300
13031301 /// Create a simple field with metadata.
@@ -2127,7 +2125,7 @@ mod tests {
21272125 assert_eq ! ( array. value( 0 ) , 42 ) ;
21282126 }
21292127 {
2130- let datum = Datum :: decimal_with_precision ( Decimal :: new ( 123 , 2 ) , 30 ) . unwrap ( ) ;
2128+ let datum = Datum :: decimal_with_precision ( decimal_new ( 123 , 2 ) , 30 ) . unwrap ( ) ;
21312129 let arrow_datum = get_arrow_datum ( & datum) . unwrap ( ) ;
21322130 let ( array, is_scalar) = arrow_datum. get ( ) ;
21332131 let array = array. as_any ( ) . downcast_ref :: < Decimal128Array > ( ) . unwrap ( ) ;
0 commit comments