scovich commented on code in PR #8540:
URL: https://github.com/apache/arrow-rs/pull/8540#discussion_r2399806680


##########
parquet/src/arrow/schema/primitive.rs:
##########
@@ -132,35 +133,24 @@ fn from_parquet(parquet_type: &Type) -> Result<DataType> {
 }
 
 fn decimal_type(scale: i32, precision: i32) -> Result<DataType> {
-    if precision <= DECIMAL128_MAX_PRECISION as i32 {
-        decimal_128_type(scale, precision)
-    } else {
-        decimal_256_type(scale, precision)
-    }
-}
-
-fn decimal_128_type(scale: i32, precision: i32) -> Result<DataType> {
+    // Convert and validate inputs once
     let scale = scale
         .try_into()
         .map_err(|_| arrow_err!("scale cannot be negative: {}", scale))?;
-
     let precision = precision
         .try_into()
         .map_err(|_| arrow_err!("precision cannot be negative: {}", 
precision))?;
 
-    Ok(DataType::Decimal128(precision, scale))
-}
-
-fn decimal_256_type(scale: i32, precision: i32) -> Result<DataType> {
-    let scale = scale
-        .try_into()
-        .map_err(|_| arrow_err!("scale cannot be negative: {}", scale))?;
-
-    let precision = precision
-        .try_into()
-        .map_err(|_| arrow_err!("precision cannot be negative: {}", 
precision))?;
-
-    Ok(DataType::Decimal256(precision, scale))
+    // Dispatch based on precision thresholds using DecimalType trait constants
+    if precision <= Decimal32Type::MAX_PRECISION {

Review Comment:
   What if we added the corrective cast to the `VariantArray` constructor, 
which already fixes up the value and metadata columns? The [variant 
spec](https://github.com/apache/parquet-format/blob/master/VariantEncoding.md#encoding-types)
 arguably requires using the narrowest possible decimal type for a given 
precision:
   
   > Decimal Precision | Decimal value type | Variant Physical Type
   > -- | -- | --
   > 1 <= precision <= 9 | int32 | decimal4
   > 10 <= precision <= 18 | int64 | decimal8
   > 19 <= precision <= 38 | int128 | decimal16
   > | > 38 | Not supported |  
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to